Skip to content

Commit 41698ff

Browse files
committed
edge bend
1 parent 15787f9 commit 41698ff

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/edges.typ

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,10 @@
198198
style: (:),
199199
snap-to: (auto, auto),
200200
name: none,
201-
draw: auto,
201+
draw: vertices => none,
202202
debug: auto,
203203
) = {
204204

205-
if draw == auto {
206-
draw = vertices => cetz.draw.line(..vertices)
207-
}
208-
209205
(ctx => {
210206

211207
if "fletcher" not in ctx.shared-state {
@@ -304,6 +300,7 @@
304300
name: none,
305301
stroke: auto,
306302
extrude: auto,
303+
bend: none,
307304
draw: auto,
308305
debug: auto,
309306
) = {
@@ -314,15 +311,46 @@
314311
snap-to: snap-to,
315312
outset: outset,
316313
extrude: extrude,
314+
bend: bend,
317315
stroke: stroke,
318316
draw: draw,
319317
)
320318

321-
options += parsing.interpret-edge-args(args, options)
319+
options += parsing.interpret-edge-positional-args(args, options)
322320
options += interpret-marks-arg(options.marks)
323321

324322
let stroke = (dash: options.at("dash", default: auto)) + utils.stroke-to-dict(options.stroke)
325323

324+
// bent arc edges
325+
if options.bend != none {
326+
if options.draw != auto {
327+
utils.error("cannot set edge options `bend` and `draw` simultaneously")
328+
}
329+
330+
options.draw = vertices => {
331+
if vertices.len() != 2 {
332+
utils.error("edge with `bend` must have two vertices; got #0", vertices)
333+
}
334+
let (a, b) = vertices
335+
336+
let perp-dist = if type(bend) == angle {
337+
let sin-bend = calc.sin(bend)
338+
if calc.abs(sin-bend) < 1e-3 { return cetz.draw.line(a, b) }
339+
let half-chord-len = cetz.vector.dist(a, b)/2
340+
half-chord-len*(1 - calc.cos(bend))/sin-bend
341+
} else {
342+
bend
343+
}
344+
345+
let midpoint = (a: (a, 50%, b), b: a, number: perp-dist, angle: -90deg)
346+
cetz.draw.merge-path(cetz.draw.arc-through(a, midpoint, b))
347+
}
348+
}
349+
350+
if options.draw == auto {
351+
options.draw = vertices => cetz.draw.line(..vertices)
352+
}
353+
326354

327355
_edge(
328356
options.vertices,

0 commit comments

Comments
 (0)