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
893 stars 36 forks source link

draw a bridge bug #358

Closed Kreijstal closed 11 months ago

Kreijstal commented 11 months ago

I want to draw a bridge, with lots of trial and error I discovered a code that worked

#import "@preview/cetz:0.1.2"

#set page(width: auto, height: auto, margin: .5cm)
#cetz.canvas({
  import cetz.draw: *
    fill(red)

  merge-path(close: true, {
    //    line((0, 1), (0,0))
        arc((0,0), start: 0 * 360deg, stop: 0.5 * 360deg, radius: 1)
        line((),(0, 1))
        line((), (-2,1))
        //line((), (-2,-0))
        line((), (0,1))
        line((), (0,0))

        //line((), (-2,0))
      })
})

This however seems like a bug and the way you'd expect it to be able to be written doesn't work, this seems it abuses a bug to make it work. Can it just work normally, or alternatively is this the way it works and I'm dubm?

johannes-wolf commented 11 months ago

The prev. pos of arc is not set to its end but to its position, which is a bug, or at least not a good default. I've fixed this with #360.

The workaround for this PR is to use anchors:

#import "@preview/cetz:0.1.2"
#set page(width: auto, height: auto)

#cetz.canvas(length: 1cm, {
  import cetz.draw: *
  merge-path({
    arc((0,0), start: 0deg, stop: 180deg, name: "arc")
    line("arc.end", (rel: (0, 1)), ((), "-|", "arc.start"))
  }, fill: red, close: true)
})