-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.typ
59 lines (50 loc) · 1.04 KB
/
utils.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#import "../typst-canvas/vector.typ"
#import "../typst-canvas/draw.typ": anchor
#let vector-dist(v1, v2) = {
return calc.abs(
vector.len(
vector.sub(
v2,
v1
)
)
)
}
#let get-angle(v1, v2, debug: false) = {
// panic(v1, v2)
let (x,y,z) = vector.sub(v2, v1)
return calc.atan2(x,-y)
// return -panic(if v2.at(1) < v1.at(1) {-1} else {1} * vector.angle(vector.sub(v2, v1), (0,0,0), (1,0,0)))
// return -if v2.at(1) < v1.at(1) {-1} else {1} * vector.angle(vector.sub(v2, v1), (0,0,0), (1,0,0))
}
#let vector-rotate(v, angle) = {
let (x, y, z) = v
// panic(angle)
(
x * calc.cos(angle) - y * calc.sin(angle),
x * calc.sin(angle) + y * calc.cos(angle),
z
)
}
#let defer-rotation(v, v1, v2) = {
(
(v, v1, v2) => {
// panic(v)
// panic(v1, v2)
vector-rotate(v, -get-angle(v1, v2))
},
v,
v1,
v2
)
}
// #let reverse-transform(v) = {
// (
// (start, center, v) =>
// )
// }
#let anchors(anchors) = {
for (k, v) in anchors {
anchor(k, v)
}
}