-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
arc.ts
108 lines (99 loc) · 1.74 KB
/
arc.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { equiv } from "@thi.ng/equiv";
import type {
Attribs,
IHiccupPathSegment,
IHiccupShape,
} from "@thi.ng/geom-api";
import {
pointAt as arcPointAt,
pointAtTheta as arcPointAtTheta,
} from "@thi.ng/geom-arc/point-at";
import type { Vec } from "@thi.ng/vectors";
import { set } from "@thi.ng/vectors/set";
import { __copyAttribs } from "../internal/copy.js";
export class Arc implements IHiccupShape, IHiccupPathSegment {
constructor(
public pos: Vec,
public r: Vec,
public axis: number,
public start: number,
public end: number,
public xl = false,
public cw = false,
public attribs?: Attribs
) {}
get type() {
return "arc";
}
copy(): Arc {
return new Arc(
set([], this.pos),
set([], this.r),
this.axis,
this.start,
this.end,
this.xl,
this.cw,
__copyAttribs(this)
);
}
withAttribs(attribs: Attribs): Arc {
return new Arc(
this.pos,
this.r,
this.axis,
this.start,
this.end,
this.xl,
this.cw,
attribs
);
}
equiv(o: any) {
return (
o instanceof Arc &&
equiv(this.pos, o.pos) &&
equiv(this.r, o.r) &&
this.start === o.start &&
this.end === o.end &&
this.axis === o.axis &&
this.xl === o.xl &&
this.cw &&
o.cw
);
}
pointAt(t: number, out: Vec = []) {
return arcPointAt(
this.pos,
this.r,
this.axis,
this.start,
this.end,
t,
out
);
}
pointAtTheta(theta: number, out: Vec = []) {
return arcPointAtTheta(this.pos, this.r, this.axis, theta, out);
}
toHiccup() {
return [
"path",
this.attribs,
[["M", this.pointAt(0)], ...this.toHiccupPathSegments()],
];
}
toHiccupPathSegments() {
return [
[
"A",
this.r[0],
this.r[1],
this.axis,
this.xl,
this.cw,
this.pointAt(1),
],
];
}
}