Skip to content

Commit

Permalink
coordinate: Clean up resolve function
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Oct 13, 2024
1 parent d14797a commit 7f8f456
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/coordinate.typ
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,21 @@
/// - update (bool): Update the context's last position
/// -> array
#let resolve(ctx, ..coordinates, update: true) = {
let ctx-resolver = ctx.at("resolve-coordinate", default: none)
let coordinates = if ctx-resolver != none {
coordinates.pos().map(ctx-resolver.with(ctx))
} else {
coordinates.pos()
let resolver = ()
if type(ctx.resolve-coordinate) == array {
resolver += ctx.resolve-coordinate
} else if type(ctx.resolve-coordinate) == function {
resolver.push(ctx.resolve-coordinate)
}

let result = ()
for c in coordinates {
for c in coordinates.pos() {
for i in range(1, resolver.len() + 1) {
c = (resolver.at(resolver.len() - i))(ctx, c)
}

let t = resolve-system(ctx, c)
let out = if t == "xyz" {
c = if t == "xyz" {
resolve-xyz(c)
} else if t == "previous" {
ctx.prev.pt
Expand All @@ -358,9 +362,10 @@
}.map(util.resolve-number.with(ctx))

if update {
ctx.prev.pt = out
ctx.prev.pt = c
}
result.push(out)

result.push(c)
}

return (ctx, ..result)
Expand Down

0 comments on commit 7f8f456

Please sign in to comment.