diff --git a/CHANGES.md b/CHANGES.md index 65d7c16a2..0c9c3d2bf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,9 @@ - `rect-around` now uses the shape instead of all anchors to compute an elements bounding box (#1022) - Fixed transformation of content frame paths along with the position in `drawable.apply-transform` - `intersections` is now using a `scope` internally to not leak body transformations +- Added special border & path anchor calculation for rects and ellipses +- Added commented out code that prepares for tikz-like border anchors + (north-east ≠ 45°) - this will be a breaking change # 0.5.0 - **BREAKING** The default matrix changed to id (#967) diff --git a/src/anchor-helper.typ b/src/anchor-helper.typ new file mode 100644 index 000000000..47ab6d6f1 --- /dev/null +++ b/src/anchor-helper.typ @@ -0,0 +1,265 @@ +#import "vector.typ" +#import "util.typ": float-epsilon + +#let _sampled-quarter-samples = 16 +#let _sampled-quarter = range(0, _sampled-quarter-samples + 1).map(t => { + t = t / _sampled-quarter-samples * 90deg + (calc.cos(t), calc.sin(t)) +}) + +// Get the circumference of a sampled quarter. +// +// -> float +#let _sampled-quarter-circumference(x-radius, y-radius) = { + let len = _sampled-quarter-samples + let u = 0 + for i in range(1, len + 1) { + let (p0x, p0y) = _sampled-quarter.at(i - 1) + p0x *= x-radius + p0y *= y-radius + + let (p1x, p1y) = _sampled-quarter.at(i) + p1x *= x-radius + p1y *= y-radius + + u += vector.dist((p0x, p0y), (p1x, p1y)) + } + return u +} + +// Lookup a sampled point on a quarter for distance s. +// +// - s (float): Distance on the quarter +// -> vector +#let _lookup-sampled-quarter-point(s, x-radius, y-radius) = { + let len = _sampled-quarter-samples + let t = 0 + for i in range(1, len + 1) { + let (p0x, p0y) = _sampled-quarter.at(i - 1) + p0x *= x-radius + p0y *= y-radius + + let (p1x, p1y) = _sampled-quarter.at(i) + p1x *= x-radius + p1y *= y-radius + let d = vector.dist((p0x, p0y), (p1x, p1y)) + + // We found our segement, lets interpolate + if t <= s and s <= t + d { + return vector.lerp((p0x, p0y), (p1x, p1y), (s - t) / d) + } + + t += d + } + + return (0, y-radius) +} + +// Lookup a point on the sampled ellipse for distance s +// +// - s (ration, float, length): Distance on the ellipses border, must be normalized +// - x-radius (float): X radius +// - y-radius (float): Y radius +// - unit-length (length): Unit length +// -> vector +// -> none +#let _lookup-ellipse-point(s, x-radius, y-radius, unit-length) = { + let qcirc = _sampled-quarter-circumference(x-radius, y-radius) + let circ = 4 * qcirc + + if type(s) == ratio { + s = s / 100% * circ + } + if type(s) == length { + s = s / unit-length + } + + // Normalize the distance to [0, circ] + s = s - calc.floor(s / circ) * circ + + // Find the quadrant we are in + let quadrant = calc.floor(s / qcirc) + let local = s - quadrant * qcirc + + return if quadrant == 0 { + _lookup-sampled-quarter-point(local, x-radius, y-radius) + } else if quadrant == 1 { + let (x, y) = _lookup-sampled-quarter-point(qcirc - local, x-radius, y-radius) + (-x, y) + } else if quadrant == 2 { + let (x, y) = _lookup-sampled-quarter-point(local, x-radius, y-radius) + (-x, -y) + } else { + let (x, y) = _lookup-sampled-quarter-point(qcirc - local, x-radius, y-radius) + (x, -y) + } +} + +// Compute a point on a circle for distance s +// +// - s (float): Distance on the circle border +// -> vector +#let _circle-point(s, radius, unit-length) = { + let circ = 2 * calc.pi * radius + + if type(s) == ratio { + s = s / 100% * circ + } + if type(s) == length { + s = s / unit-length + } + + // Normalize the distance to [0, u] + s = s - calc.floor(s / circ) * circ + + let theta = s / circ * 360deg + return (calc.cos(theta) * radius, + calc.sin(theta) * radius) +} + +/// Compute the border-anchor of a rect. +/// +/// - center (vector): Rect center point +/// - angle (angle): Angle +/// - width (float): Width of the rect +/// - height (float): Height of the rect +/// -> vector +#let compute-rect-border(center, angle, width: 1, height: 1) = { + let eps = float-epsilon + let (cx, cy, cz) = center + + // Normalize angle + angle = angle - calc.floor(angle / 360deg) * 360deg + + // Special cases for degenerate rects + if width < eps { + return (cx, cy + calc.sin(angle) * height / 2, cz) + } else if height < eps { + return (cx + calc.cos(angle) * width / 2, cy, cz) + } + + // Fast path for square rects + /* if calc.abs(width - height) < eps { */ + let sx = calc.cos(angle) + let sy = calc.sin(angle) + + if 45deg <= angle and angle <= 135deg { sy = 1 } + else if 225deg <= angle and angle <= 315deg { sy = -1 } + + if 315deg <= angle or angle <= 45deg { sx = 1 } + else if 135deg <= angle and angle <= 225deg { sx = -1 } + + return (cx + sx * width / 2, + cy + sy * height / 2, + cz) + /* } */ + +/* This is the correct code for tikz like border anchors on a circle + let radius = width * width + height * height + + let p0 = (cx - width / 2, cy + height / 2, cz) + let p1 = (cx + width / 2, cy + height / 2, cz) + let p2 = (cx + width / 2, cy - height / 2, cz) + let p3 = (cx - width / 2, cy - height / 2, cz) + + let scanline = (cx + calc.cos(angle) * radius, + cy + calc.sin(angle) * radius, + cz) + + let pt + pt = intersection.line-line(p0, p1, center, scanline) + if (pt != none) { return pt } + pt = intersection.line-line(p1, p2, center, scanline) + if (pt != none) { return pt } + pt = intersection.line-line(p2, p3, center, scanline) + if (pt != none) { return pt } + pt = intersection.line-line(p3, p0, center, scanline) + if (pt != none) { return pt } + + panic("Unreachable: rect-border", angle, center, scanline, width, height) +*/ +} + +/// Compute the path-anchor of a rect. +/// +/// - center (vector): Rect center point +/// - anchor (float, ratio): Distance +/// - width (float): Width of the rect +/// - height (float): Height of the rect +/// - unit-length (length): Canvas unit length +/// -> vector +#let compute-rect-path(center, anchor, width: 1, height: 1, unit-length: 1cm) = { + let u = width * 2 + height * 2 + if type(anchor) == ratio { + anchor = anchor / 100% * u + } + if type(anchor) == length { + anchor /= unit-length + } + + // Normalize the distance to [0, u] + anchor = anchor - calc.floor(anchor / u) * u + let (cx, cy, cz) = center + + // We start at east and go counter clockwise + let h2 = height / 2 + let w2 = width / 2 + if anchor <= h2 { return (cx + w2, cy + anchor, cz) } + anchor -= h2 + if anchor <= width { return (cx + w2 - anchor, cy + h2, cz) } + anchor -= width + if anchor <= height { return (cx - w2, cy + h2 - anchor, cz) } + anchor -= height + if anchor <= width { return (cx - w2 + anchor, cy - h2, cz) } + anchor -= width + return (cx + w2, cy - h2 + anchor, cz) +} + +/// Compute the border-anchor of an ellipse. +/// +/// - center (vector): Rect center point +/// - angle (angle): Angle +/// - x-radius (float): X radius +/// - y-radius (float): Y radius +/// -> vector +#let compute-ellipse-border(center, angle, x-radius: 1, y-radius: 1) = { + let eps = float-epsilon + + let (cx, cy, cz) = center + + // TODO: See compute-rect-border + /* if calc.abs(x-radius - y-radius) < eps { */ + return (cx + calc.cos(angle) * x-radius, + cy + calc.sin(angle) * y-radius, + cz) + /* } */ + +/* + let d = calc.sqrt(calc.pow(calc.cos(angle), 2)/(x-radius * x-radius) + calc.pow(calc.sin(angle), 2)/(y-radius * y-radius)) + let bx = calc.cos(angle) / d + let by = calc.sin(angle) / d + + return (cx + bx, cy + by, cz) +*/ +} + +/// Compute the path-anchor of an ellipse +/// +/// - center (vector): Rect center point +/// - anchor (float, ratio, length): Distance +/// - x-radius (float): X radius +/// - y-radius (float): Y radius +/// - unit-length (length): Canvas unit length +/// -> vector +#let compute-ellipse-path(center, anchor, x-radius: 1, y-radius: 1, unit-length: 1cm) = { + let eps = 1e-6 + + let (ox, oy) = if calc.abs(x-radius - y-radius) < eps { + _circle-point(anchor, x-radius, unit-length) + } else { + _lookup-ellipse-point(anchor, x-radius, y-radius, unit-length) + } + + let (cx, cy, cz) = center + return (cx + ox, cy + oy, cz) +} diff --git a/src/anchor.typ b/src/anchor.typ index 86650f17d..01a43a72d 100644 --- a/src/anchor.typ +++ b/src/anchor.typ @@ -7,6 +7,7 @@ #import "path-util.typ" #import "matrix.typ" #import "vector.typ" +#import "anchor-helper.typ": compute-rect-border, compute-rect-path, compute-ellipse-border, compute-ellipse-path // Compass direction to angle #let named-border-anchors = ( @@ -27,37 +28,37 @@ end: 100%, ) -/// Calculates a border anchor at the given angle by testing for an intersection between a line and the given drawables. Returns `none` if no intersection is found for better error reporting. +/// Calculates a border anchor at the given angle by testing for an +/// intersection between a line and the given drawables. The scan-line +/// goes from `center` to the border of an ellipse with radius `x-radius`, `y-radiu` +/// at angle `angle`. If multiple intersection points are found, the +/// one with the largest distance from `center` is returned. +/// +/// Returns `none` if no intersection is found for better error reporting. /// /// - center (vector): The position from which to start the test line. -/// - x-dist (number): The furthest distance the test line should go in the x direction. -/// - y-dist (number): The furthest distance the test line should go in the y direction. -/// - drawables (drawables): Drawables to test for an intersection against. Ideally should be of type path but all others are ignored. +/// - x-radius (number): The furthest distance the test line should go in the x direction. +/// - y-radius (number): The furthest distance the test line should go in the y direction. /// - angle (angle): The angle to check for a border anchor at. +/// - drawables (drawables): Drawables to test for an intersection against. Ideally should be of type path but all others are ignored. /// -> none /// -> vector -#let shape-border(center, x-dist, y-dist, drawables, angle) = { - x-dist += util.float-epsilon - y-dist += util.float-epsilon - +#let _shape-border(center, x-dist, y-dist, angle, drawables) = { + let eps = util.float-epsilon if type(drawables) == dictionary { drawables = (drawables,) } + let (cx, cy, cz) = center let test-line = ( center, - ( - center.at(0) + calc.abs(x-dist) * calc.cos(angle), - center.at(1) + calc.abs(y-dist) * calc.sin(angle), - center.at(2), - ) + (cx + calc.abs(x-dist + eps) * calc.cos(angle), + cy + calc.abs(y-dist + eps) * calc.sin(angle), + cz) ) let pts = () for drawable in drawables { - if drawable.type != "path" { - continue - } pts += intersection.line-path(..test-line, drawable) } @@ -73,7 +74,6 @@ } } - /// Setup an anchor calculation and handling function for an element. Unifies anchor error checking and calculation of the offset transform. /// /// A tuple of a transformation matrix and function will be returned. @@ -113,13 +113,17 @@ callback = (anchor) => {} } + if type(radii) != array { + radii = (radii, radii) + } + // Add enabled anchor names if name != none or offset-anchor != none { - if border-anchors { + if border-anchors and border-anchor-callback == none { assert("center" in anchor-names and radii != none and path != none, message: "Border anchors need a center anchor, radii and the path set!") } - if path-anchors { + if path-anchors and path-anchor-callback == none { assert.ne(path, none, message: "Path anchors need the path set!") } @@ -193,7 +197,7 @@ out = if border-anchor-callback != none { border-anchor-callback(callback("center"), anchor) } else { - shape-border(callback("center"), ..radii, path, anchor) + _shape-border(callback("center"), ..radii, anchor, path) } if out == none { panic(strfmt("Element '{}' does not have a border for anchor '{}'.", name, anchor)) diff --git a/src/draw/grouping.typ b/src/draw/grouping.typ index 716079efc..521885b17 100644 --- a/src/draw/grouping.typ +++ b/src/draw/grouping.typ @@ -291,17 +291,14 @@ aabb.padded(bounds, padding) } - // Calculate a bounding box path used for border anchor calculation. + // Calculate a bounding box used for border anchor calculation. let center = none let width = none let height = none - let path = none if bounds != none { (bounds.low.at(1), bounds.high.at(1)) = (bounds.high.at(1), bounds.low.at(1)) center = aabb.mid(bounds) (width, height, ..) = aabb.size(bounds) - - path = drawable.line-strip(aabb.corner-points(bounds), close: true) } // Children can be none if the groups array is empty @@ -313,8 +310,6 @@ } } - let is-degenerate = (width != none and util.float-eq(width, 0)) or (height != none and util.float-eq(height, 0)) - let all-anchors = if bounds != none { (default: center, center: center) } + anchors @@ -337,20 +332,11 @@ name: name, default: if bounds != none or "default" in anchors { "default" }, offset-anchor: anchor, + nested-anchors: true, path-anchors: bounds != none, border-anchors: bounds != none, - radii: (width, height), - path: path, - nested-anchors: true, - border-anchor-callback: if is-degenerate { - (center, angle) => { - let x = if util.float-eq(width, 0) { 0 } else { calc.cos(angle) } - let y = if util.float-eq(height, 0) { 0 } else { calc.sin(angle) } - return vector.add(center, (x * width / 2, y * height / 2)) - } - } else { - none - } + border-anchor-callback: anchor_.compute-rect-border.with(width: width, height: height), + path-anchor-callback: anchor_.compute-rect-path.with(width: width, height: height, unit-length: ctx.length), ) return ( diff --git a/src/draw/shapes.typ b/src/draw/shapes.typ index ad75690c4..93cce3bff 100644 --- a/src/draw/shapes.typ +++ b/src/draw/shapes.typ @@ -42,7 +42,6 @@ /// content(a, [A]); content(b, [B]) /// ``` /// -/// /// - ..points-style (coordinate, style): The position to place the circle on. /// If given two coordinates, the distance between them is used as radius. /// If given a single coordinate, the radius can be set via the `radius` (style) @@ -57,6 +56,7 @@ /// /// === Anchors /// Supports border and path anchors. The `"center"` anchor is the default. +/// Path anchors start at 0deg (east) and go counter-clockwise. /// #let circle(..points-style, name: none, anchor: none) = { let style = points-style.named() @@ -102,8 +102,8 @@ transform: ctx.transform, border-anchors: true, path-anchors: true, - radii: (rx*2, ry*2), - path: drawables, + border-anchor-callback: anchor_.compute-ellipse-border.with(x-radius: rx, y-radius: ry), + path-anchor-callback: anchor_.compute-ellipse-path.with(x-radius: rx, y-radius: ry, unit-length: ctx.length), ) return ( @@ -1020,16 +1020,16 @@ s, stroke: style.stroke, close: at-border.all(v => v))) let center = vector.lerp(from, to, .5) + let width = calc.abs(to-x - from-x) + let height = calc.abs(to-y - from-y) + let (transform, anchors) = anchor_.setup( _ => center, ("center",), name: name, transform: ctx.transform, border-anchors: true, - radii: (vector.dist(center, from) * 2,) * 2, - path: drawable.line-strip( - (from, (from.first(), to.at(1), 0), to, (to.first(), from.at(1), 0)), - close: true) + border-anchor-callback: anchor_.compute-rect-border.with(width: width, height: height) ) return ( @@ -1381,6 +1381,7 @@ /// /// == Anchors /// Supports border and path anchors. It's default is the `"center"` anchor. +/// Path anchors start at 0deg (east) and go counter-clockwise. /// #let rect(a, b, name: none, anchor: none, ..style) = { // No extra positional arguments from the style sink @@ -1419,7 +1420,7 @@ let (north-west: nw, north-east: ne, south-west: sw, south-east: se) = util.as-corner-radius-dict(ctx, style.radius, size) - let no-radius = style.radius == none or style.radius == 0 + let no-radius = style.radius == none or style.radius == 0 or (nw == (0,0) and ne == (0,0) and sw == (0,0) and se == (0,0)) let drawables = if no-radius { let segments = () // Four corner points for a non-rounded rectangle: @@ -1536,6 +1537,8 @@ path-anchors: true, radii: (width * 2, height * 2), path: drawables, + border-anchor-callback: if no-radius { anchor_.compute-rect-border.with(width: width, height: height) }, + path-anchor-callback: if no-radius { anchor_.compute-rect-path.with(width: width, height: height, unit-length: ctx.length) }, ) return ( diff --git a/tests/copy/anchor/ref/1.png b/tests/anchor/copy/ref/1.png similarity index 100% rename from tests/copy/anchor/ref/1.png rename to tests/anchor/copy/ref/1.png diff --git a/tests/copy/anchor/test.typ b/tests/anchor/copy/test.typ similarity index 100% rename from tests/copy/anchor/test.typ rename to tests/anchor/copy/test.typ diff --git a/tests/angle/ref/1.png b/tests/angle/base/ref/1.png similarity index 100% rename from tests/angle/ref/1.png rename to tests/angle/base/ref/1.png diff --git a/tests/angle/test.typ b/tests/angle/base/test.typ similarity index 100% rename from tests/angle/test.typ rename to tests/angle/base/test.typ diff --git a/tests/right/angle/ref/1.png b/tests/angle/right/ref/1.png similarity index 100% rename from tests/right/angle/ref/1.png rename to tests/angle/right/ref/1.png diff --git a/tests/right/angle/test.typ b/tests/angle/right/test.typ similarity index 100% rename from tests/right/angle/test.typ rename to tests/angle/right/test.typ diff --git a/tests/arc/previous/position/ref/1.png b/tests/arc/previous/position/ref/1.png deleted file mode 100644 index ba5384849..000000000 Binary files a/tests/arc/previous/position/ref/1.png and /dev/null differ diff --git a/tests/arc/previous/position/test.typ b/tests/arc/previous/position/test.typ deleted file mode 100644 index 8701648da..000000000 --- a/tests/arc/previous/position/test.typ +++ /dev/null @@ -1,23 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - arc((0,0), start: 0deg, stop: 180deg) - circle((), radius: .1, fill: blue) -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - - arc((0,0), start: 180deg, stop: 0deg) - circle((), radius: .1, fill: blue) -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - - arc((0,0), start: 180deg, stop: 0deg, update-position: false) - circle((), radius: .1, fill: blue) -})) diff --git a/tests/arc/ref/1.png b/tests/arc/ref/1.png deleted file mode 100644 index c852f025c..000000000 Binary files a/tests/arc/ref/1.png and /dev/null differ diff --git a/tests/arrows/ref/1.png b/tests/arrows/ref/1.png deleted file mode 100644 index f09531f46..000000000 Binary files a/tests/arrows/ref/1.png and /dev/null differ diff --git a/tests/arrows/test.typ b/tests/arrows/test.typ deleted file mode 100644 index a4d74bcd9..000000000 --- a/tests/arrows/test.typ +++ /dev/null @@ -1,112 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * -#import "/tests/helper.typ": * - -#test-case({ - import draw: * - - let next(mark) = { - line((), (rel: (1, 0)), mark: mark) - move-to((rel: (-1, .25))) - } - - set-style(fill: blue, mark: (fill: auto)) - rotate(90deg) - - let marks = (">", "<", "|", "<>", "o") //(">", "<", "|", "<>", "o") - for m in marks { - next((end: m)) - } - - for m in marks { - next((start: m)) - } - - fill(none) - - let marks = (">", "<") - for m in marks { - next((end: m)) - } - - for m in marks { - next((start: m)) - } -}) - -#test-case({ - import draw: * - - line((0,0), (9,0), stroke: blue + 1pt) - line((0,0), (9,0), stroke: green + .1pt) - line((0,-1), (9,-1), stroke: blue + 1pt) - line((0,-1), (9,-1), stroke: green + .1pt) - - set-style(mark: (stroke: (paint: green, miter-limit: 50), - fill: red)) - - for x in range(0, 18) { - line((x * .5, -1), (x * .5, 0), mark: (start: ">", end: ">", - width: (x / 50 + .05))) - } -}) - -#test-case({ - import draw: * - - line((0,0), (9,0), stroke: blue + 1pt) - line((0,0), (9,0), stroke: green + .1pt) - line((0,-1), (9,-1), stroke: blue + 1pt) - line((0,-1), (9,-1), stroke: green + .1pt) - - set-style(mark: (stroke: (paint: green, miter-limit: 50), - fill: red)) - - for x in range(0, 18) { - line((x * .5, -1), (x * .5, 0), mark: (start: "<", end: "<", - width: (x / 50 + .05))) - } -}) - -#test-case({ - import draw: * - - line((0,0), (9,0), stroke: blue + 1pt) - line((0,0), (9,0), stroke: green + .1pt) - line((0,-1), (9,-1), stroke: blue + 1pt) - line((0,-1), (9,-1), stroke: green + .1pt) - - set-style(mark: (stroke: (paint: green, miter-limit: 50, join: "round"), - fill: red)) - - for x in range(0, 18) { - line((x * .5, -1), (x * .5, 0), mark: (start: "<", end: ">", - width: (x / 50 + .05))) - } -}) - -#test-case({ - import draw: * - - line((0,0), (9,0), stroke: blue + 1pt) - line((0,0), (9,0), stroke: green + .1pt) - line((0,-1), (9,-1), stroke: blue + 1pt) - line((0,-1), (9,-1), stroke: green + .1pt) - - set-style(mark: (stroke: (paint: green, miter-limit: 50, join: "bevel"), - fill: red)) - - for x in range(0, 18) { - line((x * .5, -1), (x * .5, 0), mark: (start: "<", end: ">", - width: (x / 50 + .05))) - } -}) - -// Issue #830 -#test-case({ - import draw: * - line((0, 0), (1, 0), mark: (start: "stealth")) - line((0, -1), (1, -1), mark: (end: "stealth")) - line((0, -2), (1, -2), mark: (start: "stealth", end: "stealth")) - line((0, -3), (1, -3), mark: (symbol: "stealth",)) -}) diff --git a/tests/bounds/test.typ b/tests/bounds/test.typ index 30d13cfff..f1c13a66c 100644 --- a/tests/bounds/test.typ +++ b/tests/bounds/test.typ @@ -1,7 +1,8 @@ #set page(width: auto, height: auto) #import "/src/lib.typ": * +#import "/tests/helper.typ": * -#box(stroke: 2pt + red, canvas({ +#test-case({ import draw: * group(name: "g", { @@ -12,9 +13,9 @@ on-layer(-1, { rect("g.south-west", "g.north-east", stroke: .5pt + green) }) -})) +}) -#box(stroke: 2pt + red, canvas({ +#test-case({ import draw: * group(name: "g", { @@ -23,9 +24,9 @@ on-layer(-1, { rect("g.south-west", "g.north-east", stroke: .5pt + green) }) -})) +}) -#box(stroke: 2pt + red, canvas({ +#test-case({ import draw: * let pts = ((-1.414213562373095, 0), @@ -39,4 +40,4 @@ on-layer(-1, { rect("g.south-west", "g.north-east", stroke: .5pt + green) }) -})) +}) diff --git a/tests/set/get/ctx/ref/1.png b/tests/canvas/set-get-ctx/ref/1.png similarity index 100% rename from tests/set/get/ctx/ref/1.png rename to tests/canvas/set-get-ctx/ref/1.png diff --git a/tests/set/get/ctx/test.typ b/tests/canvas/set-get-ctx/test.typ similarity index 100% rename from tests/set/get/ctx/test.typ rename to tests/canvas/set-get-ctx/test.typ diff --git a/tests/circle/base/ref/1.png b/tests/circle/base/ref/1.png deleted file mode 100644 index af8166551..000000000 Binary files a/tests/circle/base/ref/1.png and /dev/null differ diff --git a/tests/circle/base/test.typ b/tests/circle/base/test.typ deleted file mode 100644 index ae0d8de2b..000000000 --- a/tests/circle/base/test.typ +++ /dev/null @@ -1,20 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * -#import "/tests/helper.typ": * - -#test-case(radius => { - import draw: * - - circle((0, 0), radius: radius, name: "c") - point("c.center", "M") -}, args: (1, 1cm, (1, .5), (1cm, .5), (.5, 1), (.5, 1cm))) - -#test-case(outer => { - import draw: * - - let center = (1, 1) - circle(center, outer) - move-to(center) - point(outer, "O") - point(center, "M") -}, args: ((2, 1), (rel: (1, 0)), (rel: (1, 1)))) diff --git a/tests/circle/through/ref/1.png b/tests/circle/through/ref/1.png deleted file mode 100644 index d3d3fb696..000000000 Binary files a/tests/circle/through/ref/1.png and /dev/null differ diff --git a/tests/circle/through/test.typ b/tests/circle/through/test.typ deleted file mode 100644 index 2432a83b3..000000000 --- a/tests/circle/through/test.typ +++ /dev/null @@ -1,11 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas(length: .5cm, { - import draw: * - - let (a, b, c) = ((0,0), (2,-.5), (1,1)) - line(a, b, c, close: true, stroke: gray) - circle-through(a, b, c, name: "c") - circle("c.center", radius: .05, fill: red) -})) diff --git a/tests/relative/no/update/ref/1.png b/tests/coordinate/no-update/ref/1.png similarity index 100% rename from tests/relative/no/update/ref/1.png rename to tests/coordinate/no-update/ref/1.png diff --git a/tests/relative/no/update/test.typ b/tests/coordinate/no-update/test.typ similarity index 100% rename from tests/relative/no/update/test.typ rename to tests/coordinate/no-update/test.typ diff --git a/tests/relative/length/ref/1.png b/tests/coordinate/relative/ref/1.png similarity index 100% rename from tests/relative/length/ref/1.png rename to tests/coordinate/relative/ref/1.png diff --git a/tests/relative/length/test.typ b/tests/coordinate/relative/test.typ similarity index 100% rename from tests/relative/length/test.typ rename to tests/coordinate/relative/test.typ diff --git a/tests/tangent/ref/1.png b/tests/coordinate/tangent/ref/1.png similarity index 100% rename from tests/tangent/ref/1.png rename to tests/coordinate/tangent/ref/1.png diff --git a/tests/tangent/test.typ b/tests/coordinate/tangent/test.typ similarity index 100% rename from tests/tangent/test.typ rename to tests/coordinate/tangent/test.typ diff --git a/tests/decorations/ref/1.png b/tests/decoration/brace/ref/1.png similarity index 100% rename from tests/decorations/ref/1.png rename to tests/decoration/brace/ref/1.png diff --git a/tests/decorations/test.typ b/tests/decoration/brace/test.typ similarity index 100% rename from tests/decorations/test.typ rename to tests/decoration/brace/test.typ diff --git a/tests/path/decoration/ref/1.png b/tests/decoration/path/ref/1.png similarity index 100% rename from tests/path/decoration/ref/1.png rename to tests/decoration/path/ref/1.png diff --git a/tests/path/decoration/test.typ b/tests/decoration/path/test.typ similarity index 100% rename from tests/path/decoration/test.typ rename to tests/decoration/path/test.typ diff --git a/tests/docs/torus/ref/1.png b/tests/docs/torus/ref/1.png deleted file mode 100644 index d4e08a3a0..000000000 Binary files a/tests/docs/torus/ref/1.png and /dev/null differ diff --git a/tests/element/anchors/ref.png b/tests/element/anchors/ref.png deleted file mode 100644 index 27f475551..000000000 Binary files a/tests/element/anchors/ref.png and /dev/null differ diff --git a/tests/element/anchors/ref/1.png b/tests/element/anchors/ref/1.png deleted file mode 100644 index 6fe4c61b2..000000000 Binary files a/tests/element/anchors/ref/1.png and /dev/null differ diff --git a/tests/element/anchors/test.typ b/tests/element/anchors/test.typ deleted file mode 100644 index 79929f91a..000000000 --- a/tests/element/anchors/test.typ +++ /dev/null @@ -1,111 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#let display(body, ..args) = { - import draw: * - (body)(..args, name: "elem"); - get-ctx(ctx => { - for-each-anchor( - "elem", - exclude: if args.named().at("mode", default: none) == "OPEN" { - ("east", "north-east", "north", "south", "south-east") - } else {()}, - o => { - let n = "elem." + o - - group({ - rotate(45deg) - set-style(stroke: blue) - line((rel: (-.1, 0), to: n), (rel: (.2, 0))) - line((rel: (0, -.1), to: n), (rel: (0, .2))) - }) - - let (_, nv) = coordinate.resolve(ctx, n) - let (x, y, ..) = nv - let anchor = ( - (if y < 0 { "north" } else if y > 0 { "south" },) + (if x < 0 { "east" } else if x > 0 { "west" },) - ).filter(p => p != none).join("-") - if anchor == none { - anchor = "south" - } - - content(n, text(8pt, o), anchor: anchor, padding: .2) - } - ) - }) -} - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(line, (0,0), (2,1), (4,0)) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(circle, ()) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(circle-through, (-1,0), (0,1), (1,0)) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(arc, (0,0), start: 225deg, stop: 135deg, radius: 5, mode: "OPEN") -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(arc, (0,0), start: 225deg, stop: 135deg, radius: 5, mode: "PIE") -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(arc, (0,0), start: 225deg, stop: 135deg, radius: 5, mode: "CLOSE") -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(line, (-1,0), (0,1), (1,0)) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(grid, (-1,-1), (1,1), step: 1) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(content, (), text(2cm)[Text]) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(rect, (-1,-1), (1,1)) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(rect, (-1,-1), (1,1), radius: .5) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(bezier, (-2,0), (2,0), (-1,1), (1,-1)) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(bezier, (-1,-1), (1,-1), (0,2)) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(bezier-through, (-1,-1), (0,1), (1,-1)) -})) - -#box(stroke: 2pt + red, canvas(length: 1cm, { - import draw: * - display(catmull, (-2,0), (-1,-1), (0,1), (1,-1), (2,0)) -})) diff --git a/tests/empty/base/test.typ b/tests/empty/base/test.typ deleted file mode 100644 index 3ba42b641..000000000 --- a/tests/empty/base/test.typ +++ /dev/null @@ -1 +0,0 @@ -// Empty test file diff --git a/tests/empty/group/ref/1.png b/tests/empty/group/ref/1.png deleted file mode 100644 index b96d5274d..000000000 Binary files a/tests/empty/group/ref/1.png and /dev/null differ diff --git a/tests/floating/ref/1.png b/tests/floating/ref/1.png index b800833d4..4643430ad 100644 Binary files a/tests/floating/ref/1.png and b/tests/floating/ref/1.png differ diff --git a/tests/group/anchors/ref/1.png b/tests/group/anchors/ref/1.png index cd0d3b1cc..430f31d6e 100644 Binary files a/tests/group/anchors/ref/1.png and b/tests/group/anchors/ref/1.png differ diff --git a/tests/group/anchors/test.typ b/tests/group/anchors/test.typ index aecb27b4e..5aa75a7d2 100644 --- a/tests/group/anchors/test.typ +++ b/tests/group/anchors/test.typ @@ -2,6 +2,12 @@ #import "/src/lib.typ": * #import "/tests/helper.typ": * +#test-case({ + import cetz.draw: * + + rect((-1,-1),(1,1), name:"r") + cross("r.0deg") +}) #test-case({ import cetz.draw: * diff --git a/tests/empty/base/ref/1.png b/tests/group/empty/ref/1.png similarity index 100% rename from tests/empty/base/ref/1.png rename to tests/group/empty/ref/1.png diff --git a/tests/empty/group/test.typ b/tests/group/empty/test.typ similarity index 100% rename from tests/empty/group/test.typ rename to tests/group/empty/test.typ diff --git a/tests/group/nested/anchors/ref/1.png b/tests/group/nested/ref/1.png similarity index 100% rename from tests/group/nested/anchors/ref/1.png rename to tests/group/nested/ref/1.png diff --git a/tests/group/nested/anchors/test.typ b/tests/group/nested/test.typ similarity index 100% rename from tests/group/nested/anchors/test.typ rename to tests/group/nested/test.typ diff --git a/tests/group/transform/ref/1.png b/tests/group/transform/ref/1.png index d3bac5674..34d92cd04 100644 Binary files a/tests/group/transform/ref/1.png and b/tests/group/transform/ref/1.png differ diff --git a/tests/helper.typ b/tests/helper.typ index 1133fe7b7..842db068c 100644 --- a/tests/helper.typ +++ b/tests/helper.typ @@ -1,9 +1,9 @@ #import "/src/lib.typ" as cetz /// Draw a point + label -#let point(pt, name) = { - cetz.draw.circle(pt, radius: .05cm, fill: black, stroke: none, name: "pt") - cetz.draw.content((rel: (.2cm, 0), to: "pt"), [#name], anchor: "west") +#let point(pt, name, anchor: "north", offset: (0, 0)) = { + cetz.draw.circle(pt, radius: 1pt, fill: black, stroke: none, name: "pt") + cetz.draw.content((rel: offset, to: "pt"), [#name], anchor: anchor, padding: 0.1em) } /// Draw a cross at position pt @@ -16,6 +16,67 @@ (rel: (0, len), to: pt), stroke: green, ..style) } +#let _outset-point(center, ref, distance: 0.5) = { + let d = cetz.vector.sub(ref, center) + if cetz.vector.len(d) == 0 { d = (0, 1, 0) } + cetz.vector.add(ref, cetz.vector.scale(cetz.vector.norm(d), distance)) +} + +#let show-named-anchors(center: "center", element, ..names) = { + import cetz.draw: * + for name in names.pos() { + circle(element + "." + name, radius: 1pt, fill: black, name: "pt") + if center != none { + content((_outset-point, element + "." + center, "pt"), text(7pt)[#name]) + } else { + content((rel: (0, 0.15), to: "pt"), text(7pt)[#name], anchor: "west", angle: 90deg) + } + } +} + +#let show-compass-anchors(center: "center", element, ..names) = { + import cetz.draw: * + let compass-names = ( + "north", "north-east", "north-west", + "east", "west", + "south", "south-east", "south-west") + show-named-anchors(center: center, element, ..names, ..compass-names) +} + +#let show-border-anchors(center: "center", element, ..anchors) = { + import cetz.draw: * + let angles = if anchors.pos() == () { + (0deg, 45deg, 90deg, 135deg, 180deg, 225deg, 270deg, 315deg) + } else { + anchors.pos() + } + for angle in angles { + circle((name: element, anchor: angle), radius: 1pt, fill: black, name: "pt") + if center != none { + content((_outset-point, element + "." + center, "pt"), text(7pt)[#repr(angle)]) + } else { + content((rel: (0, 0.15), to: "pt"), text(7pt)[#repr(angle)], anchor: "west", angle: 90deg) + } + } +} + +#let show-path-anchors(center: "center", element, ..anchors) = { + import cetz.draw: * + let lengths = if anchors.pos() == () { + (0, 1cm, 25%, 50%, 75%) + } else { + anchors.pos() + } + for l in lengths { + circle((name: element, anchor: l), radius: 1pt, fill: black, name: "pt") + if center != none { + content((_outset-point, element + "." + center, "pt"), text(7pt)[#repr(l)]) + } else { + content((rel: (0, 0.15), to: "pt"), text(7pt)[#repr(l)], anchor: "west", angle: 90deg) + } + } +} + /// Test case canvas surrounded by a red border #let test-case(body, ..canvas-args, args: none) = { if type(body) != function { diff --git a/tests/hobby/ref.png b/tests/hobby/ref.png deleted file mode 100644 index d43cf3424..000000000 Binary files a/tests/hobby/ref.png and /dev/null differ diff --git a/tests/image/image.png b/tests/image/image.png deleted file mode 100644 index c4b33c063..000000000 Binary files a/tests/image/image.png and /dev/null differ diff --git a/tests/image/ref/1.png b/tests/image/ref/1.png deleted file mode 100644 index 907175f8e..000000000 Binary files a/tests/image/ref/1.png and /dev/null differ diff --git a/tests/image/test.typ b/tests/image/test.typ deleted file mode 100644 index 97b0e80c0..000000000 --- a/tests/image/test.typ +++ /dev/null @@ -1,21 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - content( - (0,0), - image("image.png", width: 2cm), - anchor: "north-west", - name: "i" - ) - - set-style(radius: .1, fill: blue) - for-each-anchor("i", anchor => { - circle("i." + anchor) - }) - - fill(red); - circle(("i.north-west", 75%, "i.north-east")) -})) diff --git a/tests/line/element/element/intersection/ref.png b/tests/line/element/element/intersection/ref.png deleted file mode 100644 index ac63260e1..000000000 Binary files a/tests/line/element/element/intersection/ref.png and /dev/null differ diff --git a/tests/line/element/element/intersection/ref/1.png b/tests/line/element/element/intersection/ref/1.png deleted file mode 100644 index e562a8553..000000000 Binary files a/tests/line/element/element/intersection/ref/1.png and /dev/null differ diff --git a/tests/line/fill/rule/ref/1.png b/tests/line/fill/rule/ref/1.png deleted file mode 100644 index 2938e3670..000000000 Binary files a/tests/line/fill/rule/ref/1.png and /dev/null differ diff --git a/tests/mark/auto/offset/ref/1.png b/tests/mark/auto/offset/ref/1.png deleted file mode 100644 index 24529b08c..000000000 Binary files a/tests/mark/auto/offset/ref/1.png and /dev/null differ diff --git a/tests/mark/auto/offset/test.typ b/tests/mark/auto/offset/test.typ deleted file mode 100644 index ca23f3656..000000000 --- a/tests/mark/auto/offset/test.typ +++ /dev/null @@ -1,72 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#for w in range(1, 10) { - let w = w / 10 - let l = 1 - box(stroke: 2pt + red, canvas({ - import draw: * - - for x in range(0, 8) { - let width = (x + 1) * 1pt - let x = x * 2 - - set-style(stroke: width, mark: (width: w, length: 1, scale: .4, stroke: width)) - line((x,0), (x,3), mark: (end: ">", start: ">")) - - line((x - .5,3), (x + .5,3), stroke: .5pt + green) - line((x - .5,0), (x + .5,0), stroke: .5pt + green) - } - for x in range(0, 8) { - let width = (x + 1) * 1pt - let x = x * 2 + 2 * 8 - - set-style(stroke: width, mark: (width: w, length: 1, scale: .4, stroke: width + blue)) - line((x,0), (x,3), mark: (end: "<", start: "<")) - - line((x - .5,3), (x + .5,3), stroke: .5pt + green) - line((x - .5,0), (x + .5,0), stroke: .5pt + green) - } - })) - par([]) -} - -#box(stroke: 2pt + red, canvas({ - import draw: * - rect((1,-1), (2,2)) - rect((-2,-1), (-1,2)) - bezier((-1,-.5), (1,1), (0,-.5), (0,1), - mark: (start: ">", end: ">", fill: blue, stroke: blue, flex: false)) -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - rect((1,-1), (2,2)) - rect((-2,-1), (-1,2)) - bezier((-1,-.5), (1,1), (0,-.5), (0,1), - mark: (start: ">", end: ">", fill: blue, stroke: blue, flex: true)) -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - rect((1,-1), (2,2)) - rect((-2,-1), (-1,2)) - bezier((-1,-.5), (1,1), (0,-.5), (0,1), - mark: (start: "|", end: "o", fill: blue, stroke: blue)) -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - rect((1,-1), (2,2)) - rect((-2,-1), (-1,2)) - catmull((-1,-.5), (0,-.5), (0,1), (1,1), - mark: (start: ">", end: ">", fill: blue, stroke: blue)) -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - rect((1,-1), (2,2)) - rect((-2,-1), (-1,2)) - hobby((-1,-.5), (0,-.5), (0,1), (1,1), - mark: (start: ">", end: ">", fill: blue, stroke: blue)) -})) diff --git a/tests/custom/mark/ref/1.png b/tests/mark/custom/ref/1.png similarity index 100% rename from tests/custom/mark/ref/1.png rename to tests/mark/custom/ref/1.png diff --git a/tests/custom/mark/test.typ b/tests/mark/custom/test.typ similarity index 100% rename from tests/custom/mark/test.typ rename to tests/mark/custom/test.typ diff --git a/tests/mark/shape/transform/ref/1.png b/tests/mark/shape-transform/ref/1.png similarity index 100% rename from tests/mark/shape/transform/ref/1.png rename to tests/mark/shape-transform/ref/1.png diff --git a/tests/mark/shape/transform/test.typ b/tests/mark/shape-transform/test.typ similarity index 100% rename from tests/mark/shape/transform/test.typ rename to tests/mark/shape-transform/test.typ diff --git a/tests/mark/z/axis/ref/1.png b/tests/mark/z/ref/1.png similarity index 100% rename from tests/mark/z/axis/ref/1.png rename to tests/mark/z/ref/1.png diff --git a/tests/mark/z/axis/test.typ b/tests/mark/z/test.typ similarity index 100% rename from tests/mark/z/axis/test.typ rename to tests/mark/z/test.typ diff --git a/tests/merge/ref.png b/tests/merge-path/ref.png similarity index 100% rename from tests/merge/ref.png rename to tests/merge-path/ref.png diff --git a/tests/merge/ref/1.png b/tests/merge-path/ref/1.png similarity index 100% rename from tests/merge/ref/1.png rename to tests/merge-path/ref/1.png diff --git a/tests/merge/test.typ b/tests/merge-path/test.typ similarity index 100% rename from tests/merge/test.typ rename to tests/merge-path/test.typ diff --git a/tests/multiple/marks/ref/1.png b/tests/multiple/marks/ref/1.png deleted file mode 100644 index cb7c81ee2..000000000 Binary files a/tests/multiple/marks/ref/1.png and /dev/null differ diff --git a/tests/multiple/marks/test.typ b/tests/multiple/marks/test.typ deleted file mode 100644 index 42bed063c..000000000 --- a/tests/multiple/marks/test.typ +++ /dev/null @@ -1,23 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * -#import "/tests/helper.typ": * - -#let l = ("|", "o", ">") - -#test-case({ - import draw: * - - line((-1, -1), (1, 1), mark: (start: l, end: l)) -}) - -#test-case({ - import draw: * - - bezier((-1, -1), (1, 1), (-1, 1), (1, -1), mark: (start: l, end: l)) -}) - -#test-case({ - import draw: * - - arc((0, 0), start: 0deg, stop: 180deg, anchor: "center", mark: (start: l, end: l)) -}) diff --git a/tests/path/anchors/ref.png b/tests/path/anchors/ref.png deleted file mode 100644 index 48af39d87..000000000 Binary files a/tests/path/anchors/ref.png and /dev/null differ diff --git a/tests/path/anchors/ref/1.png b/tests/path/anchors/ref/1.png deleted file mode 100644 index faa462195..000000000 Binary files a/tests/path/anchors/ref/1.png and /dev/null differ diff --git a/tests/path/anchors/test.typ b/tests/path/anchors/test.typ deleted file mode 100644 index 3a2f3ab84..000000000 --- a/tests/path/anchors/test.typ +++ /dev/null @@ -1,132 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * -#import "/tests/helper.typ": * - -#let display(body, ..args, angle: false) = { - import draw: * - - // Fixed distance - (body)(..args, name: "elem"); - for i in (0, .5, 1) { - circle((name: "elem", anchor: i), radius: .1) - } - - set-origin((3,0)) - - (body)(..args, name: "elem"); - for i in (0%, 25%, 50%, 75%, 100%) { - circle((name: "elem", anchor: i), radius: .1) - } - - if angle { - set-origin((3,0)) - - (body)(..args, name: "elem"); - let angles = if args.named().at("mode", default: "") == "OPEN" { - (170deg, 180deg) - } else { - (0deg, 45deg, 90deg, 170deg, 180deg) - } - for i in angles { - circle((name: "elem", anchor: i), radius: .1) - } - } -} - -#test-case({ - import draw: * - display(line, (0,0), (.75,1), (1.25,-1), (2,0)) -}) - -#test-case({ - import draw: * - display(circle, (0,0), angle: true) -}) - -#test-case({ - import draw: * - display(circle-through, (-1,0), (0,1), (1,0), angle: true) -}) - -#test-case({ - import draw: * - display(arc, (0,0), start: 225deg, stop: 135deg, radius: 2, mode: "OPEN", angle: true) -}) - -#test-case({ - import draw: * - display(arc, (0,0), start: 225deg, stop: 135deg, radius: 2, mode: "PIE", angle: true) -}) - -#test-case({ - import draw: * - display(arc, (0,0), start: 225deg, stop: 135deg, radius: 2, mode: "CLOSE", angle: true) -}) - -#test-case({ - import draw: * - display(line, (-1,0), (0,1), (1,0)) -}) - -#test-case({ - import draw: * - display(rect, (-1,-1), (1,1), angle: true) -}) - -#test-case({ - import draw: * - display(rect, (-1,-1), (1,1), radius: .5) -}) - -#test-case({ - import draw: * - display(bezier, (-2,0), (2,0), (-1,1), (1,-1)) -}) - -#test-case({ - import draw: * - display(bezier, (-1,-1), (1,-1), (0,2)) -}) - -#test-case({ - import draw: * - display(bezier-through, (-1,-1), (0,1), (1,-1)) -}) - -#test-case({ - import draw: * - display(catmull, (-2,0), (-1,-1), (0,1), (1,-1), (2,0)) -}) - -#test-case({ - import draw: * - display(group, { - circle((0,0), radius: .5) - circle((1,1), radius: .7) - }, angle: true) -}) - -#test-case({ - import draw: * - - rotate(10deg) - rect((-1,-1), (1,1), name: "a") - for i in (0, 1, 2, 3, 4, 5, 6, 7) { - circle((name: "a", anchor: i), radius: .1) - } - - set-origin((3,0)) - - rect((-1,-1), (1,1), name: "a") - for i in (0%, 10%, 20%, 30%, 40%, 50%) { - circle((name: "a", anchor: i), radius: .1) - } - - set-origin((3, 0)) - - rect((-1,-1), (1,1), name: "a") - for i in range(0, 360, step: 36) { - let i = i * 1deg - circle((name: "a", anchor: i), radius: .1) - } -}) diff --git a/tests/pictures/torus/ref/1.png b/tests/pictures/torus/ref/1.png new file mode 100644 index 000000000..8b3376fb2 Binary files /dev/null and b/tests/pictures/torus/ref/1.png differ diff --git a/tests/docs/torus/test.typ b/tests/pictures/torus/test.typ similarity index 100% rename from tests/docs/torus/test.typ rename to tests/pictures/torus/test.typ diff --git a/tests/primitives/ref/1.png b/tests/primitives/ref/1.png deleted file mode 100644 index c6cafe09c..000000000 Binary files a/tests/primitives/ref/1.png and /dev/null differ diff --git a/tests/primitives/test.typ b/tests/primitives/test.typ deleted file mode 100644 index 22a5aacdd..000000000 --- a/tests/primitives/test.typ +++ /dev/null @@ -1,13 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - line((0, 0), (1, 0)) - rect((0, 1), (1, 2)) - circle((.5, 3.5), radius: .5) - arc((1, 4.5), start: 0deg, stop: 90deg, radius: .5) - bezier((0, 6), (1, 6), (.5, 5)) - bezier((0, 7), (1, 7), (.25, 6), (.75, 8)) -})) diff --git a/tests/projection/default/ref/1.png b/tests/projection/default/ref/1.png deleted file mode 100644 index 11e302e3f..000000000 Binary files a/tests/projection/default/ref/1.png and /dev/null differ diff --git a/tests/projection/default/test.typ b/tests/projection/default/test.typ deleted file mode 100644 index 6371f2712..000000000 --- a/tests/projection/default/test.typ +++ /dev/null @@ -1,23 +0,0 @@ -#import "/src/lib.typ" as cetz -#import "/tests/helper.typ": * -#set page(width: auto, height: auto) - -// Positive direction -#test-case({ - import cetz.draw: * - - set-style(mark: (transform-shape: false)) - line((0,0,0), (1,0,0), mark: (end: ">")) - line((0,0,0), (0,1,0), mark: (end: ">")) - line((0,0,0), (0,0,1), mark: (end: ">")) -}, z: (-1/2, -1/2)) - -// Negative direction -#test-case({ - import cetz.draw: * - - set-style(mark: (transform-shape: false)) - line((0,0,0), (-1,0,0), mark: (end: ">")) - line((0,0,0), (0,-1,0), mark: (end: ">")) - line((0,0,0), (0,0,-1), mark: (end: ">")) -}, z: (-1/2, -1/2)) diff --git a/tests/rect/around/base/ref/1.png b/tests/rect/around/base/ref/1.png deleted file mode 100644 index bf3e8449b..000000000 Binary files a/tests/rect/around/base/ref/1.png and /dev/null differ diff --git a/tests/rect/around/padded/ref/1.png b/tests/rect/around/padded/ref/1.png deleted file mode 100644 index b85895fc4..000000000 Binary files a/tests/rect/around/padded/ref/1.png and /dev/null differ diff --git a/tests/rect/around/padded/test.typ b/tests/rect/around/padded/test.typ deleted file mode 100644 index fa84586f9..000000000 --- a/tests/rect/around/padded/test.typ +++ /dev/null @@ -1,10 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - rect((1, 2), (rel:(1, 1)), stroke: none, fill: black, name: "r1") - rect-around("r1", stroke: yellow, radius: 0.4, padding: (top: 0.1, left: 0.2, right: 0.3, bottom: 0.4), name: "r2") - rect-around("r2", stroke: 0.5pt + black) -})) diff --git a/tests/rect/base/ref/1.png b/tests/rect/base/ref/1.png deleted file mode 100644 index 58051b331..000000000 Binary files a/tests/rect/base/ref/1.png and /dev/null differ diff --git a/tests/rect/base/test.typ b/tests/rect/base/test.typ deleted file mode 100644 index 52e1e6a05..000000000 --- a/tests/rect/base/test.typ +++ /dev/null @@ -1,13 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - rect((1,1), (0,0), name: "r") - circle("r.center", radius: .1) - circle("r.north", fill: red, radius: .1) - circle("r.south", fill: green, radius: .1) - circle("r.west", fill: blue, radius: .1) - circle("r.east", fill: yellow, radius: .1) -})) diff --git a/tests/rect/rounded/ref/1.png b/tests/rect/rounded/ref/1.png deleted file mode 100644 index ca338b3c7..000000000 Binary files a/tests/rect/rounded/ref/1.png and /dev/null differ diff --git a/tests/rect/rounded/test.typ b/tests/rect/rounded/test.typ deleted file mode 100644 index 322657329..000000000 --- a/tests/rect/rounded/test.typ +++ /dev/null @@ -1,96 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * -#import "/tests/helper.typ": * - -#let test(..args) = { - import draw: * - rect(..args, name: "r") - for-each-anchor("r", n => { - circle("r." + n, radius: .05, fill: gray) - }) -} - -#test-case({ - import draw: * - - test((-1,-1), (1,1)) -}) - -#test-case({ - import draw: * - - test((-1,-1), (1,1), radius: 0) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: .5) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: 1) -}) - -#test-case({ - import draw: * - - test((-1,-1), (1,1), radius: (north: 1)) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: (east: 1)) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: (south: 1)) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: (west: 1)) -}) - -#test-case({ - import draw: * - - test((-1,-1), (1,1), radius: (north-west: 1)) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: (north-east: 1)) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: (south-east: 1)) - set-origin((2.5, 0)) - test((-1,-1), (1,1), radius: (south-west: 1)) -}) - -#test-case({ - import draw: * - - test((-1,-1), (1,1), radius: (north-west: 1, north-east: .5, - south-west: .25, rest: 0.1)) -}) - -// Use ratio values -#test-case({ - import draw: * - - test((-1,-1), (3,1), radius: (north-west: 50%, north-east: 25%, - south-west: 10%, rest: 0)) -}) - -// Use different x & y radii -#test-case({ - import draw: * - - test((-1,-1), (3,1), radius: (north-west: (50%, .2), south-east: (50%, .2))) -}) - -// Use fixed length values -#test-case({ - import draw: * - - test((-1,-1), (3,1), radius: .5cm) -}) - -// Bug 1: small rect — .east fails, .north works -#test-case({ - import draw: * - rect((0, 0), (1, 0.45), name: "r") - circle("r.north-east", radius: 0.05, fill: blue) - circle("r.east", radius: 0.05, fill: red) -}) - -// Bug 2: rounded rect — .east fails even on large rects -#test-case({ - import draw: * - rect((0, 0), (2.4, 0.8), name: "r", radius: 0.3) - circle("r.east", radius: 0.05, fill: red) - circle("r.north-east", radius: 0.05, fill: blue) -}) diff --git a/tests/ring/ref/1.png b/tests/ring/ref/1.png deleted file mode 100644 index f03d914f8..000000000 Binary files a/tests/ring/ref/1.png and /dev/null differ diff --git a/tests/ring/test.typ b/tests/ring/test.typ deleted file mode 100644 index 79b79365a..000000000 --- a/tests/ring/test.typ +++ /dev/null @@ -1,22 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - let ring(start, end, radius) = merge-path({ - arc((0, 0), start: start, stop: end, radius: radius, - anchor: "origin", name: "outer") - - arc("outer.origin", start: end, delta: -(end - start), radius: radius - .2, - anchor: "origin", name: "inner") - - // line("outer.end", "inner.start") - }, close: true) - - stroke(black) - fill(blue) - for i in range(0, 6) { - ring((i+1) * 40deg, (i+1) * 40deg + 120deg, 2 - i * .3) - } -})) diff --git a/tests/root/anchor/ref/1.png b/tests/root/anchor/ref/1.png deleted file mode 100644 index 7261de1bd..000000000 Binary files a/tests/root/anchor/ref/1.png and /dev/null differ diff --git a/tests/root/anchor/test.typ b/tests/root/anchor/test.typ deleted file mode 100644 index a8cebf164..000000000 --- a/tests/root/anchor/test.typ +++ /dev/null @@ -1,14 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * -#import "/tests/helper.typ": * - -#test-case({ - import draw: * - - anchor("test", (1, 1)) - circle((1,1)) - - translate((3,1)) - circle("test", radius: .5, stroke: green) - circle((1,1), radius: .5, stroke: red) -}) diff --git a/tests/rotation/ref/1.png b/tests/rotation/ref/1.png deleted file mode 100644 index c1f4d67de..000000000 Binary files a/tests/rotation/ref/1.png and /dev/null differ diff --git a/tests/rotation/test.typ b/tests/rotation/test.typ deleted file mode 100644 index ec8943ddb..000000000 --- a/tests/rotation/test.typ +++ /dev/null @@ -1,76 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - group(name: "g", { - translate((-.5, .5, 0)) - - // CCW - rotate(30deg) - - rect((0, 0), (1, 1), name: "r") - anchor("1", "r.north-west") - anchor("2", "r.north-east") - anchor("3", "r.south-west") - anchor("4", "r.south-east") - }) - - stroke(green) - circle("g.1", radius: .1) - circle("g.2", radius: .1) - circle("g.3", radius: .1) - circle("g.4", radius: .1) -})) - -#let draw-xyz() = { - import draw: * - line((-1,0), (1,0), stroke: red) - line((0,-1), (0,1), stroke: blue) - line((0,0,-1), (0,0,1), stroke: green) -} - -#box(stroke: 2pt + red, canvas({ - import draw: * - - set-transform(none) - rotate(z: 45deg) - draw-xyz() -})) -#box(stroke: 2pt + red, canvas({ - import draw: * - - set-transform(none) - rotate(x: 45deg) - draw-xyz() -})) -#box(stroke: 2pt + red, canvas({ - import draw: * - - set-transform(none) - rotate(y: 45deg) - draw-xyz() -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - - set-transform(none) - rotate(yaw: 45deg) - draw-xyz() -})) -#box(stroke: 2pt + red, canvas({ - import draw: * - - set-transform(none) - rotate(pitch: 45deg) - draw-xyz() -})) -#box(stroke: 2pt + red, canvas({ - import draw: * - - set-transform(none) - rotate(roll: 45deg) - draw-xyz() -})) diff --git a/tests/shapes/arc/base/ref/1.png b/tests/shapes/arc/base/ref/1.png new file mode 100644 index 000000000..a75dd53ec Binary files /dev/null and b/tests/shapes/arc/base/ref/1.png differ diff --git a/tests/shapes/arc/base/test.typ b/tests/shapes/arc/base/test.typ new file mode 100644 index 000000000..8a010a3b9 --- /dev/null +++ b/tests/shapes/arc/base/test.typ @@ -0,0 +1,38 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ": * +#import "/tests/helper.typ": * + +#test-case(mode => { + import draw: * + + arc((0,0), start: 135deg, stop: 225deg, name: "a", mode: mode) + show-path-anchors("a") +}, args: ("OPEN", "CLOSE", "PIE")) + +#test-case(mode => { + import draw: * + + arc((0,0), start: 135deg, stop: 225deg, name: "a", mode: mode) + show-compass-anchors("a") +}, args: ("CLOSE", "PIE")) + +#test-case(mode => { + import draw: * + + arc((0,0), start: 135deg, stop: 225deg, name: "a", mode: mode) + show-border-anchors("a") +}, args: ("CLOSE", "PIE")) + +#test-case({ + import draw: * + + arc((0,0), start: 135deg, stop: 225deg, name: "a") + show-path-anchors("a") +}) + +#test-case({ + import draw: * + + arc((0,0), start: 180deg, stop: 0deg, update-position: false) + point((), [current]) +}) diff --git a/tests/shapes/arc/position/ref/1.png b/tests/shapes/arc/position/ref/1.png new file mode 100644 index 000000000..2971ce4ef Binary files /dev/null and b/tests/shapes/arc/position/ref/1.png differ diff --git a/tests/shapes/arc/position/test.typ b/tests/shapes/arc/position/test.typ new file mode 100644 index 000000000..a91e19f85 --- /dev/null +++ b/tests/shapes/arc/position/test.typ @@ -0,0 +1,17 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ": * +#import "/tests/helper.typ": * + +#test-case({ + import draw: * + + arc((0,0), start: 0deg, stop: 180deg) + point((), [current]) +}) + +#test-case({ + import draw: * + + arc((0,0), start: 180deg, stop: 0deg, update-position: false) + point((), [current]) +}) diff --git a/tests/arc/through/ref/1.png b/tests/shapes/arc/through/ref/1.png similarity index 100% rename from tests/arc/through/ref/1.png rename to tests/shapes/arc/through/ref/1.png diff --git a/tests/arc/through/test.typ b/tests/shapes/arc/through/test.typ similarity index 100% rename from tests/arc/through/test.typ rename to tests/shapes/arc/through/test.typ diff --git a/tests/catmul/ref/1.png b/tests/shapes/catmull/ref/1.png similarity index 100% rename from tests/catmul/ref/1.png rename to tests/shapes/catmull/ref/1.png diff --git a/tests/catmul/test.typ b/tests/shapes/catmull/test.typ similarity index 100% rename from tests/catmul/test.typ rename to tests/shapes/catmull/test.typ diff --git a/tests/shapes/circle-through/ref/1.png b/tests/shapes/circle-through/ref/1.png new file mode 100644 index 000000000..a3ccbeeb7 Binary files /dev/null and b/tests/shapes/circle-through/ref/1.png differ diff --git a/tests/shapes/circle-through/test.typ b/tests/shapes/circle-through/test.typ new file mode 100644 index 000000000..a0af13de7 --- /dev/null +++ b/tests/shapes/circle-through/test.typ @@ -0,0 +1,32 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ": * +#import "/tests/helper.typ": * + +#test-case({ + import draw: * + let (a, b, c) = ((0,0), (2,-.5), (1,1)) + point(a, []) + point(b, []) + point(c, []) + circle-through(a, b, c, name: "c") + point("c.center", [center], anchor: "north", offset: (0, -0.25em)) +}) + +#test-case({ + import draw: * + let (a, b, c) = ((-1, 0), (0, 0.25), (1, 0)) + point(a, []) + point(b, []) + point(c, []) + circle-through(a, b, c, name: "c") + point("c.center", [center], anchor: "north", offset: (0, -0.25em)) +}) + +#test-case({ + import draw: * + let (a, b) = ((-1, 0), (1, 0)) + point(a, []) + point(b, []) + circle-through(a, b, b, name: "c") + point("c.center", [center], anchor: "north", offset: (0, -0.25em)) +}) diff --git a/tests/shapes/circle/ref/1.png b/tests/shapes/circle/ref/1.png new file mode 100644 index 000000000..9089c1486 Binary files /dev/null and b/tests/shapes/circle/ref/1.png differ diff --git a/tests/shapes/circle/test.typ b/tests/shapes/circle/test.typ new file mode 100644 index 000000000..de18f7cee --- /dev/null +++ b/tests/shapes/circle/test.typ @@ -0,0 +1,28 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ" as cetz +#import "/tests/helper.typ": * + +#test-case(radius => { + import cetz.draw: * + circle((0, 0), name: "c", radius: radius) + show-compass-anchors("c") +}, args: (1, (2, 1))) + +#test-case(radius => { + import cetz.draw: * + circle((0, 0), name: "c", radius: radius) + show-border-anchors("c") +}, args: (1, (2, 1))) + +#test-case(radius => { + import cetz.draw: * + circle((0, 0), name: "c", radius: radius) + show-path-anchors("c") +}, args: (1, (2, 1))) + +#test-case({ + import cetz.draw: * + point((0, 0), [center], anchor: "north", offset: (0, -0.1)) + point((1, 1), [M], anchor: "south-west", offset: (0.1, 0.1)) + circle((0, 0), (1, 1)) +}) diff --git a/tests/content/anchors/ref/1.png b/tests/shapes/content/anchors/ref/1.png similarity index 100% rename from tests/content/anchors/ref/1.png rename to tests/shapes/content/anchors/ref/1.png diff --git a/tests/content/anchors/test.typ b/tests/shapes/content/anchors/test.typ similarity index 100% rename from tests/content/anchors/test.typ rename to tests/shapes/content/anchors/test.typ diff --git a/tests/content/base/ref/1.png b/tests/shapes/content/base/ref/1.png similarity index 100% rename from tests/content/base/ref/1.png rename to tests/shapes/content/base/ref/1.png diff --git a/tests/content/base/test.typ b/tests/shapes/content/base/test.typ similarity index 100% rename from tests/content/base/test.typ rename to tests/shapes/content/base/test.typ diff --git a/tests/content/intersection/ref/1.png b/tests/shapes/content/intersection/ref/1.png similarity index 100% rename from tests/content/intersection/ref/1.png rename to tests/shapes/content/intersection/ref/1.png diff --git a/tests/content/intersection/test.typ b/tests/shapes/content/intersection/test.typ similarity index 100% rename from tests/content/intersection/test.typ rename to tests/shapes/content/intersection/test.typ diff --git a/tests/content/padding/ref/1.png b/tests/shapes/content/padding/ref/1.png similarity index 100% rename from tests/content/padding/ref/1.png rename to tests/shapes/content/padding/ref/1.png diff --git a/tests/content/padding/test.typ b/tests/shapes/content/padding/test.typ similarity index 100% rename from tests/content/padding/test.typ rename to tests/shapes/content/padding/test.typ diff --git a/tests/content/rotation/ref/1.png b/tests/shapes/content/rotation/ref/1.png similarity index 100% rename from tests/content/rotation/ref/1.png rename to tests/shapes/content/rotation/ref/1.png diff --git a/tests/content/rotation/test.typ b/tests/shapes/content/rotation/test.typ similarity index 100% rename from tests/content/rotation/test.typ rename to tests/shapes/content/rotation/test.typ diff --git a/tests/content/rtl/ref.png b/tests/shapes/content/rtl/ref.png similarity index 100% rename from tests/content/rtl/ref.png rename to tests/shapes/content/rtl/ref.png diff --git a/tests/content/rtl/ref/1.png b/tests/shapes/content/rtl/ref/1.png similarity index 100% rename from tests/content/rtl/ref/1.png rename to tests/shapes/content/rtl/ref/1.png diff --git a/tests/content/rtl/test.typ b/tests/shapes/content/rtl/test.typ similarity index 100% rename from tests/content/rtl/test.typ rename to tests/shapes/content/rtl/test.typ diff --git a/tests/content/span/ref/1.png b/tests/shapes/content/span/ref/1.png similarity index 100% rename from tests/content/span/ref/1.png rename to tests/shapes/content/span/ref/1.png diff --git a/tests/content/span/test.typ b/tests/shapes/content/span/test.typ similarity index 100% rename from tests/content/span/test.typ rename to tests/shapes/content/span/test.typ diff --git a/tests/content/transform/ref/1.png b/tests/shapes/content/transform/ref/1.png similarity index 100% rename from tests/content/transform/ref/1.png rename to tests/shapes/content/transform/ref/1.png diff --git a/tests/content/transform/test.typ b/tests/shapes/content/transform/test.typ similarity index 100% rename from tests/content/transform/test.typ rename to tests/shapes/content/transform/test.typ diff --git a/tests/content/wrap/ref/1.png b/tests/shapes/content/wrap/ref/1.png similarity index 100% rename from tests/content/wrap/ref/1.png rename to tests/shapes/content/wrap/ref/1.png diff --git a/tests/content/wrap/test.typ b/tests/shapes/content/wrap/test.typ similarity index 100% rename from tests/content/wrap/test.typ rename to tests/shapes/content/wrap/test.typ diff --git a/tests/grid/ref/1.png b/tests/shapes/grid/ref/1.png similarity index 100% rename from tests/grid/ref/1.png rename to tests/shapes/grid/ref/1.png diff --git a/tests/grid/test.typ b/tests/shapes/grid/test.typ similarity index 100% rename from tests/grid/test.typ rename to tests/shapes/grid/test.typ diff --git a/tests/hobby/ref/1.png b/tests/shapes/hobby/ref/1.png similarity index 100% rename from tests/hobby/ref/1.png rename to tests/shapes/hobby/ref/1.png diff --git a/tests/hobby/test.typ b/tests/shapes/hobby/test.typ similarity index 100% rename from tests/hobby/test.typ rename to tests/shapes/hobby/test.typ diff --git a/tests/shapes/line/base/test.typ b/tests/shapes/line/base/test.typ new file mode 100644 index 000000000..1438c261a --- /dev/null +++ b/tests/shapes/line/base/test.typ @@ -0,0 +1,27 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ": * +#import "/tests/helper.typ": * + +#test-case({ + import draw: * + line((0, 0), (3, 0), name: "l") + show-path-anchors("l", center: none) +}) + +#test-case({ + import draw: * + line((0, 0), (3, 0), name: "l") + show-named-anchors("l", "start", "mid", "end", center: none) +}) + +#test-case({ + import draw: * + line((0, 0), (3, 1), (rel: (1, -1)), name: "l") + show-path-anchors("l", center: none) +}) + +#test-case({ + import draw: * + line((0, 0), (3, 1), (rel: (1, -1)), name: "l") + show-named-anchors("l", "start", "mid", "end", center: none) +}) diff --git a/tests/line/element/element/intersection/test.typ b/tests/shapes/line/element-coordinates/test.typ similarity index 100% rename from tests/line/element/element/intersection/test.typ rename to tests/shapes/line/element-coordinates/test.typ diff --git a/tests/line/fill/rule/test.typ b/tests/shapes/line/fill-rule/test.typ similarity index 99% rename from tests/line/fill/rule/test.typ rename to tests/shapes/line/fill-rule/test.typ index a0de82d0c..0eab5e4e1 100644 --- a/tests/line/fill/rule/test.typ +++ b/tests/shapes/line/fill-rule/test.typ @@ -1,5 +1,4 @@ #set page(width: auto, height: auto) - #import "/src/lib.typ": * #import "/tests/helper.typ": * diff --git a/tests/polygon/ref/1.png b/tests/shapes/polygon/ref/1.png similarity index 100% rename from tests/polygon/ref/1.png rename to tests/shapes/polygon/ref/1.png diff --git a/tests/polygon/test.typ b/tests/shapes/polygon/test.typ similarity index 100% rename from tests/polygon/test.typ rename to tests/shapes/polygon/test.typ diff --git a/tests/shapes/rect/around/ref/1.png b/tests/shapes/rect/around/ref/1.png new file mode 100644 index 000000000..6d3df6fd2 Binary files /dev/null and b/tests/shapes/rect/around/ref/1.png differ diff --git a/tests/rect/around/base/test.typ b/tests/shapes/rect/around/test.typ similarity index 89% rename from tests/rect/around/base/test.typ rename to tests/shapes/rect/around/test.typ index 70dcf2f15..9089424e3 100644 --- a/tests/rect/around/base/test.typ +++ b/tests/shapes/rect/around/test.typ @@ -5,10 +5,10 @@ #test-case({ import draw: * - circle((1, 1), radius: 0.1, fill: blue, name: "c1") - circle((0, 1), radius: 0.1, fill: red, name: "c2") + circle((1, 1), radius: 0.1, name: "c1") + circle((0, 1.5), radius: 0.1, name: "c2") rect((0, 2), (1, 2.5), name: "r1") - rect-around("c1", "c2", "r1", (0.5, 0.5), stroke: yellow, padding: 0.1) + rect-around("c1", "c2", "r1", (0.5, 0.5), padding: 0.1) }) #test-case({ diff --git a/tests/shapes/rect/base/ref/1.png b/tests/shapes/rect/base/ref/1.png new file mode 100644 index 000000000..6ccedde2f Binary files /dev/null and b/tests/shapes/rect/base/ref/1.png differ diff --git a/tests/shapes/rect/base/test.typ b/tests/shapes/rect/base/test.typ new file mode 100644 index 000000000..efaac631f --- /dev/null +++ b/tests/shapes/rect/base/test.typ @@ -0,0 +1,21 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ" as cetz +#import "/tests/helper.typ": * + +#test-case(pt => { + import cetz.draw: * + rect((0, 0), pt, name: "r") + show-compass-anchors("r") +}, args: ((1, 1), (2, 1))) + +#test-case(pt => { + import cetz.draw: * + rect((0, 0), pt, name: "r") + show-border-anchors("r") +}, args: ((1, 1), (2, 1))) + +#test-case(pt => { + import cetz.draw: * + rect((0, 0), pt, name: "r") + show-path-anchors("r") +}, args: ((1, 1), (2, 1))) diff --git a/tests/shapes/rect/rounded/ref/1.png b/tests/shapes/rect/rounded/ref/1.png new file mode 100644 index 000000000..b66a794ce Binary files /dev/null and b/tests/shapes/rect/rounded/ref/1.png differ diff --git a/tests/shapes/rect/rounded/test.typ b/tests/shapes/rect/rounded/test.typ new file mode 100644 index 000000000..c707e88c0 --- /dev/null +++ b/tests/shapes/rect/rounded/test.typ @@ -0,0 +1,23 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ" as cetz +#import "/tests/helper.typ": * + +#let r = (rest: 0.25, north-west: 1, south-west: 0, south-east: (0.5, 0.1)) + +#test-case(pt => { + import cetz.draw: * + rect((0, 0), pt, name: "r", radius: r) + show-compass-anchors("r") +}, args: ((1, 1), (2, 1))) + +#test-case(pt => { + import cetz.draw: * + rect((0, 0), pt, name: "r", radius: r) + show-border-anchors("r") +}, args: ((1, 1), (2, 1))) + +#test-case(pt => { + import cetz.draw: * + rect((0, 0), pt, name: "r", radius: r) + show-path-anchors("r") +}, args: ((1, 1), (2, 1))) diff --git a/tests/rotate/around/ref/1.png b/tests/transform/rotate-around/ref/1.png similarity index 100% rename from tests/rotate/around/ref/1.png rename to tests/transform/rotate-around/ref/1.png diff --git a/tests/rotate/around/test.typ b/tests/transform/rotate-around/test.typ similarity index 100% rename from tests/rotate/around/test.typ rename to tests/transform/rotate-around/test.typ diff --git a/tests/translation/ref/1.png b/tests/translation/ref/1.png deleted file mode 100644 index 6cd25d237..000000000 Binary files a/tests/translation/ref/1.png and /dev/null differ diff --git a/tests/translation/test.typ b/tests/translation/test.typ deleted file mode 100644 index 540b60b4a..000000000 --- a/tests/translation/test.typ +++ /dev/null @@ -1,52 +0,0 @@ -#set page(width: auto, height: auto) -#import "/src/lib.typ": * - -#box(stroke: 2pt + red, canvas({ - import draw: * - - group(name: "g", { - translate((-1.5, .5, 0)) - - rect((0, 0), (1, 1)) - anchor("tl", (0, 0)) - anchor("tr", (1, 0)) - anchor("bl", (0, 1)) - anchor("br", (1, 1)) - }) - - group({ - line((-2, 0), (2, 0)) - line((0, -2), (0, 2)) - }) - - stroke(green) - circle("g.tl", radius: .1) - circle("g.tr", radius: .1) - circle("g.bl", radius: .1) - circle("g.br", radius: .1) -})) - -#box(stroke: 2pt + red, canvas({ - import draw: * - - rect((0, 0), (1, 1), name: "a", fill: blue) - content("a.center", [A]) - - // The translation must not get scaled to 2, - // the rects have to touch at the edge. - group({ - translate((0, 1)) - scale(2) - rect((0, 0), (1, 1), name: "b", fill: green) - content("b.center", [B]) - }) - - // Translation should get scaled if multiplied post - // scaling. - group({ - scale(2) - translate((.5, 0), pre: false) - rect((0, 0), (.5, .5), name: "c", fill: red) - content("c.center", [C]) - }) -}))