@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/transform.js
CHANGED
|
@@ -14,64 +14,37 @@ import { Triangle } from "./api/triangle.js";
|
|
|
14
14
|
import { asPath } from "./as-path.js";
|
|
15
15
|
import { __copyAttribs } from "./internal/copy.js";
|
|
16
16
|
import { __dispatch } from "./internal/dispatch.js";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
__transformedShape as tx,
|
|
19
|
+
__transformedShape3 as tx3
|
|
20
|
+
} from "./internal/transform.js";
|
|
18
21
|
import { vertices } from "./vertices.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @remarks
|
|
23
|
-
* A 2x3 transform matrix is assumed for 2D shapes and 4x4 matrix for 3D shapes.
|
|
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 Quad}
|
|
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 mat
|
|
55
|
-
*/
|
|
56
|
-
export const transform = defmulti(__dispatch, {
|
|
22
|
+
const transform = defmulti(
|
|
23
|
+
__dispatch,
|
|
24
|
+
{
|
|
57
25
|
circle: "arc",
|
|
58
|
-
ellipse: "circle"
|
|
59
|
-
},
|
|
26
|
+
ellipse: "circle"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
60
29
|
arc: ($, mat) => transform(asPath($), mat),
|
|
61
30
|
cubic: tx(Cubic),
|
|
62
31
|
group: ($, mat) => $.copyTransformed((x) => transform(x, mat)),
|
|
63
32
|
line: tx(Line),
|
|
64
|
-
path: ($, mat) => new Path(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
33
|
+
path: ($, mat) => new Path(
|
|
34
|
+
[
|
|
35
|
+
...map(
|
|
36
|
+
(s) => s.type === "m" ? {
|
|
37
|
+
type: s.type,
|
|
38
|
+
point: mulV([], mat, s.point)
|
|
39
|
+
} : {
|
|
40
|
+
type: s.type,
|
|
41
|
+
geo: transform(s.geo, mat)
|
|
42
|
+
},
|
|
43
|
+
$.segments
|
|
44
|
+
)
|
|
45
|
+
],
|
|
46
|
+
__copyAttribs($)
|
|
47
|
+
),
|
|
75
48
|
points: tx(Points),
|
|
76
49
|
points3: tx3(Points3),
|
|
77
50
|
poly: tx(Polygon),
|
|
@@ -80,5 +53,9 @@ export const transform = defmulti(__dispatch, {
|
|
|
80
53
|
quadratic: tx(Quadratic),
|
|
81
54
|
rect: ($, mat) => transform(new Quad(vertices($), __copyAttribs($)), mat),
|
|
82
55
|
text: ($, mat) => new Text(mulV([], mat, $.pos), $.body, __copyAttribs($)),
|
|
83
|
-
tri: tx(Triangle)
|
|
84
|
-
}
|
|
56
|
+
tri: tx(Triangle)
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
export {
|
|
60
|
+
transform
|
|
61
|
+
};
|
package/translate.js
CHANGED
|
@@ -20,56 +20,41 @@ import { Triangle } from "./api/triangle.js";
|
|
|
20
20
|
import { __copyAttribs } from "./internal/copy.js";
|
|
21
21
|
import { __dispatch } from "./internal/dispatch.js";
|
|
22
22
|
import { __translatedShape as tx } from "./internal/translate.js";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* - {@link Cubic}
|
|
33
|
-
* - {@link Ellipse}
|
|
34
|
-
* - {@link Group}
|
|
35
|
-
* - {@link Line}
|
|
36
|
-
* - {@link Path}
|
|
37
|
-
* - {@link Points}
|
|
38
|
-
* - {@link Points3}
|
|
39
|
-
* - {@link Polygon}
|
|
40
|
-
* - {@link Polyline}
|
|
41
|
-
* - {@link Quad}
|
|
42
|
-
* - {@link Quadratic}
|
|
43
|
-
* - {@link Ray}
|
|
44
|
-
* - {@link Rect}
|
|
45
|
-
* - {@link Sphere}
|
|
46
|
-
* - {@link Text}
|
|
47
|
-
* - {@link Triangle}
|
|
48
|
-
*
|
|
49
|
-
* @param shape
|
|
50
|
-
* @param offset
|
|
51
|
-
*/
|
|
52
|
-
export const translate = defmulti(__dispatch, {}, {
|
|
53
|
-
aabb: ($, delta) => new AABB(add3([], $.pos, delta), set3([], $.size), __copyAttribs($)),
|
|
23
|
+
const translate = defmulti(
|
|
24
|
+
__dispatch,
|
|
25
|
+
{},
|
|
26
|
+
{
|
|
27
|
+
aabb: ($, delta) => new AABB(
|
|
28
|
+
add3([], $.pos, delta),
|
|
29
|
+
set3([], $.size),
|
|
30
|
+
__copyAttribs($)
|
|
31
|
+
),
|
|
54
32
|
arc: ($, delta) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
33
|
+
const a = $.copy();
|
|
34
|
+
add2(null, a.pos, delta);
|
|
35
|
+
return a;
|
|
58
36
|
},
|
|
59
37
|
circle: ($, delta) => new Circle(add2([], $.pos, delta), $.r, __copyAttribs($)),
|
|
60
38
|
cubic: tx(Cubic),
|
|
61
|
-
ellipse: ($, delta) => new Ellipse(
|
|
39
|
+
ellipse: ($, delta) => new Ellipse(
|
|
40
|
+
add2([], $.pos, delta),
|
|
41
|
+
set2([], $.r),
|
|
42
|
+
__copyAttribs($)
|
|
43
|
+
),
|
|
62
44
|
group: ($, delta) => $.copyTransformed((x) => translate(x, delta)),
|
|
63
45
|
line: tx(Line),
|
|
64
|
-
path: ($, delta) => new Path(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
path: ($, delta) => new Path(
|
|
47
|
+
$.segments.map(
|
|
48
|
+
(s) => s.geo ? {
|
|
49
|
+
type: s.type,
|
|
50
|
+
geo: translate(s.geo, delta)
|
|
51
|
+
} : {
|
|
52
|
+
type: s.type,
|
|
53
|
+
point: add2([], s.point, delta)
|
|
68
54
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}), __copyAttribs($)),
|
|
55
|
+
),
|
|
56
|
+
__copyAttribs($)
|
|
57
|
+
),
|
|
73
58
|
points: tx(Points),
|
|
74
59
|
points3: tx(Points3),
|
|
75
60
|
poly: tx(Polygon),
|
|
@@ -77,8 +62,16 @@ export const translate = defmulti(__dispatch, {}, {
|
|
|
77
62
|
quad: tx(Quad),
|
|
78
63
|
quadratic: tx(Quadratic),
|
|
79
64
|
ray: ($, delta) => new Ray(add2([], $.pos, delta), $.dir, __copyAttribs($)),
|
|
80
|
-
rect: ($, delta) => new Rect(
|
|
65
|
+
rect: ($, delta) => new Rect(
|
|
66
|
+
add2([], $.pos, delta),
|
|
67
|
+
set2([], $.size),
|
|
68
|
+
__copyAttribs($)
|
|
69
|
+
),
|
|
81
70
|
sphere: ($, delta) => new Sphere(add3([], $.pos, delta), $.r, __copyAttribs($)),
|
|
82
71
|
text: ($, delta) => new Text(add2([], $.pos, delta), $.body, __copyAttribs($)),
|
|
83
|
-
tri: tx(Triangle)
|
|
84
|
-
}
|
|
72
|
+
tri: tx(Triangle)
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
export {
|
|
76
|
+
translate
|
|
77
|
+
};
|
package/triangle.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { equilateralTriangle2 } from "@thi.ng/geom-poly-utils/equilateral";
|
|
2
2
|
import { Triangle } from "./api/triangle.js";
|
|
3
3
|
import { __pclike } from "./internal/pclike.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
function triangle(...args) {
|
|
5
|
+
return __pclike(Triangle, args);
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
const equilateralTriangle = (a, b, attribs) => new Triangle(equilateralTriangle2(a, b), attribs);
|
|
8
|
+
export {
|
|
9
|
+
equilateralTriangle,
|
|
10
|
+
triangle
|
|
11
|
+
};
|
package/union.js
CHANGED
|
@@ -3,21 +3,18 @@ import { AABB } from "./api/aabb.js";
|
|
|
3
3
|
import { Rect } from "./api/rect.js";
|
|
4
4
|
import { __unionBounds } from "./internal/bounds.js";
|
|
5
5
|
import { __dispatch } from "./internal/dispatch.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Currently only implemented for {@link AABB} and {@link Rect} to compute union
|
|
11
|
-
* bounding boxes.
|
|
12
|
-
*
|
|
13
|
-
* @param a
|
|
14
|
-
* @param b
|
|
15
|
-
*/
|
|
16
|
-
export const union = defmulti(__dispatch, {}, {
|
|
6
|
+
const union = defmulti(
|
|
7
|
+
__dispatch,
|
|
8
|
+
{},
|
|
9
|
+
{
|
|
17
10
|
aabb: (a, b) => [
|
|
18
|
-
|
|
11
|
+
new AABB(...__unionBounds(a.pos, a.size, b.pos, b.size))
|
|
19
12
|
],
|
|
20
13
|
rect: (a, b) => [
|
|
21
|
-
|
|
22
|
-
]
|
|
23
|
-
}
|
|
14
|
+
new Rect(...__unionBounds(a.pos, a.size, b.pos, b.size))
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
export {
|
|
19
|
+
union
|
|
20
|
+
};
|
package/unmap-point.js
CHANGED
|
@@ -2,29 +2,25 @@ import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
|
2
2
|
import { madd } from "@thi.ng/vectors/madd";
|
|
3
3
|
import { mixBilinear } from "@thi.ng/vectors/mix-bilinear";
|
|
4
4
|
import { __dispatch } from "./internal/dispatch.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* See {@link mapPoint} for reverse operation. Both functions together can be
|
|
11
|
-
* used to warp points from one shape into another.
|
|
12
|
-
*
|
|
13
|
-
* Currently only implemented for these shape types:
|
|
14
|
-
*
|
|
15
|
-
* - {@link AABB}
|
|
16
|
-
* - {@link Quad}
|
|
17
|
-
* - {@link Quad3}
|
|
18
|
-
* - {@link Rect}
|
|
19
|
-
*
|
|
20
|
-
* @param shape - shape to operate on
|
|
21
|
-
* @param uv - point to map in UV space
|
|
22
|
-
* @param out - result
|
|
23
|
-
*/
|
|
24
|
-
export const unmapPoint = defmulti(__dispatch, {
|
|
5
|
+
const unmapPoint = defmulti(
|
|
6
|
+
__dispatch,
|
|
7
|
+
{
|
|
25
8
|
aabb: "rect",
|
|
26
|
-
quad3: "quad"
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
quad3: "quad"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
quad: ({ points }, uv, out = []) => mixBilinear(
|
|
13
|
+
out,
|
|
14
|
+
points[0],
|
|
15
|
+
points[1],
|
|
16
|
+
points[3],
|
|
17
|
+
points[2],
|
|
18
|
+
uv[0],
|
|
19
|
+
uv[1]
|
|
20
|
+
),
|
|
21
|
+
rect: ($, uvw, out = []) => madd(out, $.size, uvw, $.pos)
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
export {
|
|
25
|
+
unmapPoint
|
|
26
|
+
};
|
package/vertices.js
CHANGED
|
@@ -15,59 +15,16 @@ import { set2 } from "@thi.ng/vectors/set";
|
|
|
15
15
|
import { Polygon } from "./api/polygon.js";
|
|
16
16
|
import { __dispatch } from "./internal/dispatch.js";
|
|
17
17
|
import { __circleOpts, __sampleAttribs } from "./internal/vertices.js";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html).
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* The given sampling options (if any) can also be overridden per shape using
|
|
25
|
-
* the special `__samples` attribute. If specified, these will be merged with
|
|
26
|
-
* the options.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* // using default
|
|
31
|
-
* vertices(circle(100))
|
|
32
|
-
*
|
|
33
|
-
* // specify resolution only
|
|
34
|
-
* vertices(circle(100), 6)
|
|
35
|
-
*
|
|
36
|
-
* // specify more advanced options
|
|
37
|
-
* vertices(circle(100), { dist: 10 })
|
|
38
|
-
*
|
|
39
|
-
* // using shape attribs
|
|
40
|
-
* vertices(circle(100, { __samples: { dist: 10 } }))
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* Currently implemented for:
|
|
44
|
-
*
|
|
45
|
-
* - {@link AABB}
|
|
46
|
-
* - {@link Arc}
|
|
47
|
-
* - {@link BPatch}
|
|
48
|
-
* - {@link Circle}
|
|
49
|
-
* - {@link Cubic}
|
|
50
|
-
* - {@link Ellipse}
|
|
51
|
-
* - {@link Group}
|
|
52
|
-
* - {@link Line}
|
|
53
|
-
* - {@link Path}
|
|
54
|
-
* - {@link Points}
|
|
55
|
-
* - {@link Points3}
|
|
56
|
-
* - {@link Quad}
|
|
57
|
-
* - {@link Quadratic}
|
|
58
|
-
* - {@link Rect}
|
|
59
|
-
* - {@link Triangle}
|
|
60
|
-
*
|
|
61
|
-
* @param shape
|
|
62
|
-
* @param opts
|
|
63
|
-
*/
|
|
64
|
-
export const vertices = defmulti(__dispatch, {
|
|
18
|
+
const vertices = defmulti(
|
|
19
|
+
__dispatch,
|
|
20
|
+
{
|
|
65
21
|
line: "polyline",
|
|
66
22
|
bpatch: "points",
|
|
67
23
|
points3: "points",
|
|
68
24
|
quad: "poly",
|
|
69
|
-
tri: "poly"
|
|
70
|
-
},
|
|
25
|
+
tri: "poly"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
71
28
|
// e +----+ h
|
|
72
29
|
// |\ :\
|
|
73
30
|
// |f+----+ g
|
|
@@ -77,83 +34,104 @@ export const vertices = defmulti(__dispatch, {
|
|
|
77
34
|
// b +----+ c
|
|
78
35
|
//
|
|
79
36
|
aabb: ({ pos, size }) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
]
|
|
37
|
+
const [px, py, pz] = pos;
|
|
38
|
+
const [qx, qy, qz] = add3([], pos, size);
|
|
39
|
+
return [
|
|
40
|
+
[px, py, pz],
|
|
41
|
+
// a
|
|
42
|
+
[px, py, qz],
|
|
43
|
+
// b
|
|
44
|
+
[qx, py, qz],
|
|
45
|
+
// c
|
|
46
|
+
[qx, py, pz],
|
|
47
|
+
// d
|
|
48
|
+
[px, qy, pz],
|
|
49
|
+
// e
|
|
50
|
+
[px, qy, qz],
|
|
51
|
+
// f
|
|
52
|
+
[qx, qy, qz],
|
|
53
|
+
// g
|
|
54
|
+
[qx, qy, pz]
|
|
55
|
+
// h
|
|
56
|
+
];
|
|
92
57
|
},
|
|
93
|
-
arc: ($, opts) => _arcVertices(
|
|
58
|
+
arc: ($, opts) => _arcVertices(
|
|
59
|
+
$.pos,
|
|
60
|
+
$.r,
|
|
61
|
+
$.axis,
|
|
62
|
+
$.start,
|
|
63
|
+
$.end,
|
|
64
|
+
__sampleAttribs(opts, $.attribs)
|
|
65
|
+
),
|
|
94
66
|
circle: ($, opts = DEFAULT_SAMPLES) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
67
|
+
opts = __sampleAttribs(opts, $.attribs);
|
|
68
|
+
const pos = $.pos;
|
|
69
|
+
const r = $.r;
|
|
70
|
+
let [num, start, last] = __circleOpts(opts, r);
|
|
71
|
+
const delta = TAU / num;
|
|
72
|
+
last && num++;
|
|
73
|
+
const buf = new Array(num);
|
|
74
|
+
for (let i = 0; i < num; i++) {
|
|
75
|
+
buf[i] = cartesian2(null, [r, start + i * delta], pos);
|
|
76
|
+
}
|
|
77
|
+
return buf;
|
|
106
78
|
},
|
|
107
79
|
cubic: ($, opts) => sampleCubic($.points, __sampleAttribs(opts, $.attribs)),
|
|
108
80
|
ellipse: ($, opts = DEFAULT_SAMPLES) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
81
|
+
opts = __sampleAttribs(opts, $.attribs);
|
|
82
|
+
const buf = [];
|
|
83
|
+
const pos = $.pos;
|
|
84
|
+
const r = $.r;
|
|
85
|
+
let [num, start, last] = __circleOpts(
|
|
86
|
+
opts,
|
|
87
|
+
Math.max($.r[0], $.r[1])
|
|
88
|
+
);
|
|
89
|
+
const delta = TAU / num;
|
|
90
|
+
last && num++;
|
|
91
|
+
for (let i = 0; i < num; i++) {
|
|
92
|
+
buf[i] = madd2([], cossin(start + i * delta), r, pos);
|
|
93
|
+
}
|
|
94
|
+
return buf;
|
|
120
95
|
},
|
|
121
96
|
group: ($, opts) => {
|
|
122
|
-
|
|
123
|
-
|
|
97
|
+
opts = __sampleAttribs(opts, $.attribs);
|
|
98
|
+
return $.children.reduce(
|
|
99
|
+
(acc, $2) => acc.concat(vertices($2, opts)),
|
|
100
|
+
[]
|
|
101
|
+
);
|
|
124
102
|
},
|
|
125
103
|
path: ($, opts) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
104
|
+
opts = __sampleAttribs(opts, $.attribs);
|
|
105
|
+
const _opts = isNumber(opts) ? { num: opts } : opts;
|
|
106
|
+
let verts = [];
|
|
107
|
+
for (let segs = $.segments, n = segs.length - 1, i = 0; i <= n; i++) {
|
|
108
|
+
const s = segs[i];
|
|
109
|
+
if (s.geo) {
|
|
110
|
+
verts = verts.concat(
|
|
111
|
+
vertices(s.geo, {
|
|
112
|
+
..._opts,
|
|
113
|
+
last: i === n && !$.closed
|
|
114
|
+
})
|
|
115
|
+
);
|
|
137
116
|
}
|
|
138
|
-
|
|
117
|
+
}
|
|
118
|
+
return verts;
|
|
139
119
|
},
|
|
140
120
|
points: ($) => $.points,
|
|
141
121
|
poly: ($, opts) => resample($.points, __sampleAttribs(opts, $.attribs), true),
|
|
142
122
|
polyline: ($, opts) => resample($.points, __sampleAttribs(opts, $.attribs)),
|
|
143
123
|
quadratic: ($, opts) => sampleQuadratic($.points, __sampleAttribs(opts, $.attribs)),
|
|
144
124
|
rect: ($, opts) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*/
|
|
159
|
-
export const ensureVertices = (shape) => isArray(shape) ? shape : vertices(shape);
|
|
125
|
+
opts = __sampleAttribs(opts, $.attribs);
|
|
126
|
+
const p = $.pos;
|
|
127
|
+
const q = add2([], p, $.size);
|
|
128
|
+
const verts = [set2([], p), [q[0], p[1]], q, [p[0], q[1]]];
|
|
129
|
+
return opts != null ? vertices(new Polygon(verts), opts) : verts;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
const ensureVertices = (shape) => isArray(shape) ? shape : vertices(shape);
|
|
134
|
+
export {
|
|
135
|
+
ensureVertices,
|
|
136
|
+
vertices
|
|
137
|
+
};
|
package/volume.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { PI } from "@thi.ng/math/api";
|
|
3
3
|
import { __dispatch } from "./internal/dispatch.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Currently only implemented for:
|
|
9
|
-
*
|
|
10
|
-
* - {@link AABB}
|
|
11
|
-
* - {@link Sphere}
|
|
12
|
-
*
|
|
13
|
-
* @param shape
|
|
14
|
-
*/
|
|
15
|
-
export const volume = defmulti(__dispatch, {}, {
|
|
4
|
+
const volume = defmulti(
|
|
5
|
+
__dispatch,
|
|
6
|
+
{},
|
|
7
|
+
{
|
|
16
8
|
[DEFAULT]: () => 0,
|
|
17
9
|
aabb: ({ size }) => size[0] * size[1] * size[2],
|
|
18
|
-
sphere: ($) =>
|
|
19
|
-
}
|
|
10
|
+
sphere: ($) => 4 / 3 * PI * $.r ** 3
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
export {
|
|
14
|
+
volume
|
|
15
|
+
};
|
package/warp-points.js
CHANGED
|
@@ -2,30 +2,20 @@ import { bounds2 } from "@thi.ng/geom-poly-utils/bounds";
|
|
|
2
2
|
import { mapPoint } from "./map-point.js";
|
|
3
3
|
import { rectFromMinMax } from "./rect.js";
|
|
4
4
|
import { unmapPoint } from "./unmap-point.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @remarks
|
|
11
|
-
* The type of `src` must be supported by {@link mapPoint}. The type of `dest`
|
|
12
|
-
* must be supported by {@link unmapPoint}.
|
|
13
|
-
*
|
|
14
|
-
* @param pts
|
|
15
|
-
* @param dest
|
|
16
|
-
* @param src
|
|
17
|
-
* @param out
|
|
18
|
-
*/
|
|
19
|
-
export const warpPoints = (pts, dest, src, out = []) => {
|
|
20
|
-
for (let n = pts.length, i = 0; i < n; i++) {
|
|
21
|
-
out.push(unmapPoint(dest, mapPoint(src, pts[i])));
|
|
22
|
-
}
|
|
23
|
-
return out;
|
|
5
|
+
const warpPoints = (pts, dest, src, out = []) => {
|
|
6
|
+
for (let n = pts.length, i = 0; i < n; i++) {
|
|
7
|
+
out.push(unmapPoint(dest, mapPoint(src, pts[i])));
|
|
8
|
+
}
|
|
9
|
+
return out;
|
|
24
10
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
const warpPointsBPatch = (pts, dest, src, out = []) => {
|
|
12
|
+
src = src || rectFromMinMax(...bounds2(pts));
|
|
13
|
+
for (let i = pts.length; i-- > 0; ) {
|
|
14
|
+
out[i] = dest.unmapPoint(mapPoint(src, pts[i]));
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
warpPoints,
|
|
20
|
+
warpPointsBPatch
|
|
31
21
|
};
|
package/with-attribs.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* (if any).
|
|
6
|
-
*
|
|
7
|
-
* @param shape
|
|
8
|
-
* @param attribs
|
|
9
|
-
* @param replace
|
|
10
|
-
*/
|
|
11
|
-
export const withAttribs = (shape, attribs, replace = true) => shape.withAttribs(replace ? attribs : { ...shape.attribs, ...attribs });
|
|
1
|
+
const withAttribs = (shape, attribs, replace = true) => shape.withAttribs(replace ? attribs : { ...shape.attribs, ...attribs });
|
|
2
|
+
export {
|
|
3
|
+
withAttribs
|
|
4
|
+
};
|