As the title said, why doesn't it work if I scale the shape doing shape.scale(0.5)
?
It doesn't work even if I do shape(0,0,200,200)
meaning I draw the shape not in the original dimensions. Is this a bug or I'm missing something?
As the title said, why doesn't it work if I scale the shape doing shape.scale(0.5)
?
It doesn't work even if I do shape(0,0,200,200)
meaning I draw the shape not in the original dimensions. Is this a bug or I'm missing something?
It kind of is a bug, although I'm not sure how severe. As you found out from your test the
contains()
method doesn't work when transformations(translation/rotation/scale) are used.I've got two somewhat hacky workarounds:
The first solution sounds like a bit of work and pointless duplication of data, not mention annoying when it comes to handling rotations and also error prone for 'stacked'/complex transformations.
The second workaround looks slightly hacky since contains() should've just worked, but it makes uses of Processing classes so it's not that bad. It works like this:
The svg comes from Examples > Basic > Shape > GetChild. You can open the sketch folder(Ctrl + K / CMD + K) to get "usa-wikipedia.svg" if you want to test the code as is:
I've noticed that the applyMatrix() method only works with the
P3D
andOPENGL
renderers even thought I'm passing a PMatrix2D instance, otherwise this warning appears:The 'cleaner' option is to modify the contains() method in the PShape class, then recompile Processing's core.jar and use the updated jar. If this is for a one-off small project I don't know if it's worth the trouble though, it might faster to have the slightly messier code from above than recompiling/updating core.jar.