cetz icon indicating copy to clipboard operation
cetz copied to clipboard

group padding is ignored when line is drawn to group's center

Open lvgrr opened this issue 11 months ago • 2 comments

The following code draws a rectangle within a group with padding and a line to the group's center.

group({
    rect((0,0), (1,1))},
    name: "r",
    padding: .5cm,
)
line((-1,.5), "r")

The output is:

Image

Even though the border anchors with padding have been correctly computed, specifying the end coordinate for the line as the center of the group ignores its padding. Is this expected? I'd expect it to take padding into account, so the result would look like this:

Image

lvgrr avatar Mar 09 '25 10:03 lvgrr

The line Element has a mode to use (path!) intersections if you pass element names. This is what happens here. I do not think padding should apply to intersections. Since groups have no border path, they do not cause intersections by themselves. You could draw a hidden rect using hide(...) to simulate the group border. Or do you think that something should be changed/added here? Maybe an option?

johannes-wolf avatar Mar 09 '25 14:03 johannes-wolf

I see, thanks for the explanation. I stand by my opinion that the line should end on the padding edge. That I think would be more consistent with the behaviour you get by referencing the group's border (i.e. in the example above r.north, r.east etc.), where the padding is indeed taken into account. But it's just my opinion, it'd be interesting to see what others think of this.

If anything this behaviour could be optional, depending on the value of a parameter of group.

lvgrr avatar Mar 09 '25 19:03 lvgrr