@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.
Files changed (104) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/aabb.js +31 -32
  4. package/api/aabb.js +34 -29
  5. package/api/apc.js +15 -13
  6. package/api/arc.js +82 -66
  7. package/api/bpatch.js +79 -96
  8. package/api/circle.js +21 -21
  9. package/api/cubic.js +28 -25
  10. package/api/ellipse.js +26 -21
  11. package/api/group.js +45 -47
  12. package/api/line.js +26 -27
  13. package/api/path.js +62 -58
  14. package/api/plane.js +21 -21
  15. package/api/points.js +30 -26
  16. package/api/polygon.js +19 -16
  17. package/api/polyline.js +25 -22
  18. package/api/quad.js +20 -17
  19. package/api/quad3.js +20 -17
  20. package/api/quadratic.js +28 -25
  21. package/api/ray.js +30 -26
  22. package/api/rect.js +34 -29
  23. package/api/sphere.js +21 -21
  24. package/api/text.js +21 -28
  25. package/api/triangle.js +20 -17
  26. package/apply-transforms.js +28 -48
  27. package/arc-length.js +17 -30
  28. package/arc.js +17 -6
  29. package/area.js +19 -45
  30. package/as-cubic.js +38 -57
  31. package/as-path.js +4 -8
  32. package/as-polygon.js +12 -29
  33. package/as-polyline.js +18 -38
  34. package/as-svg.js +32 -63
  35. package/bounds.js +46 -48
  36. package/bpatch.js +22 -14
  37. package/center.js +22 -17
  38. package/centroid.js +14 -34
  39. package/circle.js +11 -6
  40. package/classify-point.js +20 -27
  41. package/clip-convex.js +40 -39
  42. package/closest-point.js +28 -34
  43. package/convex-hull.js +12 -27
  44. package/cubic.js +13 -5
  45. package/edges.js +31 -60
  46. package/ellipse.js +5 -2
  47. package/fit-into-bounds.js +78 -61
  48. package/flip.js +24 -41
  49. package/group.js +4 -1
  50. package/internal/args.js +18 -51
  51. package/internal/bounds.js +23 -38
  52. package/internal/collate.js +33 -17
  53. package/internal/copy.js +12 -23
  54. package/internal/dispatch.js +6 -4
  55. package/internal/edges.js +4 -1
  56. package/internal/pclike.js +8 -4
  57. package/internal/points-as-shape.js +4 -3
  58. package/internal/rotate.js +6 -2
  59. package/internal/scale.js +8 -2
  60. package/internal/split.js +9 -6
  61. package/internal/transform.js +24 -12
  62. package/internal/translate.js +6 -2
  63. package/internal/vertices.js +15 -31
  64. package/intersects.js +15 -39
  65. package/line.js +11 -9
  66. package/map-point.js +10 -18
  67. package/offset.js +31 -29
  68. package/package.json +33 -31
  69. package/path-builder.js +152 -143
  70. package/path-from-svg.js +129 -131
  71. package/path.js +28 -25
  72. package/plane.js +10 -5
  73. package/point-at.js +12 -30
  74. package/point-inside.js +20 -25
  75. package/points.js +6 -2
  76. package/polygon.js +15 -47
  77. package/polyline.js +18 -22
  78. package/quad.js +23 -15
  79. package/quadratic.js +7 -3
  80. package/ray.js +4 -1
  81. package/rect.js +47 -46
  82. package/resample.js +12 -27
  83. package/rotate.js +30 -42
  84. package/scale.js +66 -64
  85. package/scatter.js +18 -30
  86. package/simplify.js +38 -55
  87. package/sphere.js +7 -3
  88. package/split-arclength.js +53 -108
  89. package/split-at.js +46 -26
  90. package/split-near.js +28 -22
  91. package/subdiv-curve.js +33 -72
  92. package/tangent-at.js +12 -24
  93. package/tessellate.js +22 -47
  94. package/text.js +4 -1
  95. package/transform-vertices.js +31 -55
  96. package/transform.js +31 -54
  97. package/translate.js +39 -46
  98. package/triangle.js +7 -3
  99. package/union.js +12 -15
  100. package/unmap-point.js +21 -25
  101. package/vertices.js +91 -113
  102. package/volume.js +10 -14
  103. package/warp-points.js +15 -25
  104. 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 { __transformedShape as tx, __transformedShape3 as tx3, } from "./internal/transform.js";
17
+ import {
18
+ __transformedShape as tx,
19
+ __transformedShape3 as tx3
20
+ } from "./internal/transform.js";
18
21
  import { vertices } from "./vertices.js";
