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
733 stars 34 forks source link

`line` is drawn with wrong offset for coordinates that are `content` with a non-`center` anchor #621

Open kram-tm opened 1 month ago

kram-tm commented 1 month ago

When using draw.line to draw a line between the border of a content node and another element, the resulting line seems to be drawn with a proper angle, but unexpected offset relative to the content's border. The issue is visible in the following example:

#import "@preview/cetz:0.2.2": draw, canvas

#stack(
  dir: ltr,
  canvas({
    draw.content(name: "test1", frame: "rect", (0,0))[Test 1]
    draw.content(name: "test2", frame: "rect", (-1,-1))[Test 2]
    draw.line("test1", "test2")
  }),
  canvas({
    draw.content(name: "test1", (0,0))[Test 1]
    draw.content((-1,-1))[#box(stroke: 1pt + red, hide[Test 2])]
    draw.content(name: "test2", frame: "rect", anchor: "north-east", (-1,-1))[Test 2]
    draw.line("test1", "test2")
  }),
  canvas({
    draw.content(name: "test1", (0,0))[Test 1]
    draw.content((-1,-1))[#box(stroke: 1pt + red, hide[Test 2])]
    draw.content(name: "test2", frame: "rect", anchor: "south", (-1,-1))[Test 2]
    draw.line("test1", "test2")
  }),
)

image As evident in the image, line considers both the actual content node and a variant of it with anchor: center, drawing the line towards the center of the former and stopping at the first intersection with the border of either of the nodes. The error is seemingly absent in other shapes (circle and rect, at least).