From 6aeb792f7c203c9e52651318109341f1059a3a35 Mon Sep 17 00:00:00 2001 From: Johannes Wolf <519002+johannes-wolf@users.noreply.github.com> Date: Thu, 21 Dec 2023 23:56:18 +0100 Subject: [PATCH] Distance and Angle Path Anchors (#381) This PR adds path anchors for fixed and relative distances to most elements. Closed elements (circle, rect, arc) can also handle angle anchors. This means: `(name: "element", anchor: )` can be used to get dynamic anchors on element paths. - Arc PIE mode line strip has been fixed and is now the last element, after the arc so that all arc paths start at `arc-start`. - All paths got `start`, `mid` and `end` anchors that point to 0%, 50% and 100% of the path. --- CHANGES.md | 1 + manual.typ | 22 +- src/anchor.typ | 219 +++++++++++--- src/coordinate.typ | 27 +- src/draw/grouping.typ | 53 ++-- src/draw/shapes.typ | 434 ++++++++++++--------------- src/drawable.typ | 7 +- tests/anchor/element-anchors/ref.png | Bin 437744 -> 454720 bytes tests/anchor/path-anchors/ref.png | Bin 0 -> 291171 bytes tests/anchor/path-anchors/test.typ | 119 ++++++++ tests/arc/ref.png | Bin 241717 -> 242910 bytes tests/chart/piechart/ref.png | Bin 232835 -> 232779 bytes tests/group/transform/ref.png | Bin 254172 -> 260906 bytes tests/group/translate/ref.png | Bin 48591 -> 48591 bytes tests/plot/legend/ref.png | Bin 568500 -> 568493 bytes tests/plot/ref.png | Bin 823142 -> 822691 bytes tests/rect/rounded/ref.png | Bin 140007 -> 141449 bytes 17 files changed, 563 insertions(+), 319 deletions(-) create mode 100644 tests/anchor/path-anchors/ref.png create mode 100644 tests/anchor/path-anchors/test.typ diff --git a/CHANGES.md b/CHANGES.md index 5954aa51..3b7edd7c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ CeTZ 0.2.0 requires Typst 0.10.0 - Added Hobby curves (`hobby`) in addition to catmull (thanks to @Enivex) - Added `radius` style to `rect` for drawing rounded rects - Added `hide` function for hiding elements +- Added distance, ratio and angle anchors to elements ### Plot - Added `plot.add-contour(..)` for plotting contour plots diff --git a/manual.typ b/manual.typ index ccddfd3f..c559e945 100644 --- a/manual.typ +++ b/manual.typ @@ -70,7 +70,7 @@ Many CeTZ functions expect data in certain formats which we will call types. Not / `