diff --git a/CHANGES.md b/CHANGES.md index ef3bbd84c..306a41deb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,9 @@ CeTZ 0.3.0 requires Typst 0.11.0 The licence changed from Apache-2.0 to GPLv3. ## Canvas -- Add runtime cetz version check support (see `assert-version`) +- Marks drawn using the `mark` function now respect the `transform-shape` style. +- The second argument of `mark` is now optional and defaults to `0deg`. +- Add runtime cetz version check support (see `assert-version`). - Fixed a bug with `#set place(float: true)` affecting the canvas. - Transformation matrices are now rounded - The default coordinate system changed to a right-hand side system. diff --git a/src/draw/shapes.typ b/src/draw/shapes.typ index 057573bde..dac1b9a2b 100644 --- a/src/draw/shapes.typ +++ b/src/draw/shapes.typ @@ -428,6 +428,9 @@ /// Note: To place a mark centered at the first coodinate (`from`) use /// the marks `anchor: "center"` style. /// +/// To place marks unaffected by the current transformation, set their +/// `transform-shape` style to `false`. +/// /// = parameters /// /// = Styling @@ -436,27 +439,26 @@ /// /// - from (coordinate): The position to place the mark. /// - to (coordinate,angle): The position or angle the mark should point towards. -/// - ..style (style): -#let mark(from, to, ..style) = { - assert.eq( - style.pos(), - (), - message: "Unexpected positional arguments: " + repr(style.pos()), - ) - - let style = style.named() - - if type(to) == angle { - // Construct a coordinate pointing (+1, 0) away from - // `from`, rotated by the angle given. - to = ((rel: (to, 1), to: from)) +/// - ..args-style (coordinate,angle,style): An optional secondary position or angle +/// to rotate the mark by and the marks style key value pairs (including `symbol:` to set the mark shape). +#let mark(from, ..args-style) = { + assert(args-style.pos().len() <= 1, + message: "Unexpected positional arguments: " + repr(args-style.pos())) + + let style = args-style.named() + + let to-angle = args-style.pos().at(0, default: 0deg) + let to = if type(to-angle) == angle { + (rel: (to-angle, 1), to: from) + } else if to-angle != none { + to-angle } (from, to).map(coordinate.resolve-system) return (ctx => { - let (ctx, ..pts) = coordinate.resolve(ctx, from, to) let style = styles.resolve(ctx.style, merge: style, root: "mark") + let (ctx, ..pts) = coordinate.resolve(ctx, from, to) if style.end == none { style.end = style.symbol @@ -471,7 +473,11 @@ drawables = mark_.place-marks-along-path(ctx, style, none, drawables, add-path: false) return ( ctx: ctx, - drawables: drawable.apply-transform(ctx.transform, drawables) + drawables: if style.transform-shape { + drawable.apply-transform(ctx.transform, drawables) + } else { + drawables + } ) },) } diff --git a/tests/mark/shape-transform/ref/1.png b/tests/mark/shape-transform/ref/1.png index 0ba5a5ff2..a21f64a69 100644 Binary files a/tests/mark/shape-transform/ref/1.png and b/tests/mark/shape-transform/ref/1.png differ diff --git a/tests/mark/shape-transform/test.typ b/tests/mark/shape-transform/test.typ index f16fcd70b..cc9bcf599 100644 --- a/tests/mark/shape-transform/test.typ +++ b/tests/mark/shape-transform/test.typ @@ -28,3 +28,14 @@ rotate(45deg) line((-1,-1), (1,-1), (1,1), mark: (start: "rect", end: "rect", scale: 3)) }) + +#test-case({ + import cetz.draw: * + + set-style(mark: (transform-shape: false)) + + rotate(30deg) + rect((-1,-1), (1,1)) + + mark((0,0), symbol: "x") +}) diff --git a/tests/mark/single/ref/1.png b/tests/mark/single/ref/1.png index 9abf3e0af..c4d5b9a60 100644 Binary files a/tests/mark/single/ref/1.png and b/tests/mark/single/ref/1.png differ diff --git a/tests/mark/single/test.typ b/tests/mark/single/test.typ index b426b9fd8..05e4ac312 100644 --- a/tests/mark/single/test.typ +++ b/tests/mark/single/test.typ @@ -28,3 +28,10 @@ mark((0,0), 180deg, symbol: ">", scale: 3, fill: red) mark((0,0), 270deg, symbol: ">", scale: 3, fill: yellow) }) + +// Default angle +#test-case({ + import draw: * + + mark((0,0), symbol: ">") +})