cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
809 stars 35 forks source link

Group bounding box/border anchors should be effected by rotation #488

Open fenjalien opened 7 months ago

fenjalien commented 7 months ago

In the example I would expect the red circle to cover the blue one

rotate(45deg)
group({
  rect((0, 0), (1, 1), name: "rect")
  circle("rect.west", radius: 0.1, fill: blue)
}, name: "group")
circle("group.west", radius: 0.1, fill: red)

image

johannes-wolf commented 7 months ago

~~The bbox of groups is currently axis aligned, which is intended. If we support rotated group bboxes, this has to be toggleable as a flag, because getting an axis aligned bbox is very useful.~~

As soon as nested anchors are merged, this example would be possible by using the rect instead of the group for anchor placement (https://github.com/johannes-wolf/cetz/pull/389).

EDIT: I think I got this wrong. Yes, if the transformation is outsides the group, its anchors should get transformed by that.

johannes-wolf commented 6 months ago

How should this work for groups containing elements with different z coordinates? If we do not “flatten” the bounding box to an aabb, we can not correctly generate bounding boxes for such groups.

Second problem are groups with content(..) insides them. Content is not affected by transformations.

johannes-wolf commented 6 months ago

Example with content: grafik

The cleanest solution would be to implement setting a transformation matrix in Typst and transforming text like any other element.

fenjalien commented 6 months ago

Hmm, I would rather not be transforming content until we get better control from Typst, otherwise it feels just to brittle and difficult to keep working.

My current work around is to hide a rectangle then copy its anchors, which works but does mean I have to calculate the bounds before hand and angle/path anchors don't work as expected. What might be an easier solution would be to allow completely overriding the anchors of a group.

The bounds anchors would be kept as default but it would require exposing anchor.setup in some form...

johannes-wolf commented 6 months ago

All we need from Typst is it allowing to set a transformation matrix. Internally, it should use them already, so the missing part is a function to set one. Maybe we can make a PR for Typst implementing such function?

johannes-wolf commented 6 months ago

My current work around is to hide a rectangle then copy its anchors, which works but does mean I have to calculate the bounds before hand and angle/path anchors don't work as expected. What might be an easier solution would be to allow completely overriding the anchors of a group.

What do you mean with allowing to override anchors of groups? Isn't that possible?