Closed ghost closed 3 years ago
The actual rotation of an object can actually change the bbox. If you have a normal square and you rotate it by 45°, you have a bounding box larger than the original square. The rotations you have are based on some point. So if you rotated it around a different corner by 90 degrees you would end up things differently with regard to position. Or rotating it around the center of the point.
Yeah, I checked by loading it up in meerk40t and applying the rotation moving it around in a circle. And yes, the bbox is wrong in that case. You'd have to reify the path to get the correct bbox. abs(path).bbox()
will give you the correct results. Which will work as a good work around while I look into why it's wrong.
You can see when I reify the image it gets the correct bounding box. I swear there's a reason it does this but I'm not sure. I think it calculates the bounding box and then rotates the four corners of that bounding box. I'll get a better answer fairly soon.
And the second question: how could I rotate about a certain point?
There's two optional parameter of x an y in any translation event. "rotate(0.3turn)"
will, for example, perform a turn of 30% around, however implied in that is that the turn is relative to 0,0. "rotate(108deg, 30, 30)"
is a rotation around point 30,30. Mathematically this will be the same as translating by -30,-30, rotating around the origin, then translating back +30,+30. Which is how the affine transformation is performed. SVG allows that kind of shorthand.
I ended up correcting 104 by simply performing the transformation universally before the bbox. The issue was conceptual since you cannot actually rotate a value and not change the underlying geometry. Rotating the corners of the original bounds is not sufficient. https://github.com/meerk40t/svgelements/pull/106/commits/1a68c1dd5d147b8511394dab2c9e7f4a24d43835
Calling the bbox method on the following path after a rotation returns a wrong bounding box (wider than the path boundaries). This happens specifically when the rotation is not on one of four axis (ie 0, 90, 135 & 180 return the correct path bbox):
results in
Also is it possible to assign rotation axis?