19
- /**
20
- * Transforms given shape with provided matrix.
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
- ...map((s) => s.type === "m"
66
- ? {
67
- type: s.type,
68
- point: mulV([], mat, s.point),
69
- }
70
- : {
71
- type: s.type,
72
- geo: transform(s.geo, mat),
73
- }, $.segments),
74
- ], __copyAttribs($)),
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
- * Translates given shape by given `offset` vector.
25
- *
26
- * @remarks
27
- * Currently implemented for:
28
- *
29
- * - {@link AABB}
30
- * - {@link Arc}
31
- * - {@link Circle}
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
- const a = $.copy();
56
- add2(null, a.pos, delta);
57
- return a;
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(add2([], $.pos, delta), set2([], $.r), __copyAttribs($)),
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($.segments.map((s) => s.geo
65
- ? {
66
- type: s.type,
67
- geo: translate(s.geo, delta),
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
- type: s.type,
71
- point: add2([], s.point, delta),
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(add2([], $.pos, delta), set2([], $.size), __copyAttribs($)),
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
- export function triangle(...args) {
5
- return __pclike(Triangle, args);
4
+ function triangle(...args) {
5
+ return __pclike(Triangle, args);
6
6
  }
7
- export const equilateralTriangle = (a, b, attribs) => new Triangle(equilateralTriangle2(a, b), attribs);
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
- * Computes shape "union" of given 2 shapes.
8
- *
9
- * @remarks
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
- new AABB(...__unionBounds(a.pos, a.size, b.pos, b.size)),
11
+ new AABB(...__unionBounds(a.pos, a.size, b.pos, b.size))
19
12
  ],
20
13
  rect: (a, b) => [
21
- new Rect(...__unionBounds(a.pos, a.size, b.pos, b.size)),
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
- * Projects given point `uv` (normalized coords) into the target space defined
7
- * by `shape` and writes result to `out` (or returns new vector).
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
- quad: ({ points }, uv, out = []) => mixBilinear(out, points[0], points[1], points[3], points[2], uv[0], uv[1]),
29
- rect: ($, uvw, out = []) => madd(out, $.size, uvw, $.pos),
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
- * Extracts/samples vertices from given shape's boundary and returns them as
20
- * array. Some shapes also support
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
- const [px, py, pz] = pos;
81
- const [qx, qy, qz] = add3([], pos, size);
82
- return [
83
- [px, py, pz], // a
84
- [px, py, qz], // b
85
- [qx, py, qz], // c
86
- [qx, py, pz], // d
87
- [px, qy, pz], // e
88
- [px, qy, qz], // f
89
- [qx, qy, qz], // g
90
- [qx, qy, pz], // h
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($.pos, $.r, $.axis, $.start, $.end, __sampleAttribs(opts, $.attribs)),
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
- opts = __sampleAttribs(opts, $.attribs);
96
- const pos = $.pos;
97
- const r = $.r;
98
- let [num, start, last] = __circleOpts(opts, r);
99
- const delta = TAU / num;
100
- last && num++;
101
- const buf = new Array(num);
102
- for (let i = 0; i < num; i++) {
103
- buf[i] = cartesian2(null, [r, start + i * delta], pos);
104
- }
105
- return buf;
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
- opts = __sampleAttribs(opts, $.attribs);
110
- const buf = [];
111
- const pos = $.pos;
112
- const r = $.r;
113
- let [num, start, last] = __circleOpts(opts, Math.max($.r[0], $.r[1]));
114
- const delta = TAU / num;
115
- last && num++;
116
- for (let i = 0; i < num; i++) {
117
- buf[i] = madd2([], cossin(start + i * delta), r, pos);
118
- }
119
- return buf;
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
- opts = __sampleAttribs(opts, $.attribs);
123
- return $.children.reduce((acc, $) => acc.concat(vertices($, opts)), []);
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
- opts = __sampleAttribs(opts, $.attribs);
127
- const _opts = isNumber(opts) ? { num: opts } : opts;
128
- let verts = [];
129
- for (let segs = $.segments, n = segs.length - 1, i = 0; i <= n; i++) {
130
- const s = segs[i];
131
- if (s.geo) {
132
- verts = verts.concat(vertices(s.geo, {
133
- ..._opts,
134
- last: i === n && !$.closed,
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
- return verts;
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
- opts = __sampleAttribs(opts, $.attribs);
146
- const p = $.pos;
147
- const q = add2([], p, $.size);
148
- const verts = [set2([], p), [q[0], p[1]], q, [p[0], q[1]]];
149
- return opts != null ? vertices(new Polygon(verts), opts) : verts;
150
- },
151
- });
152
- /**
153
- * Takes an array of vertices or an `IShape`. If the latter, calls
154
- * {@link vertices} with default options and returns result, else returns
155
- * original array.
156
- *
157
- * @param shape -
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
- * Returns the volume of given 3D shape. Returns 0 for all others.
6
- *
7
- * @remarks
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: ($) => (4 / 3) * PI * $.r ** 3,
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
- * Transfers/remaps points (in world space) given in relation to `src` shape to
7
- * be relative to the space of `dest` shape. Writes results to `out` (or creates
8
- * new array).
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
- export const warpPointsBPatch = (pts, dest, src, out = []) => {
26
- src = src || rectFromMinMax(...bounds2(pts));
27
- for (let i = pts.length; i-- > 0;) {
28
- out[i] = dest.unmapPoint(mapPoint(src, pts[i]));
29
- }
30
- return out;
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
- * Returns a shallow copy of given shape with new `attribs` assigned (using
3
- * [`IAttributed`](https://docs.thi.ng/umbrella/geom-api/interfaces/IAttributed.html).withAttribs}).
4
- * If `replace` is false, the new attribs will be merged with the existing ones
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
+ };