You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting the anchor to center doesn't change the a position in the rectangle, it remains what seems to be south-west. Which makes sens as this is what the documentation says:
a: Coordinate of the bottom left corner of the rectangle.
But this scratched my head. How could such a trivial problem could remain unnoticed for so long? It has to be a problem with my comprehension. So I experimented with different anchors and I was very surprised by the behavior, that looked, at first glance, chaotic and nonsensical. But at the end, I got it:
a is bottom left
b is top right
the anchor applies a shift (or drag) to have the anchor point on the center (a + b) / 2
It makes sens after all. It is coherent. Knowing that, a rectangle can be centered by putting its anchor to north-east.
Request
I suggest to add a clarification in the documentation about this.
Or even maybe add an optional center: false parameter to change the meaning of a as the center instead of the bottom left corner. (Which is not equivalent to setting anchor to north-east)
The text was updated successfully, but these errors were encountered:
uben0
changed the title
Anchor on rect makes little sens
Anchor on rect needs doc clarification
Jan 31, 2024
Note: the second argument of rect is an absolute position! If you want to pass a size, use (rel: (width, height)). Using relative coordinates is the correct way to add multiple coordinates in cetz.
You can get centered rects if you use relative coordinates:
rect((rel: (-1,-1), to: (...center...)), (rel: (2,2)), name: "b")
Proposal: Change rect’s default anchor to its first parameter (a). This would allow the expected transformation to happen (anchor: "center"). The intersection code of line must be changed to use the center anchor instead of the default anchor.
Proposal: Change rect’s default anchor to its first parameter (a). This would allow the expected transformation to happen (anchor: "center"). The intersection code of line must be changed to use the center anchor instead of the default anchor.
I just ran into the same problem and this solution sound like it would make sense.
Currently rects anchor to south-west, but think that they would anchor to center. Changing the anchor to anything else leads to even more unexpected behavior. Changing it to south for example leads to a rect that's not even in touch with its anchor.
I'm just beginning to use CeTZ (awesome job BTW 🤩) and I could not find how to center rectangles. Maybe it's just a skill issue 😶🌫️
#rect((3, 0), (0.8, 0.8), name: "b", anchor: "center")
Setting the
anchor
tocenter
doesn't change thea
position in the rectangle, it remains what seems to besouth-west
. Which makes sens as this is what the documentation says:I wrote a wrapper to bypass this limitation:
But this scratched my head. How could such a trivial problem could remain unnoticed for so long? It has to be a problem with my comprehension. So I experimented with different anchors and I was very surprised by the behavior, that looked, at first glance, chaotic and nonsensical. But at the end, I got it:
a
is bottom leftb
is top right(a + b) / 2
It makes sens after all. It is coherent. Knowing that, a rectangle can be centered by putting its
anchor
tonorth-east
.Request
I suggest to add a clarification in the documentation about this.
Or even maybe add an optional
center: false
parameter to change the meaning ofa
as the center instead of the bottom left corner. (Which is not equivalent to settinganchor
tonorth-east
)The text was updated successfully, but these errors were encountered: