@thi.ng/geom 6.0.7 → 6.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/aabb.js +31 -32
- package/api/aabb.js +34 -29
- package/api/apc.js +15 -13
- package/api/arc.js +82 -66
- package/api/bpatch.js +79 -96
- package/api/circle.js +21 -21
- package/api/cubic.js +28 -25
- package/api/ellipse.js +26 -21
- package/api/group.js +45 -47
- package/api/line.js +26 -27
- package/api/path.js +62 -58
- package/api/plane.js +21 -21
- package/api/points.js +30 -26
- package/api/polygon.js +19 -16
- package/api/polyline.js +25 -22
- package/api/quad.js +20 -17
- package/api/quad3.js +20 -17
- package/api/quadratic.js +28 -25
- package/api/ray.js +30 -26
- package/api/rect.js +34 -29
- package/api/sphere.js +21 -21
- package/api/text.js +21 -28
- package/api/triangle.js +20 -17
- package/apply-transforms.js +28 -48
- package/arc-length.js +17 -30
- package/arc.js +17 -6
- package/area.js +19 -45
- package/as-cubic.js +38 -57
- package/as-path.js +4 -8
- package/as-polygon.js +12 -29
- package/as-polyline.js +18 -38
- package/as-svg.js +32 -63
- package/bounds.js +46 -48
- package/bpatch.js +22 -14
- package/center.js +22 -17
- package/centroid.js +14 -34
- package/circle.js +11 -6
- package/classify-point.js +20 -27
- package/clip-convex.js +40 -39
- package/closest-point.js +28 -34
- package/convex-hull.js +12 -27
- package/cubic.js +13 -5
- package/edges.js +31 -60
- package/ellipse.js +5 -2
- package/fit-into-bounds.js +78 -61
- package/flip.js +24 -41
- package/group.js +4 -1
- package/internal/args.js +18 -51
- package/internal/bounds.js +23 -38
- package/internal/collate.js +33 -17
- package/internal/copy.js +12 -23
- package/internal/dispatch.js +6 -4
- package/internal/edges.js +4 -1
- package/internal/pclike.js +8 -4
- package/internal/points-as-shape.js +4 -3
- package/internal/rotate.js +6 -2
- package/internal/scale.js +8 -2
- package/internal/split.js +9 -6
- package/internal/transform.js +24 -12
- package/internal/translate.js +6 -2
- package/internal/vertices.js +15 -31
- package/intersects.js +15 -39
- package/line.js +11 -9
- package/map-point.js +10 -18
- package/offset.js +31 -29
- package/package.json +33 -30
- package/path-builder.js +152 -143
- package/path-from-svg.js +129 -131
- package/path.js +28 -25
- package/plane.js +10 -5
- package/point-at.js +12 -30
- package/point-inside.js +20 -25
- package/points.js +6 -2
- package/polygon.js +15 -47
- package/polyline.js +18 -22
- package/quad.js +23 -15
- package/quadratic.js +7 -3
- package/ray.js +4 -1
- package/rect.js +47 -46
- package/resample.js +12 -27
- package/rotate.js +30 -42
- package/scale.js +66 -64
- package/scatter.js +18 -30
- package/simplify.js +38 -55
- package/sphere.js +7 -3
- package/split-arclength.js +53 -108
- package/split-at.js +46 -26
- package/split-near.js +28 -22
- package/subdiv-curve.js +33 -72
- package/tangent-at.js +12 -24
- package/tessellate.js +22 -47
- package/text.js +4 -1
- package/transform-vertices.js +31 -55
- package/transform.js +31 -54
- package/translate.js +39 -46
- package/triangle.js +7 -3
- package/union.js +12 -15
- package/unmap-point.js +21 -25
- package/vertices.js +91 -113
- package/volume.js +10 -14
- package/warp-points.js +15 -25
- package/with-attribs.js +4 -11
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/aabb.js
CHANGED
|
@@ -8,38 +8,37 @@ import { sub3 } from "@thi.ng/vectors/sub";
|
|
|
8
8
|
import { subN3 } from "@thi.ng/vectors/subn";
|
|
9
9
|
import { AABB } from "./api/aabb.js";
|
|
10
10
|
import { __argsVV } from "./internal/args.js";
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
function aabb(...args) {
|
|
12
|
+
return new AABB(...__argsVV(args));
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @param b -
|
|
24
|
-
*/
|
|
25
|
-
export const intersectionAABB = (a, b) => {
|
|
26
|
-
const p = max3([], a.pos, b.pos);
|
|
27
|
-
const q = min3(null, add3([], a.pos, a.size), add3([], b.pos, b.size));
|
|
28
|
-
const size = max3(null, sub3(null, q, p), ZERO3);
|
|
29
|
-
return size[0] > 0 && size[1] > 0 && size[2] > 0
|
|
30
|
-
? new AABB(p, size)
|
|
31
|
-
: undefined;
|
|
14
|
+
const aabbFromMinMax = (min, max, attribs) => new AABB(min, sub3([], max, min), attribs);
|
|
15
|
+
const aabbFromMinMaxWithMargin = (min, max, margin, attribs) => aabbFromMinMax(min, max, attribs).offset(margin);
|
|
16
|
+
const aabbFromCentroid = (centroid, size, attribs) => new AABB(maddN3([], size, -0.5, centroid), size, attribs);
|
|
17
|
+
const aabbWithCentroidAndMargin = (centroid, size, margin, attribs) => aabbFromCentroid(centroid, size, attribs).offset(margin);
|
|
18
|
+
const intersectionAABB = (a, b) => {
|
|
19
|
+
const p = max3([], a.pos, b.pos);
|
|
20
|
+
const q = min3(null, add3([], a.pos, a.size), add3([], b.pos, b.size));
|
|
21
|
+
const size = max3(null, sub3(null, q, p), ZERO3);
|
|
22
|
+
return size[0] > 0 && size[1] > 0 && size[2] > 0 ? new AABB(p, size) : void 0;
|
|
32
23
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return aabb(subN3([], pos, r), r * 2);
|
|
24
|
+
function inscribedAABB(...args) {
|
|
25
|
+
let pos, r;
|
|
26
|
+
if (args.length === 1) {
|
|
27
|
+
const c = args[0];
|
|
28
|
+
pos = c.pos;
|
|
29
|
+
r = c.r;
|
|
30
|
+
} else {
|
|
31
|
+
[pos, r] = args;
|
|
32
|
+
}
|
|
33
|
+
r *= SQRT2_2;
|
|
34
|
+
return aabb(subN3([], pos, r), r * 2);
|
|
45
35
|
}
|
|
36
|
+
export {
|
|
37
|
+
aabb,
|
|
38
|
+
aabbFromCentroid,
|
|
39
|
+
aabbFromMinMax,
|
|
40
|
+
aabbFromMinMaxWithMargin,
|
|
41
|
+
aabbWithCentroidAndMargin,
|
|
42
|
+
inscribedAABB,
|
|
43
|
+
intersectionAABB
|
|
44
|
+
};
|
package/api/aabb.js
CHANGED
|
@@ -6,33 +6,38 @@ import { set3 } from "@thi.ng/vectors/set";
|
|
|
6
6
|
import { subN3 } from "@thi.ng/vectors/subn";
|
|
7
7
|
import { __asVec } from "../internal/args.js";
|
|
8
8
|
import { __copyAttribs } from "../internal/copy.js";
|
|
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
|
-
|
|
9
|
+
class AABB {
|
|
10
|
+
constructor(pos = [0, 0, 0], size = 1, attribs) {
|
|
11
|
+
this.pos = pos;
|
|
12
|
+
this.attribs = attribs;
|
|
13
|
+
this.size = __asVec(size, 3);
|
|
14
|
+
}
|
|
15
|
+
size;
|
|
16
|
+
get type() {
|
|
17
|
+
return "aabb";
|
|
18
|
+
}
|
|
19
|
+
copy() {
|
|
20
|
+
return new AABB(
|
|
21
|
+
set3([], this.pos),
|
|
22
|
+
set3([], this.size),
|
|
23
|
+
__copyAttribs(this)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
withAttribs(attribs) {
|
|
27
|
+
return new AABB(this.pos, this.size, attribs);
|
|
28
|
+
}
|
|
29
|
+
max() {
|
|
30
|
+
return add3([], this.pos, this.size);
|
|
31
|
+
}
|
|
32
|
+
offset(offset) {
|
|
33
|
+
subN3(null, this.pos, offset);
|
|
34
|
+
max3(null, addN3(null, this.size, offset * 2), ZERO3);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
toHiccup() {
|
|
38
|
+
return ["aabb", this.attribs, this.pos, this.size];
|
|
39
|
+
}
|
|
38
40
|
}
|
|
41
|
+
export {
|
|
42
|
+
AABB
|
|
43
|
+
};
|
package/api/apc.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { ensureArray } from "@thi.ng/arrays/ensure-array";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
2
|
+
class APC {
|
|
3
|
+
constructor(points, attribs) {
|
|
4
|
+
this.attribs = attribs;
|
|
5
|
+
this.points = points ? ensureArray(points) : [];
|
|
6
|
+
}
|
|
7
|
+
points;
|
|
8
|
+
*[Symbol.iterator]() {
|
|
9
|
+
yield* this.points;
|
|
10
|
+
}
|
|
11
|
+
clear() {
|
|
12
|
+
this.points.length = 0;
|
|
13
|
+
}
|
|
15
14
|
}
|
|
15
|
+
export {
|
|
16
|
+
APC
|
|
17
|
+
};
|
package/api/arc.js
CHANGED
|
@@ -1,70 +1,86 @@
|
|
|
1
1
|
import { equiv } from "@thi.ng/equiv";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
pointAt as arcPointAt,
|
|
4
|
+
pointAtTheta as arcPointAtTheta
|
|
5
|
+
} from "@thi.ng/geom-arc/point-at";
|
|
3
6
|
import { set } from "@thi.ng/vectors/set";
|
|
4
7
|
import { __copyAttribs } from "../internal/copy.js";
|
|
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
|
-
|
|
8
|
+
class Arc {
|
|
9
|
+
constructor(pos, r, axis, start, end, xl = false, cw = false, attribs) {
|
|
10
|
+
this.pos = pos;
|
|
11
|
+
this.r = r;
|
|
12
|
+
this.axis = axis;
|
|
13
|
+
this.start = start;
|
|
14
|
+
this.end = end;
|
|
15
|
+
this.xl = xl;
|
|
16
|
+
this.cw = cw;
|
|
17
|
+
this.attribs = attribs;
|
|
18
|
+
}
|
|
19
|
+
get type() {
|
|
20
|
+
return "arc";
|
|
21
|
+
}
|
|
22
|
+
copy() {
|
|
23
|
+
return new Arc(
|
|
24
|
+
set([], this.pos),
|
|
25
|
+
set([], this.r),
|
|
26
|
+
this.axis,
|
|
27
|
+
this.start,
|
|
28
|
+
this.end,
|
|
29
|
+
this.xl,
|
|
30
|
+
this.cw,
|
|
31
|
+
__copyAttribs(this)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
withAttribs(attribs) {
|
|
35
|
+
return new Arc(
|
|
36
|
+
this.pos,
|
|
37
|
+
this.r,
|
|
38
|
+
this.axis,
|
|
39
|
+
this.start,
|
|
40
|
+
this.end,
|
|
41
|
+
this.xl,
|
|
42
|
+
this.cw,
|
|
43
|
+
attribs
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
equiv(o) {
|
|
47
|
+
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;
|
|
48
|
+
}
|
|
49
|
+
pointAt(t, out = []) {
|
|
50
|
+
return arcPointAt(
|
|
51
|
+
this.pos,
|
|
52
|
+
this.r,
|
|
53
|
+
this.axis,
|
|
54
|
+
this.start,
|
|
55
|
+
this.end,
|
|
56
|
+
t,
|
|
57
|
+
out
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
pointAtTheta(theta, out = []) {
|
|
61
|
+
return arcPointAtTheta(this.pos, this.r, this.axis, theta, out);
|
|
62
|
+
}
|
|
63
|
+
toHiccup() {
|
|
64
|
+
return [
|
|
65
|
+
"path",
|
|
66
|
+
this.attribs,
|
|
67
|
+
[["M", this.pointAt(0)], ...this.toHiccupPathSegments()]
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
toHiccupPathSegments() {
|
|
71
|
+
return [
|
|
72
|
+
[
|
|
73
|
+
"A",
|
|
74
|
+
this.r[0],
|
|
75
|
+
this.r[1],
|
|
76
|
+
this.axis,
|
|
77
|
+
this.xl,
|
|
78
|
+
this.cw,
|
|
79
|
+
this.pointAt(1)
|
|
80
|
+
]
|
|
81
|
+
];
|
|
82
|
+
}
|
|
70
83
|
}
|
|
84
|
+
export {
|
|
85
|
+
Arc
|
|
86
|
+
};
|
package/api/bpatch.js
CHANGED
|
@@ -2,102 +2,85 @@ import { mixCubic } from "@thi.ng/vectors/mix-cubic";
|
|
|
2
2
|
import { __copyShape } from "../internal/copy.js";
|
|
3
3
|
import { __ensureNumVerts } from "../internal/pclike.js";
|
|
4
4
|
import { APC } from "./apc.js";
|
|
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
|
-
unmapPoint(uv, out) {
|
|
75
|
-
const cp = this.points;
|
|
76
|
-
const [u, v] = uv;
|
|
77
|
-
return mixCubic(out || null, mixCubic([], cp[0], cp[4], cp[8], cp[12], v), mixCubic([], cp[1], cp[5], cp[9], cp[13], v), mixCubic([], cp[2], cp[6], cp[10], cp[14], v), mixCubic([], cp[3], cp[7], cp[11], cp[15], v), u);
|
|
78
|
-
}
|
|
79
|
-
toHiccup() {
|
|
80
|
-
const attribs = this.attribs;
|
|
81
|
-
const acc = ["g", { fill: "none", ...attribs }];
|
|
82
|
-
if (attribs && attribs.res) {
|
|
83
|
-
const res = attribs.res - 1;
|
|
84
|
-
const delta = 1 / res;
|
|
85
|
-
for (let u = 0; u <= res; u++) {
|
|
86
|
-
const col = [];
|
|
87
|
-
const row = [];
|
|
88
|
-
const uu = u * delta;
|
|
89
|
-
for (let v = 0; v <= res; v++) {
|
|
90
|
-
const p = [uu, v * delta];
|
|
91
|
-
col.push(this.unmapPoint(p));
|
|
92
|
-
row.push(this.unmapPoint([p[1], p[0]]));
|
|
93
|
-
}
|
|
94
|
-
acc.push(["polyline", {}, col]);
|
|
95
|
-
acc.push(["polyline", {}, row]);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.edges().forEach((l) => acc.push(["line", {}, ...l]));
|
|
5
|
+
class BPatch extends APC {
|
|
6
|
+
constructor(points, attribs) {
|
|
7
|
+
super(points, attribs);
|
|
8
|
+
__ensureNumVerts(this.points.length, 16);
|
|
9
|
+
}
|
|
10
|
+
get type() {
|
|
11
|
+
return "bpatch";
|
|
12
|
+
}
|
|
13
|
+
copy() {
|
|
14
|
+
return __copyShape(BPatch, this);
|
|
15
|
+
}
|
|
16
|
+
withAttribs(attribs) {
|
|
17
|
+
return new BPatch(this.points, attribs);
|
|
18
|
+
}
|
|
19
|
+
edges() {
|
|
20
|
+
const p = this.points;
|
|
21
|
+
return [
|
|
22
|
+
[0, 1],
|
|
23
|
+
[1, 2],
|
|
24
|
+
[2, 3],
|
|
25
|
+
[0, 4],
|
|
26
|
+
[1, 5],
|
|
27
|
+
[2, 6],
|
|
28
|
+
[3, 7],
|
|
29
|
+
[4, 5],
|
|
30
|
+
[5, 6],
|
|
31
|
+
[6, 7],
|
|
32
|
+
[4, 8],
|
|
33
|
+
[5, 9],
|
|
34
|
+
[6, 10],
|
|
35
|
+
[7, 11],
|
|
36
|
+
[8, 9],
|
|
37
|
+
[9, 10],
|
|
38
|
+
[10, 11],
|
|
39
|
+
[8, 12],
|
|
40
|
+
[9, 13],
|
|
41
|
+
[10, 14],
|
|
42
|
+
[11, 15],
|
|
43
|
+
[12, 13],
|
|
44
|
+
[13, 14],
|
|
45
|
+
[14, 15]
|
|
46
|
+
].map(([a, b]) => [p[a], p[b]]);
|
|
47
|
+
}
|
|
48
|
+
unmapPoint(uv, out) {
|
|
49
|
+
const cp = this.points;
|
|
50
|
+
const [u, v] = uv;
|
|
51
|
+
return mixCubic(
|
|
52
|
+
out || null,
|
|
53
|
+
mixCubic([], cp[0], cp[4], cp[8], cp[12], v),
|
|
54
|
+
mixCubic([], cp[1], cp[5], cp[9], cp[13], v),
|
|
55
|
+
mixCubic([], cp[2], cp[6], cp[10], cp[14], v),
|
|
56
|
+
mixCubic([], cp[3], cp[7], cp[11], cp[15], v),
|
|
57
|
+
u
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
toHiccup() {
|
|
61
|
+
const attribs = this.attribs;
|
|
62
|
+
const acc = ["g", { fill: "none", ...attribs }];
|
|
63
|
+
if (attribs && attribs.res) {
|
|
64
|
+
const res = attribs.res - 1;
|
|
65
|
+
const delta = 1 / res;
|
|
66
|
+
for (let u = 0; u <= res; u++) {
|
|
67
|
+
const col = [];
|
|
68
|
+
const row = [];
|
|
69
|
+
const uu = u * delta;
|
|
70
|
+
for (let v = 0; v <= res; v++) {
|
|
71
|
+
const p = [uu, v * delta];
|
|
72
|
+
col.push(this.unmapPoint(p));
|
|
73
|
+
row.push(this.unmapPoint([p[1], p[0]]));
|
|
100
74
|
}
|
|
101
|
-
|
|
75
|
+
acc.push(["polyline", {}, col]);
|
|
76
|
+
acc.push(["polyline", {}, row]);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
this.edges().forEach((l) => acc.push(["line", {}, ...l]));
|
|
102
80
|
}
|
|
81
|
+
return acc;
|
|
82
|
+
}
|
|
103
83
|
}
|
|
84
|
+
export {
|
|
85
|
+
BPatch
|
|
86
|
+
};
|
package/api/circle.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { set } from "@thi.ng/vectors/set";
|
|
2
2
|
import { __copyAttribs } from "../internal/copy.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
toHiccup() {
|
|
22
|
-
return ["circle", this.attribs, this.pos, this.r];
|
|
23
|
-
}
|
|
3
|
+
class Circle {
|
|
4
|
+
constructor(pos = [0, 0], r = 1, attribs) {
|
|
5
|
+
this.pos = pos;
|
|
6
|
+
this.r = r;
|
|
7
|
+
this.attribs = attribs;
|
|
8
|
+
}
|
|
9
|
+
get type() {
|
|
10
|
+
return "circle";
|
|
11
|
+
}
|
|
12
|
+
copy() {
|
|
13
|
+
return new Circle(set([], this.pos), this.r, __copyAttribs(this));
|
|
14
|
+
}
|
|
15
|
+
withAttribs(attribs) {
|
|
16
|
+
return new Circle(this.pos, this.r, attribs);
|
|
17
|
+
}
|
|
18
|
+
toHiccup() {
|
|
19
|
+
return ["circle", this.attribs, this.pos, this.r];
|
|
20
|
+
}
|
|
24
21
|
}
|
|
22
|
+
export {
|
|
23
|
+
Circle
|
|
24
|
+
};
|
package/api/cubic.js
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import { __copyShape } from "../internal/copy.js";
|
|
2
2
|
import { __ensureNumVerts } from "../internal/pclike.js";
|
|
3
3
|
import { APC } from "./apc.js";
|
|
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
|
-
|
|
4
|
+
class Cubic extends APC {
|
|
5
|
+
constructor(points, attribs) {
|
|
6
|
+
super(points, attribs);
|
|
7
|
+
__ensureNumVerts(this.points.length, 4);
|
|
8
|
+
}
|
|
9
|
+
get type() {
|
|
10
|
+
return "cubic";
|
|
11
|
+
}
|
|
12
|
+
copy() {
|
|
13
|
+
return __copyShape(Cubic, this);
|
|
14
|
+
}
|
|
15
|
+
withAttribs(attribs) {
|
|
16
|
+
return new Cubic(this.points, attribs);
|
|
17
|
+
}
|
|
18
|
+
toHiccup() {
|
|
19
|
+
return [
|
|
20
|
+
"path",
|
|
21
|
+
this.attribs,
|
|
22
|
+
[["M", this.points[0]], ...this.toHiccupPathSegments()]
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
toHiccupPathSegments() {
|
|
26
|
+
const pts = this.points;
|
|
27
|
+
return [["C", pts[1], pts[2], pts[3]]];
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
|
+
export {
|
|
31
|
+
Cubic
|
|
32
|
+
};
|