@thi.ng/geom 6.0.6 → 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 -31
- 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/rect.js
CHANGED
|
@@ -10,54 +10,55 @@ import { sub2 } from "@thi.ng/vectors/sub";
|
|
|
10
10
|
import { subN2 } from "@thi.ng/vectors/subn";
|
|
11
11
|
import { Rect } from "./api/rect.js";
|
|
12
12
|
import { __argAttribs, __argsVV, __asVec } from "./internal/args.js";
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function rect(...args) {
|
|
14
|
+
return new Rect(...__argsVV(args));
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const rectFromMinMax = (min, max, attribs) => new Rect(min, sub2([], max, min), attribs);
|
|
17
|
+
const rectFromMinMaxWithMargin = (min, max, margin, attribs) => rectFromMinMax(min, max, attribs).offset(margin);
|
|
18
|
+
const rectWithCentroid = (centroid2, size, attribs) => {
|
|
19
|
+
size = __asVec(size);
|
|
20
|
+
return new Rect(maddN2([], size, -0.5, centroid2), size, attribs);
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* @param b -
|
|
29
|
-
*/
|
|
30
|
-
export const intersectionRect = (a, b) => {
|
|
31
|
-
const p = max2([], a.pos, b.pos);
|
|
32
|
-
const q = min2(null, add2([], a.pos, a.size), add2([], b.pos, b.size));
|
|
33
|
-
const size = max2(null, sub2(null, q, p), ZERO2);
|
|
34
|
-
return size[0] > 0 && size[1] > 0 ? new Rect(p, size) : undefined;
|
|
22
|
+
const rectWithCentroidAndMargin = (centroid2, size, margin, attribs) => rectWithCentroid(centroid2, size, attribs).offset(margin);
|
|
23
|
+
const intersectionRect = (a, b) => {
|
|
24
|
+
const p = max2([], a.pos, b.pos);
|
|
25
|
+
const q = min2(null, add2([], a.pos, a.size), add2([], b.pos, b.size));
|
|
26
|
+
const size = max2(null, sub2(null, q, p), ZERO2);
|
|
27
|
+
return size[0] > 0 && size[1] > 0 ? new Rect(p, size) : void 0;
|
|
35
28
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return rect(subN2([], pos, r), r * 2, attribs);
|
|
29
|
+
function inscribedSquare(...args) {
|
|
30
|
+
let pos, r;
|
|
31
|
+
const attribs = __argAttribs(args);
|
|
32
|
+
if (args.length === 1) {
|
|
33
|
+
const c = args[0];
|
|
34
|
+
pos = c.pos;
|
|
35
|
+
r = c.r;
|
|
36
|
+
} else {
|
|
37
|
+
[pos, r] = args;
|
|
38
|
+
}
|
|
39
|
+
r *= SQRT2_2;
|
|
40
|
+
return rect(subN2([], pos, r), r * 2, attribs);
|
|
49
41
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return rect(subN2([], pos, l / 2), l, attribs);
|
|
42
|
+
function inscribedSquareHex(...args) {
|
|
43
|
+
let pos, l;
|
|
44
|
+
const attribs = __argAttribs(args);
|
|
45
|
+
if (args.length === 1) {
|
|
46
|
+
const pts = args[0].points;
|
|
47
|
+
pos = centroid(pts);
|
|
48
|
+
l = dist(pts[0], pts[1]);
|
|
49
|
+
} else {
|
|
50
|
+
[pos, l] = args;
|
|
51
|
+
}
|
|
52
|
+
l *= 3 - SQRT3;
|
|
53
|
+
return rect(subN2([], pos, l / 2), l, attribs);
|
|
63
54
|
}
|
|
55
|
+
export {
|
|
56
|
+
inscribedSquare,
|
|
57
|
+
inscribedSquareHex,
|
|
58
|
+
intersectionRect,
|
|
59
|
+
rect,
|
|
60
|
+
rectFromMinMax,
|
|
61
|
+
rectFromMinMaxWithMargin,
|
|
62
|
+
rectWithCentroid,
|
|
63
|
+
rectWithCentroidAndMargin
|
|
64
|
+
};
|
package/resample.js
CHANGED
|
@@ -5,36 +5,21 @@ import { Polyline } from "./api/polyline.js";
|
|
|
5
5
|
import { asPolygon } from "./as-polygon.js";
|
|
6
6
|
import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
|
|
7
7
|
import { __dispatch } from "./internal/dispatch.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
14
|
-
* avoid recursive application.
|
|
15
|
-
*
|
|
16
|
-
* Currently implemented for:
|
|
17
|
-
*
|
|
18
|
-
* - {@link Circle}
|
|
19
|
-
* - {@link Ellipse}
|
|
20
|
-
* - {@link Line}
|
|
21
|
-
* - {@link Polygon}
|
|
22
|
-
* - {@link Polyline}
|
|
23
|
-
* - {@link Quad}
|
|
24
|
-
* - {@link Rect}
|
|
25
|
-
* - {@link Triangle}
|
|
26
|
-
*
|
|
27
|
-
* @param shape
|
|
28
|
-
* @param opts
|
|
29
|
-
*/
|
|
30
|
-
export const resample = defmulti(__dispatch, {
|
|
8
|
+
const resample = defmulti(
|
|
9
|
+
__dispatch,
|
|
10
|
+
{
|
|
31
11
|
ellipse: "circle",
|
|
32
12
|
line: "polyline",
|
|
33
13
|
quad: "poly",
|
|
34
14
|
tri: "poly",
|
|
35
|
-
rect: "circle"
|
|
36
|
-
},
|
|
15
|
+
rect: "circle"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
37
18
|
circle: ($, opts) => asPolygon($, opts),
|
|
38
19
|
poly: ($, opts) => new Polygon(_resample($.points, opts, true, true), __attribs($)),
|
|
39
|
-
polyline: ($, opts) => new Polyline(_resample($.points, opts, false, true), __attribs($))
|
|
40
|
-
}
|
|
20
|
+
polyline: ($, opts) => new Polyline(_resample($.points, opts, false, true), __attribs($))
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
export {
|
|
24
|
+
resample
|
|
25
|
+
};
|
package/rotate.js
CHANGED
|
@@ -17,37 +17,14 @@ import { asPolygon } from "./as-polygon.js";
|
|
|
17
17
|
import { __copyAttribs } from "./internal/copy.js";
|
|
18
18
|
import { __dispatch } from "./internal/dispatch.js";
|
|
19
19
|
import { __rotatedShape as tx } from "./internal/rotate.js";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* Currently implemented for:
|
|
25
|
-
*
|
|
26
|
-
* - {@link Arc}
|
|
27
|
-
* - {@link Circle}
|
|
28
|
-
* - {@link Cubic}
|
|
29
|
-
* - {@link Ellipse}
|
|
30
|
-
* - {@link Group}
|
|
31
|
-
* - {@link Line}
|
|
32
|
-
* - {@link Path}
|
|
33
|
-
* - {@link Points}
|
|
34
|
-
* - {@link Polygon}
|
|
35
|
-
* - {@link Polyline}
|
|
36
|
-
* - {@link Quad}
|
|
37
|
-
* - {@link Quadratic}
|
|
38
|
-
* - {@link Ray}
|
|
39
|
-
* - {@link Rect}
|
|
40
|
-
* - {@link Text}
|
|
41
|
-
* - {@link Triangle}
|
|
42
|
-
*
|
|
43
|
-
* @param shape
|
|
44
|
-
* @param theta
|
|
45
|
-
*/
|
|
46
|
-
export const rotate = defmulti(__dispatch, {}, {
|
|
20
|
+
const rotate = defmulti(
|
|
21
|
+
__dispatch,
|
|
22
|
+
{},
|
|
23
|
+
{
|
|
47
24
|
arc: ($, theta) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
25
|
+
const a = $.copy();
|
|
26
|
+
$rotate(null, a.pos, theta);
|
|
27
|
+
return a;
|
|
51
28
|
},
|
|
52
29
|
circle: ($, theta) => new Circle($rotate([], $.pos, theta), $.r, __copyAttribs($)),
|
|
53
30
|
cubic: tx(Cubic),
|
|
@@ -55,15 +32,18 @@ export const rotate = defmulti(__dispatch, {}, {
|
|
|
55
32
|
group: ($, theta) => $.copyTransformed((x) => rotate(x, theta)),
|
|
56
33
|
line: tx(Line),
|
|
57
34
|
path: ($, theta) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
35
|
+
return new Path(
|
|
36
|
+
$.segments.map(
|
|
37
|
+
(s) => s.geo ? {
|
|
38
|
+
type: s.type,
|
|
39
|
+
geo: rotate(s.geo, theta)
|
|
40
|
+
} : {
|
|
41
|
+
type: s.type,
|
|
42
|
+
point: $rotate([], s.point, theta)
|
|
43
|
+
}
|
|
44
|
+
),
|
|
45
|
+
__copyAttribs($)
|
|
46
|
+
);
|
|
67
47
|
},
|
|
68
48
|
points: tx(Points),
|
|
69
49
|
poly: tx(Polygon),
|
|
@@ -71,9 +51,17 @@ export const rotate = defmulti(__dispatch, {}, {
|
|
|
71
51
|
quad: tx(Quad),
|
|
72
52
|
quadratic: tx(Quadratic),
|
|
73
53
|
ray: ($, theta) => {
|
|
74
|
-
|
|
54
|
+
return new Ray(
|
|
55
|
+
$rotate([], $.pos, theta),
|
|
56
|
+
$rotate([], $.dir, theta),
|
|
57
|
+
__copyAttribs($)
|
|
58
|
+
);
|
|
75
59
|
},
|
|
76
60
|
rect: ($, theta) => rotate(asPolygon($), theta),
|
|
77
61
|
text: ($, theta) => new Text($rotate([], $.pos, theta), $.body, __copyAttribs($)),
|
|
78
|
-
tri: tx(Triangle)
|
|
79
|
-
}
|
|
62
|
+
tri: tx(Triangle)
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
export {
|
|
66
|
+
rotate
|
|
67
|
+
};
|
package/scale.js
CHANGED
|
@@ -24,71 +24,59 @@ import { __asVec } from "./internal/args.js";
|
|
|
24
24
|
import { __copyAttribs } from "./internal/copy.js";
|
|
25
25
|
import { __dispatch } from "./internal/dispatch.js";
|
|
26
26
|
import { __scaledShape as tx } from "./internal/scale.js";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* Scaling non-uniformly might result in different result types, e.g.
|
|
32
|
-
* {@link Circle} => {@link Ellipse}.
|
|
33
|
-
*
|
|
34
|
-
* Currently implemented for:
|
|
35
|
-
*
|
|
36
|
-
* - {@link AABB}
|
|
37
|
-
* - {@link Arc}
|
|
38
|
-
* - {@link Circle}
|
|
39
|
-
* - {@link Cubic}
|
|
40
|
-
* - {@link Ellipse}
|
|
41
|
-
* - {@link Group}
|
|
42
|
-
* - {@link Line}
|
|
43
|
-
* - {@link Path}
|
|
44
|
-
* - {@link Points}
|
|
45
|
-
* - {@link Points3}
|
|
46
|
-
* - {@link Polygon}
|
|
47
|
-
* - {@link Polyline}
|
|
48
|
-
* - {@link Quad}
|
|
49
|
-
* - {@link Quadratic}
|
|
50
|
-
* - {@link Ray}
|
|
51
|
-
* - {@link Rect}
|
|
52
|
-
* - {@link Sphere}
|
|
53
|
-
* - {@link Text}
|
|
54
|
-
* - {@link Triangle}
|
|
55
|
-
*
|
|
56
|
-
* @param shape
|
|
57
|
-
* @param factor
|
|
58
|
-
*/
|
|
59
|
-
export const scale = defmulti(__dispatch, {}, {
|
|
27
|
+
const scale = defmulti(
|
|
28
|
+
__dispatch,
|
|
29
|
+
{},
|
|
30
|
+
{
|
|
60
31
|
aabb: ($, delta) => {
|
|
61
|
-
|
|
62
|
-
|
|
32
|
+
delta = __asVec(delta, 3);
|
|
33
|
+
return new AABB(
|
|
34
|
+
mul3([], $.pos, delta),
|
|
35
|
+
mul3([], $.size, delta),
|
|
36
|
+
__copyAttribs($)
|
|
37
|
+
);
|
|
63
38
|
},
|
|
64
39
|
arc: ($, delta) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
40
|
+
delta = __asVec(delta);
|
|
41
|
+
const a = $.copy();
|
|
42
|
+
mul2(null, a.pos, delta);
|
|
43
|
+
mul2(null, a.r, delta);
|
|
44
|
+
return a;
|
|
70
45
|
},
|
|
71
|
-
circle: ($, delta) => isNumber(delta)
|
|
72
|
-
|
|
73
|
-
|
|
46
|
+
circle: ($, delta) => isNumber(delta) ? new Circle(
|
|
47
|
+
mulN2([], $.pos, delta),
|
|
48
|
+
$.r * delta,
|
|
49
|
+
__copyAttribs($)
|
|
50
|
+
) : new Ellipse(
|
|
51
|
+
mul2([], $.pos, delta),
|
|
52
|
+
mulN2([], delta, $.r),
|
|
53
|
+
__copyAttribs($)
|
|
54
|
+
),
|
|
74
55
|
cubic: tx(Cubic),
|
|
75
56
|
ellipse: ($, delta) => {
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
delta = __asVec(delta);
|
|
58
|
+
return new Ellipse(
|
|
59
|
+
mul2([], $.pos, delta),
|
|
60
|
+
mul2([], $.r, delta),
|
|
61
|
+
__copyAttribs($)
|
|
62
|
+
);
|
|
78
63
|
},
|
|
79
64
|
group: ($, delta) => $.copyTransformed((x) => scale(x, delta)),
|
|
80
65
|
line: tx(Line),
|
|
81
66
|
path: ($, delta) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
67
|
+
delta = __asVec(delta);
|
|
68
|
+
return new Path(
|
|
69
|
+
$.segments.map(
|
|
70
|
+
(s) => s.geo ? {
|
|
71
|
+
type: s.type,
|
|
72
|
+
geo: scale(s.geo, delta)
|
|
73
|
+
} : {
|
|
74
|
+
type: s.type,
|
|
75
|
+
point: mul2([], s.point, delta)
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
__copyAttribs($)
|
|
79
|
+
);
|
|
92
80
|
},
|
|
93
81
|
points: tx(Points),
|
|
94
82
|
points3: tx(Points3),
|
|
@@ -97,16 +85,30 @@ export const scale = defmulti(__dispatch, {}, {
|
|
|
97
85
|
quad: tx(Quad),
|
|
98
86
|
quadratic: tx(Quadratic),
|
|
99
87
|
ray: ($, delta) => {
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
delta = __asVec(delta);
|
|
89
|
+
return new Ray(
|
|
90
|
+
mul2([], $.pos, delta),
|
|
91
|
+
normalize2(null, mul2([], $.dir, delta)),
|
|
92
|
+
__copyAttribs($)
|
|
93
|
+
);
|
|
102
94
|
},
|
|
103
95
|
rect: ($, delta) => {
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
delta = __asVec(delta);
|
|
97
|
+
return new Rect(
|
|
98
|
+
mul2([], $.pos, delta),
|
|
99
|
+
mul2([], $.size, delta),
|
|
100
|
+
__copyAttribs($)
|
|
101
|
+
);
|
|
106
102
|
},
|
|
107
|
-
sphere: ($, delta) => isNumber(delta)
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
sphere: ($, delta) => isNumber(delta) ? new Sphere(
|
|
104
|
+
mulN3([], $.pos, delta),
|
|
105
|
+
$.r * delta,
|
|
106
|
+
__copyAttribs($)
|
|
107
|
+
) : unsupported("can't non-uniformly scale sphere"),
|
|
110
108
|
text: ($, delta) => new Text(mul2([], $.pos, __asVec(delta)), $.body, __copyAttribs($)),
|
|
111
|
-
tri: tx(Triangle)
|
|
112
|
-
}
|
|
109
|
+
tri: tx(Triangle)
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
export {
|
|
113
|
+
scale
|
|
114
|
+
};
|
package/scatter.js
CHANGED
|
@@ -2,35 +2,23 @@ import { SYSTEM } from "@thi.ng/random/system";
|
|
|
2
2
|
import { randMinMax } from "@thi.ng/vectors/rand-minmax";
|
|
3
3
|
import { bounds } from "./bounds.js";
|
|
4
4
|
import { pointInside } from "./point-inside.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @param out
|
|
19
|
-
*/
|
|
20
|
-
export const scatter = (shape, num, rnd = SYSTEM, out = []) => {
|
|
21
|
-
const b = bounds(shape);
|
|
22
|
-
if (!b)
|
|
23
|
-
return;
|
|
24
|
-
const mi = b.pos;
|
|
25
|
-
const mx = b.max();
|
|
26
|
-
for (; num-- > 0;) {
|
|
27
|
-
while (true) {
|
|
28
|
-
const p = randMinMax([], mi, mx, rnd);
|
|
29
|
-
if (pointInside(shape, p)) {
|
|
30
|
-
out.push(p);
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
5
|
+
const scatter = (shape, num, rnd = SYSTEM, out = []) => {
|
|
6
|
+
const b = bounds(shape);
|
|
7
|
+
if (!b)
|
|
8
|
+
return;
|
|
9
|
+
const mi = b.pos;
|
|
10
|
+
const mx = b.max();
|
|
11
|
+
for (; num-- > 0; ) {
|
|
12
|
+
while (true) {
|
|
13
|
+
const p = randMinMax([], mi, mx, rnd);
|
|
14
|
+
if (pointInside(shape, p)) {
|
|
15
|
+
out.push(p);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
34
18
|
}
|
|
35
|
-
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
scatter
|
|
36
24
|
};
|
package/simplify.js
CHANGED
|
@@ -7,62 +7,45 @@ import { Polyline } from "./api/polyline.js";
|
|
|
7
7
|
import { __copyAttribs } from "./internal/copy.js";
|
|
8
8
|
import { __dispatch } from "./internal/dispatch.js";
|
|
9
9
|
import { vertices } from "./vertices.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* and given `threshold` distance (default: 0, which removes only co-linear
|
|
15
|
-
* vertices).
|
|
16
|
-
*
|
|
17
|
-
* @remarks
|
|
18
|
-
* Currently only implemented for:
|
|
19
|
-
*
|
|
20
|
-
* - {@link Path}
|
|
21
|
-
* - {@link Polygon}
|
|
22
|
-
* - {@link Polyline}
|
|
23
|
-
*
|
|
24
|
-
* Use {@link asPath}, {@link asPolygon} or {@link asPolyline} to convert other
|
|
25
|
-
* shape types first.
|
|
26
|
-
*
|
|
27
|
-
* @param shape
|
|
28
|
-
* @param threshold
|
|
29
|
-
*/
|
|
30
|
-
export const simplify = defmulti(__dispatch, {}, {
|
|
10
|
+
const simplify = defmulti(
|
|
11
|
+
__dispatch,
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
31
14
|
path: ($, eps = 0) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
points = null;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
res.push({ ...s });
|
|
55
|
-
}
|
|
15
|
+
const res = [];
|
|
16
|
+
const orig = $.segments;
|
|
17
|
+
const n = orig.length;
|
|
18
|
+
let points;
|
|
19
|
+
let lastP;
|
|
20
|
+
for (let i = 0; i < n; i++) {
|
|
21
|
+
const s = orig[i];
|
|
22
|
+
if (s.type === "l" || s.type === "p") {
|
|
23
|
+
points = points ? points.concat(vertices(s.geo)) : vertices(s.geo);
|
|
24
|
+
lastP = peek(points);
|
|
25
|
+
} else if (points) {
|
|
26
|
+
points.push(lastP);
|
|
27
|
+
res.push({
|
|
28
|
+
geo: new Polyline(_simplify(points, eps)),
|
|
29
|
+
type: "p"
|
|
30
|
+
});
|
|
31
|
+
points = null;
|
|
32
|
+
} else {
|
|
33
|
+
res.push({ ...s });
|
|
56
34
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
35
|
+
}
|
|
36
|
+
if (points) {
|
|
37
|
+
points.push(lastP);
|
|
38
|
+
res.push({
|
|
39
|
+
geo: new Polyline(points),
|
|
40
|
+
type: "p"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return new Path(res, __copyAttribs($));
|
|
65
44
|
},
|
|
66
45
|
poly: ($, eps = 0) => new Polygon(_simplify($.points, eps, true), __copyAttribs($)),
|
|
67
|
-
polyline: ($, eps = 0) => new Polyline(_simplify($.points, eps), __copyAttribs($))
|
|
68
|
-
}
|
|
46
|
+
polyline: ($, eps = 0) => new Polyline(_simplify($.points, eps), __copyAttribs($))
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
export {
|
|
50
|
+
simplify
|
|
51
|
+
};
|
package/sphere.js
CHANGED
|
@@ -2,7 +2,11 @@ import { dist } from "@thi.ng/vectors/dist";
|
|
|
2
2
|
import { mixN3 } from "@thi.ng/vectors/mixn";
|
|
3
3
|
import { Sphere } from "./api/sphere.js";
|
|
4
4
|
import { __argsVN } from "./internal/args.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function sphere(...args) {
|
|
6
|
+
return new Sphere(...__argsVN(args));
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
const sphereFrom2Points = (a, b, attribs) => new Sphere(mixN3([], a, b, 0.5), dist(a, b) / 2, attribs);
|
|
9
|
+
export {
|
|
10
|
+
sphere,
|
|
11
|
+
sphereFrom2Points
|
|
12
|
+
};
|