Getting PShape primitive sizes


#1

Is there a way to obtain the size of a PShape primitive?

PShape ps1 = createShape();
ps1.beginShape();
ps1.vertex(-50, -50);
ps1.vertex(50, -50);
ps1.vertex(50, 50);
ps1.vertex(-50, 50);
ps1.endShape(CLOSE);
println(ps1.width, " ",ps1.height);
// prints   50.0   50.0

PShape ps2 = createShape(RECT, -50, -50, 100, 100);
println(ps2.width, " ", ps2.height);
// prints   0.0   0.0

If so, would it work with PShape GROUPs?

Hmm… I just noticed that printing the width,height of ps1 doesn’t give the absolute size since it ignores values less than 0. Obviously the size of ps1 should be 100,100.

Here’s ps1 “corrected”:

PShape ps1 = createShape();
ps1.beginShape();
ps1.vertex(0, 0);
ps1.vertex(0, 100);
ps1.vertex(100, 100);
ps1.vertex(0, 100);
ps1.endShape(CLOSE);
println(ps1.width, " ",ps1.height);
// prints   100.0   100.0

// ok, let's create ps1 another 100 units away
PShape ps1 = createShape();
ps1.beginShape();
ps1.vertex(100, 100);
ps1.vertex(100, 200);
ps1.vertex(200, 200);
ps1.vertex(100, 200);
ps1.endShape(CLOSE);
println(ps1.width, " ",ps1.height);
// prints   200.0   200.0

So it seems to determine the size based on its position to the canvas?!

Which raises the question: how does one obtain the absolute size of any PShape object?


#2

-a- yes, looks like the properties

shape.width and shape.height

not work for that primitives

-b- and what you now show in your second example gets even more bad
when i used minus values…

-c- and also not work on groups

so might be a bug?