Reputation: 415
When we select an item in paperjs, a blue rectangle is created around it. I tried to get the bounds of that rectangle using item.getBounds()
.
When the item is not rotated, I get the correct bounds. But when it is rotated, item.getBounds()
returns a different rectangle compared to the displayed blue rectangle. How can I get the bounds of the selection rectangle even when the item is rotated.
Upvotes: 1
Views: 204
Reputation: 11619
You can always unrotate (or untransform) the item, get its bounding box, and then reapply transformations.
Another way is to get its bounding box at creation time and store it for later use.
item.bounds
returns the smallest rectangle which contains the transformed item (that is why rotated rectangles often have bigger bounds).
Here is a sketch which explains how you can do it.
Upvotes: 1