Skip to content

Commit

Permalink
mark: Add plus, x and star shaped marks
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Dec 21, 2023
1 parent 4cda671 commit b85b288
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/mark-shapes.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "drawable.typ"
#import "path-util.typ"
#import "vector.typ"

// Calculate triangular tip offset, depending on the strokes
// join type.
Expand Down Expand Up @@ -31,6 +32,21 @@
return calc.sin(angle/2) * (style.stroke.thickness / 2)
}

#let _star-shape(n, style, angle-offset: 0deg) = {
let radius(angle) = {
vector.dist((0,0), (calc.cos(angle) * style.length, calc.sin(angle) * style.width)) / 2
}
range(0, n)
.map(i => i * 360deg / n + angle-offset)
.filter(a => not style.harpoon or (a >= 0deg and a <= 180deg))
.map(a => {
let d = vector.scale(vector.rotate-z((1, 0, 0), a), radius(a))

drawable.path(path-util.line-segment(((0,0,0), vector.add((0,0,0), d))),
stroke: style.stroke, close: false)
})
}


// Dictionary of built-in mark styles
//
Expand Down Expand Up @@ -208,6 +224,22 @@
distance: style.length,
inset: style.length
),
plus: (style) => (
drawables: _star-shape(4, style),
tip-offset: 0,
distance: style.length / 2,
),
x: (style) => (
drawables: _star-shape(4, style, angle-offset: 45deg),
tip-offset: 0,
distance: style.length / 2,
inset: style.length / 2
),
star: (style) => (
drawables: _star-shape(5, style),
tip-offset: 0,
distance: style.length / 2,
)
)
#let names = marks.keys()

Expand All @@ -221,6 +253,9 @@
"[": ("bracket", true),
"|": ("bar", false),
"o": ("circle", false),
"+": ("plus", false),
"x": ("x", false),
"*": ("star", false),
)

// Get a mark shape + reverse tuple for a mark name
Expand Down

0 comments on commit b85b288

Please sign in to comment.