Skip to content

Commit

Permalink
Review stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Aug 28, 2024
1 parent abacf13 commit 9cc34a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/draw/styling.typ
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@
/// register-mark(":)", style => {
/// circle((0,0), radius: .5, fill: yellow)
/// arc((0,0), start: 180deg + 30deg, delta: 180deg - 60deg, anchor: "origin", radius: .3)
/// circle((-.15, +.15), radius: .1, fill: white)
/// circle((-.10, +.10), radius: .025, fill: black)
/// circle((+.15, +.15), radius: .1, fill: white)
/// circle((+.20, +.10), radius: .025, fill: black)
/// circle((-0.15, 0.15), radius: .1, fill: white)
/// circle((-0.10, 0.10), radius: .025, fill: black)
/// circle(( 0.15, 0.15), radius: .1, fill: white)
/// circle(( 0.20, 0.10), radius: .025, fill: black)
///
/// anchor("tip", (+.5, 0))
/// anchor("base", (-.5, 0))
/// anchor("tip", ( 0.5, 0))
/// anchor("base", (-0.5, 0))
/// })
///
/// line((0,0), (3,0), mark: (end: ":)"))
/// ```
///
/// - symbol (string): Mark name
/// - mnemonic (none,string): Mark short name
/// - symbol (str): Mark name
/// - mnemonic (none,str): Mark short name
/// - body (function): Mark drawing callback, receiving the mark style as argument and returning elements. Format `(styles) => elements`.
#let register-mark(symbol, body, mnemonic: none) = {
assert(type(symbol) == str)
Expand Down
37 changes: 19 additions & 18 deletions src/mark-shapes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
return calc.sin(angle/2) * (style.stroke.thickness / 2)
}

#let tip-base(style, tip, base, center: none) = {
#let create-tip-and-base-anchor(style, tip, base, center: none) = {
if base == tip { base = vector.add(tip, (1e-8, 0, 0)) }
let dir = vector.norm(vector.sub(tip, base))

Expand All @@ -43,7 +43,7 @@
anchor("base", vector.sub(base, vector.scale(dir, style.stroke.thickness / 2)))
}

#let triangle-tip-base(style, tip, base, center: none) = {
#let create-triangle-tip-and-base-anchor(style, tip, base, center: none) = {
if base == tip { base = vector.add(tip, (1e-8, 0, 0)) }
let dir = vector.norm(vector.sub(tip, base))

Expand All @@ -56,7 +56,7 @@
anchor("base", vector.sub(base, vector.scale(dir, style.stroke.thickness / 2)))
}

#let diamond-tip-base(style, tip, base, center: none, ratio: 50%) = {
#let create-diamond-tip-and-base-anchor(style, tip, base, center: none, ratio: 50%) = {
if base == tip { base = vector.add(tip, (1e-8, 0, 0)) }
let dir = vector.norm(vector.sub(tip, base))

Expand Down Expand Up @@ -89,8 +89,9 @@
line((0,0), (style.length, -style.width / 2), (style.length, +style.width / 2), close: true)
}

triangle-tip-base(style, (0, 0), (style.length, 0))
create-triangle-tip-and-base-anchor(style, (0, 0), (style.length, 0))
},
// A mark in the shape of an arrow tip.
stealth: (style) => {
import "/src/draw.typ": *

Expand All @@ -102,7 +103,7 @@
line((0,0), (l, w / 2), (l - i, 0), (l, -w / 2), close: true)
}

triangle-tip-base(style, (0, 0), (l - i, 0))
create-triangle-tip-and-base-anchor(style, (0, 0), (l - i, 0))
},
bar: (style) => {
import "/src/draw.typ": *
Expand All @@ -115,7 +116,7 @@
line((0, w / 2), (0, -w / 2))
}

tip-base(style, (0, 0), (0, 0))
create-tip-and-base-anchor(style, (0, 0), (0, 0))
},
ellipse: (style) => {
import "/src/draw.typ": *
Expand All @@ -128,7 +129,7 @@
circle((0, 0), radius: r)
}

tip-base(style, (r.at(0), 0), (-r.at(0), 0))
create-tip-and-base-anchor(style, (r.at(0), 0), (-r.at(0), 0))
},
circle: (style) => {
import "/src/draw.typ": *
Expand All @@ -141,7 +142,7 @@
circle((0, 0), radius: r)
}

tip-base(style, (r, 0), (-r, 0))
create-tip-and-base-anchor(style, (r, 0), (-r, 0))
},
bracket: (style) => {
import "/src/draw.typ": *
Expand All @@ -154,7 +155,7 @@
line((-l - i, w / 2), (0, w / 2), (0, -w / 2), (-l - i, -w / 2), fill: none)
}

tip-base(style, (0, 0), (-1e-8, 0), center: ((-l - i) / 2, 0))
create-tip-and-base-anchor(style, (0, 0), (-1e-8, 0), center: ((-l - i) / 2, 0))
},
diamond: (style) => {
import "/src/draw.typ": *
Expand All @@ -167,7 +168,7 @@
line((0,0), (l / 2, w / 2), (l, 0), (l / 2, -w / 2), close: true)
}

diamond-tip-base(style, (0, 0), (l, 0))
create-diamond-tip-and-base-anchor(style, (0, 0), (l, 0))
},
rect: (style) => {
import "/src/draw.typ": *
Expand All @@ -180,7 +181,7 @@
rect((0, -w / 2), (-l, +w / 2))
}

tip-base(style, (0, 0), (-l, 0))
create-tip-and-base-anchor(style, (0, 0), (-l, 0))
},
hook: (style) => {
import "/src/draw.typ": *
Expand All @@ -199,8 +200,9 @@

line((0, 0), (l - r, 0))

tip-base(style, (-r, 0), (l - r, 0), center: ((-r + i) / 2, 0))
create-tip-and-base-anchor(style, (-r, 0), (l - r, 0), center: ((-r + i) / 2, 0))
},
// An unfilled mark in the shape of an angle bracket (>).
straight: (style) => {
import "/src/draw.typ": *

Expand All @@ -212,7 +214,7 @@
line((l, w / 2), (0, 0), (l, -w / 2), fill: none)
}

triangle-tip-base(style, (0, 0), (0, 0))
create-triangle-tip-and-base-anchor(style, (0, 0), (0, 0))
},
barbed: (style) => {
import "/src/draw.typ": *
Expand All @@ -222,7 +224,6 @@

let (l, w) = (style.length, style.width)

// Force join to "round" as other joins look bad
let ctrl-a = (l, 0)
let ctrl-b = (0, 0)

Expand All @@ -233,7 +234,7 @@
}
}, ..style)

tip-base(style, (0, 0), (1e-6, 0))
create-tip-and-base-anchor(style, (0, 0), (1e-6, 0))
},
plus: (style) => {
import "/src/draw.typ": *
Expand All @@ -246,7 +247,7 @@
line((-l / 2, 0), (+l / 2, 0))
line((0, -w / 2), (0, +w / 2))

tip-base(style, (0, 0), (l / 2, 0))
create-tip-and-base-anchor(style, (0, 0), (l / 2, 0))
},
x: (style) => {
import "/src/draw.typ": *
Expand All @@ -259,7 +260,7 @@
line((-l / 2, w / 2), (+l / 2, -w / 2))
line((-l / 2, -w / 2), (+l / 2, +w / 2))

tip-base(style, (0, 0), (0, 0))
create-tip-and-base-anchor(style, (0, 0), (0, 0))
},
star: (style) => {
import "/src/draw.typ": *
Expand All @@ -272,7 +273,7 @@
line((0, 0), (calc.cos(a) * l / 2, calc.sin(a) * w / 2))
}

tip-base(style, (0, 0), (l / 2, 0))
create-tip-and-base-anchor(style, (0, 0), (l / 2, 0))
},
)
#let names = marks.keys()
Expand Down
8 changes: 4 additions & 4 deletions src/mark.typ
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@
mark.offset = vector.dist(origin, tip)

let t = (
/* Translate & rotate to the target coordinate & direction */
// Translate & rotate to the target coordinate & direction
matrix.transform-translate(..pos),
matrix.transform-rotate-dir(dir, up),
matrix.transform-rotate-z(-90deg),

/* Apply mark transformations */
// Apply mark transformations
if reverse {
matrix.transform-translate(-mark.length, 0, 0)
},
Expand Down Expand Up @@ -158,7 +158,7 @@
return mark
}

#let _eval-mark(ctx, mark, style) = {
#let _eval-mark-shape-and-anchors(ctx, mark, style) = {
if "eval-mark-guard" in ctx {
panic("Recursive mark drawing is not allowed")
}
Expand Down Expand Up @@ -258,7 +258,7 @@
style = merge-flag(style, "flip")
style = merge-flag(style, "harpoon")

let mark = _eval-mark(ctx, mark-fn(style), style)
let mark = _eval-mark-shape-and-anchors(ctx, mark-fn(style), style)

let pos = if style.flex {
path-util.point-on-path(
Expand Down

0 comments on commit 9cc34a6

Please sign in to comment.