@thi.ng/geom 6.0.7 → 6.0.9
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/split-arclength.js
CHANGED
|
@@ -6,117 +6,62 @@ import { asPolyline } from "./as-polyline.js";
|
|
|
6
6
|
import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
|
|
7
7
|
import { __dispatch } from "./internal/dispatch.js";
|
|
8
8
|
import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @remarks
|
|
14
|
-
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
15
|
-
* avoid recursive application.
|
|
16
|
-
*
|
|
17
|
-
* Currently only implemented for:
|
|
18
|
-
*
|
|
19
|
-
* - {@link Group}
|
|
20
|
-
* - {@link Polyline}
|
|
21
|
-
*
|
|
22
|
-
* Other shape types will be attempted to be auto-converted via
|
|
23
|
-
* {@link asPolyline} first.
|
|
24
|
-
*
|
|
25
|
-
* Nested groups are NOT supported. Groups are processing their child shapes and
|
|
26
|
-
* forming new child groups of given max. arc lengths and potentially splitting
|
|
27
|
-
* shapes if they don't fit within the current subgroup...
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* // circle (to be sampled as octagon)
|
|
32
|
-
* const a = circle(100, { stroke: "red", __samples: 8 });
|
|
33
|
-
*
|
|
34
|
-
* // inner square of circle
|
|
35
|
-
* const b = inscribedSquare(a, { stroke: "blue" });
|
|
36
|
-
*
|
|
37
|
-
* // process as group, split/partition into subgroups of arclength max. 200
|
|
38
|
-
* splitArcLength(group({}, [a, b]), 200);
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* Result serialized to SVG:
|
|
42
|
-
*
|
|
43
|
-
* ```svg
|
|
44
|
-
* <g>
|
|
45
|
-
* <g>
|
|
46
|
-
* <polyline fill="none" points="100,0 70.7,70.7 0.0,100 -43.4,82.0" stroke="red"/>
|
|
47
|
-
* </g>
|
|
48
|
-
* <g>
|
|
49
|
-
* <polyline fill="none" points="-43.4,82.0 -70.7,70.7 -100,0.0 -70.7,-70.7 -54.7,-77.3" stroke="red"/>
|
|
50
|
-
* </g>
|
|
51
|
-
* <g>
|
|
52
|
-
* <polyline fill="none" points="-54.7,-77.3 -0.0,-100 70.7,-70.7 95.3,-11.4" stroke="red"/>
|
|
53
|
-
* </g>
|
|
54
|
-
* <g>
|
|
55
|
-
* <!-- last segment of circle -->
|
|
56
|
-
* <polyline fill="none" points="95.3,-11.4 100,0" stroke="red"/>
|
|
57
|
-
* <!-- first segment of rect -->
|
|
58
|
-
* <polyline fill="none" points="-70.7,-70.7 70.7,-70.7 70.7,-24.4" stroke="blue"/>
|
|
59
|
-
* </g>
|
|
60
|
-
* <g>
|
|
61
|
-
* <polyline fill="none" points="70.7,-24.4 70.7,70.7 -34.2,70.7" stroke="blue"/>
|
|
62
|
-
* </g>
|
|
63
|
-
* <g>
|
|
64
|
-
* <polyline fill="none" points="-34.2,70.7 -70.7,70.7 -70.7,-70.7" stroke="blue"/>
|
|
65
|
-
* </g>
|
|
66
|
-
* </g>
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @param shape
|
|
70
|
-
* @param dist
|
|
71
|
-
*/
|
|
72
|
-
export const splitArcLength = defmulti(__dispatch, {}, {
|
|
9
|
+
const splitArcLength = defmulti(
|
|
10
|
+
__dispatch,
|
|
11
|
+
{},
|
|
12
|
+
{
|
|
73
13
|
[DEFAULT]: ($, d) => splitArcLength(asPolyline($), d),
|
|
74
14
|
group: ($, d) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
queue.push(new Polyline(next, __attribs(child)));
|
|
96
|
-
}
|
|
15
|
+
const groups = [];
|
|
16
|
+
let curr = [];
|
|
17
|
+
let currLen = 0;
|
|
18
|
+
const queue = $.children.slice().reverse();
|
|
19
|
+
while (queue.length) {
|
|
20
|
+
const child = queue.pop();
|
|
21
|
+
const polyline = asPolyline(child);
|
|
22
|
+
const sampler = new Sampler(polyline.points);
|
|
23
|
+
const len = sampler.totalLength();
|
|
24
|
+
if (currLen + len <= d) {
|
|
25
|
+
curr.push(polyline);
|
|
26
|
+
currLen += len;
|
|
27
|
+
} else {
|
|
28
|
+
const remainingLen = d - currLen;
|
|
29
|
+
const [fill, next] = sampler.splitAt(remainingLen / len);
|
|
30
|
+
curr.push(new Polyline(fill, __attribs(child)));
|
|
31
|
+
groups.push(new Group({}, curr));
|
|
32
|
+
curr = [];
|
|
33
|
+
currLen = 0;
|
|
34
|
+
queue.push(new Polyline(next, __attribs(child)));
|
|
97
35
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
36
|
+
}
|
|
37
|
+
if (curr.length)
|
|
38
|
+
groups.push(new Group({}, curr));
|
|
39
|
+
return new Group(__attribs($), groups);
|
|
101
40
|
},
|
|
102
41
|
polyline: ($, d) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
42
|
+
const chunks = [];
|
|
43
|
+
let pts = $.points;
|
|
44
|
+
while (true) {
|
|
45
|
+
const sampler = new Sampler(pts);
|
|
46
|
+
const total = sampler.totalLength();
|
|
47
|
+
if (total > d) {
|
|
48
|
+
const parts = sampler.splitAt(d / total);
|
|
49
|
+
if (!parts)
|
|
50
|
+
break;
|
|
51
|
+
chunks.push(parts[0]);
|
|
52
|
+
pts = parts[1];
|
|
53
|
+
} else {
|
|
54
|
+
chunks.push(pts);
|
|
55
|
+
break;
|
|
119
56
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
57
|
+
}
|
|
58
|
+
return new Group(
|
|
59
|
+
__attribs($),
|
|
60
|
+
__pointArraysAsShapes(Polyline, chunks)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
export {
|
|
66
|
+
splitArcLength
|
|
67
|
+
};
|
package/split-at.js
CHANGED
|
@@ -13,31 +13,51 @@ import { __copyAttribs } from "./internal/copy.js";
|
|
|
13
13
|
import { __dispatch } from "./internal/dispatch.js";
|
|
14
14
|
import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
15
15
|
import { __splitLine } from "./internal/split.js";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* Currently only implemented for:
|
|
21
|
-
*
|
|
22
|
-
* - {@link Arc}
|
|
23
|
-
* - {@link Cubic}
|
|
24
|
-
* - {@link Line}
|
|
25
|
-
* - {@link Polyline}
|
|
26
|
-
* - {@link Quadratic}
|
|
27
|
-
*
|
|
28
|
-
* @param shape
|
|
29
|
-
* @param t
|
|
30
|
-
*/
|
|
31
|
-
export const splitAt = defmulti(__dispatch, {}, {
|
|
16
|
+
const splitAt = defmulti(
|
|
17
|
+
__dispatch,
|
|
18
|
+
{},
|
|
19
|
+
{
|
|
32
20
|
arc: ($, t) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
const theta = fit01(t, $.start, $.end);
|
|
22
|
+
return [
|
|
23
|
+
new Arc(
|
|
24
|
+
set([], $.pos),
|
|
25
|
+
set([], $.r),
|
|
26
|
+
$.axis,
|
|
27
|
+
$.start,
|
|
28
|
+
theta,
|
|
29
|
+
$.xl,
|
|
30
|
+
$.cw,
|
|
31
|
+
__copyAttribs($)
|
|
32
|
+
),
|
|
33
|
+
new Arc(
|
|
34
|
+
set([], $.pos),
|
|
35
|
+
set([], $.r),
|
|
36
|
+
$.axis,
|
|
37
|
+
theta,
|
|
38
|
+
$.end,
|
|
39
|
+
$.xl,
|
|
40
|
+
$.cw,
|
|
41
|
+
__copyAttribs($)
|
|
42
|
+
)
|
|
43
|
+
];
|
|
38
44
|
},
|
|
39
|
-
cubic: ({ attribs, points }, t) => cubicSplitAt(points[0], points[1], points[2], points[3], t).map(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
45
|
+
cubic: ({ attribs, points }, t) => cubicSplitAt(points[0], points[1], points[2], points[3], t).map(
|
|
46
|
+
(pts) => new Cubic(pts, { ...attribs })
|
|
47
|
+
),
|
|
48
|
+
line: ({ attribs, points }, t) => __splitLine(points[0], points[1], t).map(
|
|
49
|
+
(pts) => new Line(pts, { ...attribs })
|
|
50
|
+
),
|
|
51
|
+
polyline: ($, t) => __pointArraysAsShapes(
|
|
52
|
+
Polyline,
|
|
53
|
+
new Sampler($.points).splitAt(t),
|
|
54
|
+
$.attribs
|
|
55
|
+
),
|
|
56
|
+
quadratic: ({ attribs, points }, t) => quadraticSplitAt(points[0], points[1], points[2], t).map(
|
|
57
|
+
(pts) => new Quadratic(pts, { ...attribs })
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
export {
|
|
62
|
+
splitAt
|
|
63
|
+
};
|
package/split-near.js
CHANGED
|
@@ -12,27 +12,33 @@ import { __copyAttribs } from "./internal/copy.js";
|
|
|
12
12
|
import { __dispatch } from "./internal/dispatch.js";
|
|
13
13
|
import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
14
14
|
import { __splitLine } from "./internal/split.js";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
* @param shape - shape to operate on
|
|
28
|
-
* @param p - split point
|
|
29
|
-
*/
|
|
30
|
-
export const splitNearPoint = defmulti(__dispatch, {}, {
|
|
31
|
-
cubic: ({ points, attribs }, p) => splitCubicNearPoint(p, points[0], points[1], points[2], points[3]).map((pts) => new Cubic(pts, { ...attribs })),
|
|
15
|
+
const splitNearPoint = defmulti(
|
|
16
|
+
__dispatch,
|
|
17
|
+
{},
|
|
18
|
+
{
|
|
19
|
+
cubic: ({ points, attribs }, p) => splitCubicNearPoint(
|
|
20
|
+
p,
|
|
21
|
+
points[0],
|
|
22
|
+
points[1],
|
|
23
|
+
points[2],
|
|
24
|
+
points[3]
|
|
25
|
+
).map((pts) => new Cubic(pts, { ...attribs })),
|
|
32
26
|
line: ($, p) => {
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const t = closestT(p, $.points[0], $.points[1]) || 0;
|
|
28
|
+
return __splitLine($.points[0], $.points[1], clamp01(t)).map(
|
|
29
|
+
(pts) => new Line(pts, __copyAttribs($))
|
|
30
|
+
);
|
|
35
31
|
},
|
|
36
|
-
polyline: ($, p) => __pointArraysAsShapes(
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
polyline: ($, p) => __pointArraysAsShapes(
|
|
33
|
+
Polyline,
|
|
34
|
+
new Sampler($.points).splitNear(p),
|
|
35
|
+
$.attribs
|
|
36
|
+
),
|
|
37
|
+
quadratic: ({ points, attribs }, p) => quadraticSplitNearPoint(p, points[0], points[1], points[2]).map(
|
|
38
|
+
(pts) => new Quadratic(pts, { ...attribs })
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
export {
|
|
43
|
+
splitNearPoint
|
|
44
|
+
};
|
package/subdiv-curve.js
CHANGED
|
@@ -7,81 +7,42 @@ import { asPolygon } from "./as-polygon.js";
|
|
|
7
7
|
import { asPolyline } from "./as-polyline.js";
|
|
8
8
|
import { __copyAttribs } from "./internal/copy.js";
|
|
9
9
|
import { __dispatch } from "./internal/dispatch.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* to given shape/boundary. See
|
|
14
|
-
* [thi.ng/geom-subdiv-curve](https://thi.ng/thi.ng/geom-subdiv-curve) package
|
|
15
|
-
* for further details.
|
|
16
|
-
*
|
|
17
|
-
* @remarks
|
|
18
|
-
* By default only applies a single iteration.
|
|
19
|
-
*
|
|
20
|
-
* Currently only implemented for:
|
|
21
|
-
*
|
|
22
|
-
* - {@link Arc}
|
|
23
|
-
* - {@link Circle}
|
|
24
|
-
* - {@link Ellipse}
|
|
25
|
-
* - {@link Line}
|
|
26
|
-
* - {@link Polygon}
|
|
27
|
-
* - {@link Polyline}
|
|
28
|
-
* - {@link Quad}
|
|
29
|
-
* - {@link Rect}
|
|
30
|
-
* - {@link Triangle}
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
*
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param shape
|
|
38
|
-
* @param kernel
|
|
39
|
-
* @param iter
|
|
40
|
-
*/
|
|
41
|
-
export const subdivCurve = defmulti(__dispatch, {
|
|
10
|
+
const subdivCurve = defmulti(
|
|
11
|
+
__dispatch,
|
|
12
|
+
{
|
|
42
13
|
ellipse: "circle",
|
|
43
14
|
line: "polyline",
|
|
44
15
|
quad: "poly",
|
|
45
16
|
rect: "circle",
|
|
46
|
-
tri: "poly"
|
|
47
|
-
},
|
|
17
|
+
tri: "poly"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
48
20
|
arc: ($, kernel, iter = 1) => subdivCurve(asPolyline($), kernel, iter),
|
|
49
21
|
circle: ($, kernel, iter = 1) => subdivCurve(asPolygon($), kernel, iter),
|
|
50
|
-
poly: ($, kernel, iter = 1) => new Polygon(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export const SUBDIV_CHAIKIN_OPEN = sdc.SUBDIV_CHAIKIN_OPEN;
|
|
78
|
-
/**
|
|
79
|
-
* Re-export of thi.ng/geom-subdiv-curve
|
|
80
|
-
* [`SUBDIV_CHAIKIN_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CHAIKIN_CLOSED.html)
|
|
81
|
-
*/
|
|
82
|
-
export const SUBDIV_CHAIKIN_CLOSED = sdc.SUBDIV_CHAIKIN_CLOSED;
|
|
83
|
-
/**
|
|
84
|
-
* Re-export of thi.ng/geom-subdiv-curve
|
|
85
|
-
* [`SUBDIV_CUBIC_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CUBIC_CLOSED.html)
|
|
86
|
-
*/
|
|
87
|
-
export const SUBDIV_CUBIC_CLOSED = sdc.SUBDIV_CUBIC_CLOSED;
|
|
22
|
+
poly: ($, kernel, iter = 1) => new Polygon(
|
|
23
|
+
subdivide($.points, kernel, iter),
|
|
24
|
+
__copyAttribs($)
|
|
25
|
+
),
|
|
26
|
+
polyline: ($, kernel, iter = 1) => new Polyline(
|
|
27
|
+
subdivide($.points, kernel, iter),
|
|
28
|
+
__copyAttribs($)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
const SUBDIV_MID_OPEN = sdc.SUBDIV_MID_OPEN;
|
|
33
|
+
const SUBDIV_MID_CLOSED = sdc.SUBDIV_MID_CLOSED;
|
|
34
|
+
const SUBDIV_THIRDS_OPEN = sdc.SUBDIV_THIRDS_OPEN;
|
|
35
|
+
const SUBDIV_THIRDS_CLOSED = sdc.SUBDIV_THIRDS_CLOSED;
|
|
36
|
+
const SUBDIV_CHAIKIN_OPEN = sdc.SUBDIV_CHAIKIN_OPEN;
|
|
37
|
+
const SUBDIV_CHAIKIN_CLOSED = sdc.SUBDIV_CHAIKIN_CLOSED;
|
|
38
|
+
const SUBDIV_CUBIC_CLOSED = sdc.SUBDIV_CUBIC_CLOSED;
|
|
39
|
+
export {
|
|
40
|
+
SUBDIV_CHAIKIN_CLOSED,
|
|
41
|
+
SUBDIV_CHAIKIN_OPEN,
|
|
42
|
+
SUBDIV_CUBIC_CLOSED,
|
|
43
|
+
SUBDIV_MID_CLOSED,
|
|
44
|
+
SUBDIV_MID_OPEN,
|
|
45
|
+
SUBDIV_THIRDS_CLOSED,
|
|
46
|
+
SUBDIV_THIRDS_OPEN,
|
|
47
|
+
subdivCurve
|
|
48
|
+
};
|
package/tangent-at.js
CHANGED
|
@@ -7,34 +7,22 @@ import { HALF_PI, TAU } from "@thi.ng/math/api";
|
|
|
7
7
|
import { direction2 } from "@thi.ng/vectors/direction";
|
|
8
8
|
import { __dispatch } from "./internal/dispatch.js";
|
|
9
9
|
import { vertices } from "./vertices.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @remarks
|
|
14
|
-
* Currently implemented for:
|
|
15
|
-
*
|
|
16
|
-
* - {@link Circle}
|
|
17
|
-
* - {@link Cubic}
|
|
18
|
-
* - {@link Line}
|
|
19
|
-
* - {@link Polygon}
|
|
20
|
-
* - {@link Polyline}
|
|
21
|
-
* - {@link Quad}
|
|
22
|
-
* - {@link Quadratic}
|
|
23
|
-
* - {@link Rect}
|
|
24
|
-
* - {@link Triangle}
|
|
25
|
-
*
|
|
26
|
-
* @param shape
|
|
27
|
-
* @param t
|
|
28
|
-
*/
|
|
29
|
-
export const tangentAt = defmulti(__dispatch, {
|
|
10
|
+
const tangentAt = defmulti(
|
|
11
|
+
__dispatch,
|
|
12
|
+
{
|
|
30
13
|
quad: "poly",
|
|
31
|
-
tri: "poly"
|
|
32
|
-
},
|
|
14
|
+
tri: "poly"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
33
17
|
circle: (_, t) => cossin(TAU * t + HALF_PI),
|
|
34
18
|
cubic: ({ points }, t) => cubicTangentAt([], points[0], points[1], points[2], points[3], t),
|
|
35
19
|
line: ({ points }) => direction2([], points[0], points[1]),
|
|
36
20
|
poly: ($, t) => new Sampler($.points, true).tangentAt(t),
|
|
37
21
|
polyline: ($, t) => new Sampler($.points).tangentAt(t),
|
|
38
22
|
quadratic: ({ points }, t) => quadraticTangentAt([], points[0], points[1], points[2], t),
|
|
39
|
-
rect: ($, t) => new Sampler(vertices($), true).tangentAt(t)
|
|
40
|
-
}
|
|
23
|
+
rect: ($, t) => new Sampler(vertices($), true).tangentAt(t)
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
export {
|
|
27
|
+
tangentAt
|
|
28
|
+
};
|
package/tessellate.js
CHANGED
|
@@ -10,51 +10,26 @@ import { mapcat } from "@thi.ng/transducers/mapcat";
|
|
|
10
10
|
import { Group } from "./api/group.js";
|
|
11
11
|
import { __dispatch } from "./internal/dispatch.js";
|
|
12
12
|
import { vertices } from "./vertices.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* [thi.ng/geom-tessellate](https://thi.ng/thi.ng/geom-tessellate) package for
|
|
18
|
-
* more details.
|
|
19
|
-
*
|
|
20
|
-
* @remarks
|
|
21
|
-
* Implemented for all shapes supported by {@link vertices}. For groups, every
|
|
22
|
-
* child shape will be tessellated individually.
|
|
23
|
-
*
|
|
24
|
-
* @param shape
|
|
25
|
-
* @param tessellators
|
|
26
|
-
*/
|
|
27
|
-
export const tessellate = defmulti(__dispatch, {}, {
|
|
13
|
+
const tessellate = defmulti(
|
|
14
|
+
__dispatch,
|
|
15
|
+
{},
|
|
16
|
+
{
|
|
28
17
|
[DEFAULT]: ($, fns) => _tessellate(vertices($), fns),
|
|
29
|
-
group: ($, fns) => mapcat((x) => _tessellate(vertices(x), fns), $.children)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* Alias for thi.ng/geom-tessellate
|
|
48
|
-
* [`quadFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/quadFan.html)
|
|
49
|
-
*/
|
|
50
|
-
export const TESSELLATE_QUAD_FAN = quadFan;
|
|
51
|
-
/**
|
|
52
|
-
* Alias for thi.ng/geom-tessellate
|
|
53
|
-
* [`rimTris`](https://docs.thi.ng/umbrella/geom-tessellate/functions/rimTris.html)
|
|
54
|
-
*/
|
|
55
|
-
export const TESSELLATE_RIM_TRIS = rimTris;
|
|
56
|
-
/**
|
|
57
|
-
* Alias for thi.ng/geom-tessellate
|
|
58
|
-
* [`triFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/triFan.html)
|
|
59
|
-
*/
|
|
60
|
-
export const TESSELLATE_TRI_FAN = triFan;
|
|
18
|
+
group: ($, fns) => mapcat((x) => _tessellate(vertices(x), fns), $.children)
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
const TESSELLATE_EARCUT = earCut2;
|
|
22
|
+
const TESSELLATE_EDGE_SPLIT = edgeSplit;
|
|
23
|
+
const TESSELLATE_INSET = tesselInset;
|
|
24
|
+
const TESSELLATE_QUAD_FAN = quadFan;
|
|
25
|
+
const TESSELLATE_RIM_TRIS = rimTris;
|
|
26
|
+
const TESSELLATE_TRI_FAN = triFan;
|
|
27
|
+
export {
|
|
28
|
+
TESSELLATE_EARCUT,
|
|
29
|
+
TESSELLATE_EDGE_SPLIT,
|
|
30
|
+
TESSELLATE_INSET,
|
|
31
|
+
TESSELLATE_QUAD_FAN,
|
|
32
|
+
TESSELLATE_RIM_TRIS,
|
|
33
|
+
TESSELLATE_TRI_FAN,
|
|
34
|
+
tessellate
|
|
35
|
+
};
|
package/text.js
CHANGED
package/transform-vertices.js
CHANGED
|
@@ -14,64 +14,36 @@ import { asPolygon } from "./as-polygon.js";
|
|
|
14
14
|
import { asPolyline } from "./as-polyline.js";
|
|
15
15
|
import { __copyAttribs } from "./internal/copy.js";
|
|
16
16
|
import { __dispatch } from "./internal/dispatch.js";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* Some shape types will be automatically converted to other types prior to
|
|
25
|
-
* transformation because they cannot be reliably represented in their original
|
|
26
|
-
* type anymore, this includes:
|
|
27
|
-
*
|
|
28
|
-
* - {@link Arc} => {@link Path} (cubics)
|
|
29
|
-
* - {@link Circle} => {@link Path} (cubics)
|
|
30
|
-
* - {@link Ellipse} => {@link Path} (cubics)
|
|
31
|
-
* - {@link Rect} => {@link Polygon}
|
|
32
|
-
*
|
|
33
|
-
* Currently implemented for:
|
|
34
|
-
*
|
|
35
|
-
* - {@link Arc}
|
|
36
|
-
* - {@link Circle}
|
|
37
|
-
* - {@link Cubic}
|
|
38
|
-
* - {@link Ellipse}
|
|
39
|
-
* - {@link Group}
|
|
40
|
-
* - {@link Line}
|
|
41
|
-
* - {@link Path}
|
|
42
|
-
* - {@link Points}
|
|
43
|
-
* - {@link Points3}
|
|
44
|
-
* - {@link Polygon}
|
|
45
|
-
* - {@link Polyline}
|
|
46
|
-
* - {@link Quad}
|
|
47
|
-
* - {@link Quadratic}
|
|
48
|
-
* - {@link Ray}
|
|
49
|
-
* - {@link Rect}
|
|
50
|
-
* - {@link Text}
|
|
51
|
-
* - {@link Triangle}
|
|
52
|
-
*
|
|
53
|
-
* @param shape
|
|
54
|
-
* @param fn
|
|
55
|
-
*/
|
|
56
|
-
export const transformVertices = defmulti(__dispatch, {
|
|
17
|
+
import {
|
|
18
|
+
__transformedShapePoints as tx,
|
|
19
|
+
__transformedShapePoints3 as tx3
|
|
20
|
+
} from "./internal/transform.js";
|
|
21
|
+
const transformVertices = defmulti(
|
|
22
|
+
__dispatch,
|
|
23
|
+
{
|
|
57
24
|
circle: "rect",
|
|
58
|
-
ellipse: "circle"
|
|
59
|
-
},
|
|
25
|
+
ellipse: "circle"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
60
28
|
arc: ($, fn) => transformVertices(asPolyline($), fn),
|
|
61
29
|
cubic: tx(Cubic),
|
|
62
30
|
group: ($, fn) => $.copyTransformed((x) => transformVertices(x, fn)),
|
|
63
31
|
line: tx(Line),
|
|
64
|
-
path: ($, fn) => new Path(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
32
|
+
path: ($, fn) => new Path(
|
|
33
|
+
[
|
|
34
|
+
...map(
|
|
35
|
+
(s) => s.type === "m" ? {
|
|
36
|
+
type: s.type,
|
|
37
|
+
point: mulV([], fn(s.point), s.point)
|
|
38
|
+
} : {
|
|
39
|
+
type: s.type,
|
|
40
|
+
geo: transformVertices(s.geo, fn)
|
|
41
|
+
},
|
|
42
|
+
$.segments
|
|
43
|
+
)
|
|
44
|
+
],
|
|
45
|
+
__copyAttribs($)
|
|
46
|
+
),
|
|
75
47
|
points: tx(Points),
|
|
76
48
|
points3: tx3(Points3),
|
|
77
49
|
poly: tx(Polygon),
|
|
@@ -79,5 +51,9 @@ export const transformVertices = defmulti(__dispatch, {
|
|
|
79
51
|
quad: tx(Quad),
|
|
80
52
|
quadratic: tx(Quadratic),
|
|
81
53
|
rect: ($, fn) => transformVertices(asPolygon($), fn),
|
|
82
|
-
tri: tx(Triangle)
|
|
83
|
-
}
|
|
54
|
+
tri: tx(Triangle)
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
export {
|
|
58
|
+
transformVertices
|
|
59
|
+
};
|