Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent anchor calculation for groups of asymmetric size between using the anchor as anchor parameter or in a relative coordinate #772

Closed
manuelVo opened this issue Dec 16, 2024 · 1 comment

Comments

@manuelVo
Copy link

When using the anchors of a group that has an asymmetric size (i.e. the origin is not in the center of the group), the anchor calculation for that group is inconsistent. Depending on where the anchor is being used (as the anchor parameter for the group or as part of a relative coordinate), different coordinates end up being calculated.

Example: The following code

#import "@preview/cetz:0.3.1"

#cetz.canvas({
  import cetz.draw: *

  let asymmetric_group(pos, text, anchor: none, name: none) = {
    group(
      name: name,
      anchor: anchor,
      get-ctx(ctx => {
        let (ctx, pos) = cetz.coordinate.resolve(ctx, pos)
        set-origin(pos)
        rect((-1cm, 0cm), (2cm,2cm))
      })
    )
  }
  
  content((1, 1cm), name: "north1", "North1")
  asymmetric_group((rel: (0,0), to: "north1"), anchor: "north", name: "group", "Some text")
  content((rel: (0,0), to: "group.north"), "North2")
})

uses the north anchor of the group twice. Once when defining the group to determine that the group shall be anchored at its north side. The second time the anchor is being used as part of the relative position of the second content element. Again, this element is placed at the group's north. Since both content elements are placed at the group's north, i would expect them to be placed at the exact same position. However, the following is what's actually being rendered:

grafik

@johannes-wolf johannes-wolf added bug 🐛 Something isn't working and removed bug 🐛 Something isn't working labels Dec 16, 2024
@johannes-wolf
Copy link
Member

johannes-wolf commented Dec 22, 2024

I've tested this. This is not a bug. The documentation specifies how the group anchor works:
You have to set an anchor called "default" as the groups origin (anchor("default", pos) in your case). I've opened a PR with a test-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants