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

canvas debug inverts fill area of merge-path #575

Open raphCode opened 4 months ago

raphCode commented 4 months ago

I noticed a very special edge case of using canvas(debug: true) together with fills in merge-path and some relative coordinates. I did not perform any further testing to minimize the repro code, so it is possible that the bug can be triggered in more general situations.

When activating the canvas debug plots in the following code, the fill areas of the triangle are inverted:

#import "@preview/cetz:0.2.2"

#cetz.canvas(debug: false, {  // toggle debug here
  import cetz.draw: *

  let end-pos = (0.1, 1)
  let (tri-w, tri-h) = (0.5em, 1em)
  merge-path(
    {
      rect((0,0), end-pos)
      line(
        end-pos,
        (rel: (y: -tri-h)),
        (rel: (tri-w, tri-h / 2)),
        close: true,
      )
    },
    stroke: none,
    fill: blue,
  )
})

Without debug, expected form: image With debug: true, unexpected fill area inversion: image

Maybe I am also abusing the merge-path function here since the rect line draw order is not specified in the manual? My goal was to avoid the fine white line between the rect and the triangle, which happens without merge-path in some PDF viewers.

johannes-wolf commented 4 months ago

Note: Mark debug elements as such and exclude them from merge-path.