From 628deb943ab4218a20301e6576f4ac2b1a24ce3e Mon Sep 17 00:00:00 2001 From: johannes-wolf Date: Thu, 28 Dec 2023 15:59:56 +0100 Subject: [PATCH] mark: Cleanup & Port of 75972d --- src/drawable.typ | 2 ++ src/mark.typ | 38 ++++++++++++++------------------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/drawable.typ b/src/drawable.typ index 68dce7d2..195a7722 100644 --- a/src/drawable.typ +++ b/src/drawable.typ @@ -11,6 +11,8 @@ return () } for drawable in drawables { + assert(type(drawable) != array, + message: "Expected drawable, got array: " + repr(drawable)) if drawable.type == "path" { drawable.segments = drawable.segments.map(s => { return (s.at(0),) + util.apply-transform(transform, ..s.slice(1)) diff --git a/src/mark.typ b/src/mark.typ index b79b5be1..ac2fd1c7 100644 --- a/src/mark.typ +++ b/src/mark.typ @@ -112,37 +112,22 @@ return mark } -/// Places a mark with the given style at a position pointing towards in the direction of the given angle. -/// - style (dictionary): A dictionary of keys in order to style the mark. The following are the required keys. +/// Places one or more marks with the given styles on path segments. +/// - ctx (context): +/// - styles (dictionary): A dictionary of keys in order to style the mark. The following are the required keys. /// - stroke /// - fill /// - width /// - length /// - symbol /// - inset -/// - pos (vector): The position to place the mark at. -/// - angle (angle): The direction to point the mark towards. +/// - segments (array): List of path segments +/// - is-end (bool): If false, marks get placed in the direction from the first segment to the last +/// segment; in reverse order if true. /// -> A dictionary with the keys: /// - drawables (drawables): The transformed drawables of the mark. -/// - distance: The distance between the tip of the mark and the end. -#let place-mark(ctx, style, pos, angle) = { - let (mark-fn, reverse) = get-mark(ctx, style.symbol) - style.reverse = (style.reverse or reverse) and not (style.reverse and reverse) - let (drawables, distance, tip-offset) = mark-fn(style) - - return ( - drawables: drawable.apply-transform( - matrix.mul-mat( - matrix.transform-translate(..pos), - matrix.transform-rotate-z(angle), - matrix.transform-translate(tip-offset, 0, 0) - ), - drawables - ), - distance: distance + tip-offset - ) -} - +/// - distance (float): The distance between the tip of the mark and the end. +/// - pos (vector): The position the path segments must get shortened to. #let place-mark-on-path(ctx, styles, segments, is-end: false) = { if type(styles) != array { styles = (styles,) @@ -292,7 +277,12 @@ snap-to.last() = pt } if distance != (0, 0) { - segments = path-util.shorten-path(segments, ..distance, mode: if style.flex { "CURVED" } else { "LINEAR" }, samples: style.position-samples, snap-to: snap-to) + segments = path-util.shorten-path( + segments, + ..distance, + mode: if style.flex { "CURVED" } else { "LINEAR" }, + samples: style.position-samples, + snap-to: snap-to) } return (drawables, segments)