Skip to content

Commit

Permalink
mark: Implement barbed arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Nov 12, 2023
1 parent 5b20c78 commit 89c2057
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ grid((0,0), (3,2), help-lines: true)

#show-module-fn(draw-module, "mark")
```example
line((1, 0), (1, 6), stroke: (paint: gray, dash: "dotted"))
line((1, 0), (1, 7), stroke: (paint: gray, dash: "dotted"))
set-style(mark: (fill: none))
line((0, 7), (1, 7), mark: (end: "barbed"))
line((0, 6), (1, 6), mark: (end: "<"))
line((0, 5), (1, 5), mark: (end: ">"))
set-style(mark: (fill: black))
Expand Down
17 changes: 17 additions & 0 deletions src/drawable.typ
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@
}
}

// TikZ style barbed arrow tip
let barbed() = {
let a = vector.sub(base, w)
let b = vector.add(base, w)
let ct = vector.add(t, vector.scale(dir, -length))

path(
(path-util.cubic-segment(a, t, a, ct),
path-util.cubic-segment(t, b, ct, b)),
close: false,
fill: none,
stroke: stroke
)
}

let harpoon(side: "left") = {
let s = if side == "left" {
vector.add(base, w)
Expand Down Expand Up @@ -243,6 +258,8 @@
triangle()
} else if symbol == "<" {
triangle()
} else if symbol == "barbed" {
barbed()
} else if symbol == "|" {
bar()
} else if symbol == "<>" {
Expand Down
2 changes: 2 additions & 0 deletions src/mark.typ
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#let calc-mark-offset(ctx, symbol, style) = {
if symbol in ("<", ">") {
return _triangular-mark-offset(ctx, style.width, style.length, symbol, style)
} else if symbol == "barbed" {
return _triangular-mark-offset(ctx, 0 /* The tip has angle 0 */, style.length, symbol, style)
} else if symbol in ("left-harpoon", "right-harpoon") {
return _triangular-mark-offset(ctx, style.width / 2, style.length, symbol, style)
} else if symbol == "<>" {
Expand Down
Binary file modified tests/arrows/ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/arrows/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
set-style(fill: blue, mark: (fill: auto))
rotate(-90deg)

let marks = (">", "<", "|", "<>", "o")
let marks = (">", "<", "|", "<>", "o", "barbed")
for m in marks {
next((end: m))
}
Expand Down

0 comments on commit 89c2057

Please sign in to comment.