-
-
Notifications
You must be signed in to change notification settings - Fork 77
canvas: Support custom coordinate systems #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
403fa78
0362d51
12805a7
458e31a
1854bdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,8 +133,6 @@ | |
| assert.eq(style.pos(), (), message: "Unexpected positional arguments: " + repr(style.pos())) | ||
| style = style.named() | ||
|
|
||
| (a, b, c).map(coordinate.resolve-system) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these should be removed, they help tell the user where they've entered an invalid coordinate
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I see why they've been removed, thats a really difficult trade off.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add some
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created a PR for a possible implementation of such functionality here: #726. |
||
|
|
||
| return (ctx => { | ||
| let (ctx, a, b, c) = coordinate.resolve(ctx, a, b, c) | ||
|
|
||
|
|
@@ -237,9 +235,6 @@ | |
| ) | ||
| let style = style.named() | ||
|
|
||
| // Coordinate check | ||
| let t = coordinate.resolve-system(position) | ||
|
|
||
| let start-angle = if start == auto { stop - delta } else { start } | ||
| let stop-angle = if stop == auto { start + delta } else { stop } | ||
| // Border angles can break if the angle is 0. | ||
|
|
@@ -462,8 +457,6 @@ | |
| to = ((rel: (to, 1), to: from)) | ||
| } | ||
|
|
||
| (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") | ||
|
|
@@ -523,9 +516,6 @@ | |
|
|
||
| assert(pts.len() >= 2, message: "Line must have a minimum of two points") | ||
|
|
||
| // Coordinate check | ||
| let pts-system = pts.map(coordinate.resolve-system) | ||
|
|
||
| // Find the intersection between line a-b next to b | ||
| // if no intersection could be found, return a. | ||
| let element-line-intersection(ctx, elem, a, b) = { | ||
|
|
@@ -551,6 +541,7 @@ | |
| return (ctx => { | ||
| let first-elem = pts.first() | ||
| let last-elem = pts.last() | ||
| let pts-system = pts.map(coordinate.resolve-system.with(ctx)) | ||
| let (ctx, ..pts) = coordinate.resolve(ctx, ..pts) | ||
|
|
||
| // If the first/last element, test for intersection | ||
|
|
@@ -622,8 +613,6 @@ | |
| /// *Root*: `polygon` | ||
| /// - radius (number) = 1: Radius of the polygon | ||
| #let polygon(origin, sides, angle: 0deg, name: none, anchor: none, ..style) = { | ||
| coordinate.resolve-system(origin) | ||
|
|
||
| assert(type(sides) == int and sides >= 3, | ||
| message: "Invalid number of sides: " + repr(sides)) | ||
|
|
||
|
|
@@ -708,8 +697,6 @@ | |
| /// ## Anchors | ||
| /// Supports border anchors. | ||
| #let grid(from, to, name: none, ..style) = { | ||
| (from, to).map(coordinate.resolve-system) | ||
|
|
||
| assert.eq(style.pos(), (), message: "Unexpected positional arguments: " + repr(style.pos())) | ||
| style = style.named() | ||
|
|
||
|
|
@@ -859,16 +846,6 @@ | |
| panic("Expected 2 or 3 positional arguments, got " + str(args.len())) | ||
| } | ||
|
|
||
| coordinate.resolve-system(a) | ||
|
|
||
| if b != auto { | ||
| coordinate.resolve-system(b) | ||
| } | ||
|
|
||
| if type(angle) != typst-angle { | ||
| coordinate.resolve-system(angle) | ||
| } | ||
|
|
||
| return (ctx => { | ||
| let body = body | ||
| let style = styles.resolve(ctx.style, merge: style, root: "content") | ||
|
|
@@ -1114,9 +1091,6 @@ | |
| /// Supports border and path anchors. It's default is the `"center"` anchor. | ||
| /// | ||
| #let rect(a, b, name: none, anchor: none, ..style) = { | ||
| // Coordinate check | ||
| let t = (a, b).map(coordinate.resolve-system) | ||
|
|
||
| // No extra positional arguments from the style sink | ||
| assert.eq( | ||
| style.pos(), | ||
|
|
@@ -1320,9 +1294,6 @@ | |
| ) | ||
| let coordinates = (start, ..ctrl, end) | ||
|
|
||
| // Coordinates check | ||
| let t = coordinates.map(coordinate.resolve-system) | ||
|
|
||
| return ( | ||
| ctx => { | ||
| let (ctx, start, ..ctrl, end) = coordinate.resolve(ctx, ..coordinates) | ||
|
|
@@ -1423,8 +1394,6 @@ | |
|
|
||
| assert(pts.len() >= 2, message: "Catmull-rom curve requires at least two points. Got " + repr(pts.len()) + "instead.") | ||
|
|
||
| pts.map(coordinate.resolve-system) | ||
|
|
||
| return (ctx => { | ||
| let (ctx, ..pts) = coordinate.resolve(ctx, ..pts) | ||
| let style = styles.resolve(ctx.style, merge: style, root: "catmull") | ||
|
|
@@ -1497,8 +1466,6 @@ | |
|
|
||
| assert(pts.len() >= 2, message: "Hobby curve requires at least two points. Got " + repr(pts.len()) + "instead.") | ||
|
|
||
| pts.map(coordinate.resolve-system) | ||
|
|
||
| return (ctx => { | ||
| let (ctx, ..pts) = coordinate.resolve(ctx, ..pts) | ||
| let style = styles.resolve(ctx.style, merge: style, root: "hobby") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #set page(width: auto, height: auto) | ||
| #import "/src/lib.typ": * | ||
| #import "/tests/helper.typ": * | ||
|
|
||
| #test-case({ | ||
| import draw: * | ||
| grid((-2,-1), (7,1), stroke: gray) | ||
|
|
||
| let log-resolver(ctx, coordinate) = { | ||
| if type(coordinate) == dictionary and "log" in coordinate { | ||
| coordinate = coordinate.log | ||
| coordinate = coordinate.map(n => calc.log(calc.max(n, util.float-epsilon), base: 10)) | ||
| } | ||
|
|
||
| return coordinate | ||
| } | ||
|
|
||
| register-coordinate-resolver(log-resolver) | ||
|
|
||
| set-style(circle: (radius: .1)) | ||
| for i in (.1, 1, 10, 100, 1000, 10000) { | ||
| let pt = (log: (i * 1, 1)) | ||
| circle(pt) | ||
| content(pt, repr(i), anchor: "north", padding: (top: .5)) | ||
| } | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.