|
198 | 198 | style: (:), |
199 | 199 | snap-to: (auto, auto), |
200 | 200 | name: none, |
201 | | - draw: auto, |
| 201 | + draw: vertices => none, |
202 | 202 | debug: auto, |
203 | 203 | ) = { |
204 | 204 |
|
205 | | - if draw == auto { |
206 | | - draw = vertices => cetz.draw.line(..vertices) |
207 | | - } |
208 | | - |
209 | 205 | (ctx => { |
210 | 206 |
|
211 | 207 | if "fletcher" not in ctx.shared-state { |
|
304 | 300 | name: none, |
305 | 301 | stroke: auto, |
306 | 302 | extrude: auto, |
| 303 | + bend: none, |
307 | 304 | draw: auto, |
308 | 305 | debug: auto, |
309 | 306 | ) = { |
|
314 | 311 | snap-to: snap-to, |
315 | 312 | outset: outset, |
316 | 313 | extrude: extrude, |
| 314 | + bend: bend, |
317 | 315 | stroke: stroke, |
318 | 316 | draw: draw, |
319 | 317 | ) |
320 | 318 |
|
321 | | - options += parsing.interpret-edge-args(args, options) |
| 319 | + options += parsing.interpret-edge-positional-args(args, options) |
322 | 320 | options += interpret-marks-arg(options.marks) |
323 | 321 |
|
324 | 322 | let stroke = (dash: options.at("dash", default: auto)) + utils.stroke-to-dict(options.stroke) |
325 | 323 |
|
| 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 | + |
326 | 354 |
|
327 | 355 | _edge( |
328 | 356 | options.vertices, |
|
0 commit comments