#Add `radius` to corners created by cetz line (perpendicular feature, right angles)

43 messages · Page 1 of 1 (latest)

inner crown
#
#import "@preview/cetz:0.2.1"
#cetz.canvas({
  import cetz.draw: *
  let action-counter = counter("action")
  let box(coordinates, body, order: auto, ..args) = group(..args, {
    anchor("default", coordinates)
    let w = 3
    let h = 1.7

    rect((), (rel: (w, h)), name: "a")

    let offset = 0.2
    let nw = "a.north-west"
    line((rel: (0, -offset), to: nw), (rel: (+offset, 0), to: nw))

    content("a.center", {
      set block(width: 1cm * w * 0.9, height: 1cm * h * 0.8)
      set align(center)
      set par(leading: 0.3em)
      block(pad(top: 0.3em, body))
    })

    let offset = 0.1
    content(
      (rel: (-offset, offset), to: "a.south-east"),
      if order == auto {
        action-counter.step()
        action-counter.display()
      } else { order },
      anchor: "south-east",
    )

    copy-anchors("a")
  })
  box((0,0), name: "2")[two]
  box((rel: (4, -3), to: "2"), name: "3")[three]
  let start = (name: "2", anchor: -20deg)
  let end = ("3.west")
  let mid = (start, 50%, end)
  line(start, (start, "-|", mid), (mid, "|-", end), end, mark: (end: ">", fill: black))
})
#

Here is a more cut down version:

#

?r

#import "@preview/cetz:0.2.1"
#cetz.canvas({
  import cetz.draw: *
  let box(coordinates, ..args) = group(..args, {
    anchor("default", coordinates)
    let w = 3
    let h = 1.7
    rect((), (rel: (w, h)), name: "a")
    copy-anchors("a")
  })
  box((0,0), name: "2")
  box((rel: (4, -3), to: "2"), name: "3")
  let start = (name: "2", anchor: -20deg)
  let end = ("3.west")
  let mid = (start, 50%, end)
  line(start, (start, "-|", mid), (mid, "|-", end), end, mark: (end: ">", fill: black))
})
inner crown
#

@tiny carbon

#

I have a feeling this is a new feature request.

tiny carbon
#

Yes, I would like to add this, but this has not been implemented yet.

inner crown
#

Is there an open issue?

tiny carbon
#

No.

inner crown
#

I'm on it.

tiny carbon
#

Thanks.

#

But it will take a while, I guess. I do not have that much free time in the next few weeks.

inner crown
#

only for right angles?

tiny carbon
#

No, all angles, also with beziers, but only in 2D space.

#

I'd like to implement it as a decoration function.

#

There is a ticket open to apply decorations via style key. Smth. like line(..., decoration: ("radius", ...))

inner crown
#

I think that maybe a...zig-zag line could be added... a second one, I guess...

pseudo frost
#

I’ll just mention that fletcher implements this, but it isn’t as low-level as you probably want (a bulit-in edge style, not a cetz path decoration).

#

?r theme=light ```
#import "@preview/fletcher:0.4.2": diagram, node, edge
#diagram(
spacing: (5mm, 10mm),
node-stroke: 1pt,
node((0,0), "two"),
node((2,1), "three"),
edge((0,0), "r,d,r", "-|>", corner-radius: 5pt)
)

inner crown
#

Ohhh, thaaat is where I saw the "l,u,r,d" thing.

#

Interesting. Gotta check it out. Thanks

inner crown
#

idk what is broken, but looks like fletcher. this is the first time I'm having these problems.

inner crown
#

I'm shocked that the bot somehow manages to compile this. The problem is that cetz.dras.hide() is introduced in v0.2.1. And v0.2.0 is used 4 times.

#

@tiny carbon, do you know anything about this? Was the previous version somehow substituted/altered or something?

tiny carbon
#

?r t=l

#import "@preview/cetz:0.2.0"
#cetz.canvas({
  cetz.draw.hide(cetz.draw.rect((0,0), (1,1)))
})
tiny carbon
#

Hide is in 0.2.0.

inner crown
#

Em...

#

Is my typst binary broken then? There is no way.

tiny carbon
#

Do you have some local 0.2.0 install?

inner crown
#

Oh... hold on.

tiny carbon
#

(in the preview dir)

inner crown
#

yeah...

#

I forgot I had this.

#

I also forgot that I can save them into ~/.local/share/typst/packages/preview/cetz.

#

That's why clearing cache didn't work.

#

Thanks.

inner crown