@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.
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 -30
  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/api/ellipse.js CHANGED
@@ -1,25 +1,30 @@
1
1
  import { set } from "@thi.ng/vectors/set";
2
2
  import { __asVec } from "../internal/args.js";
3
3
  import { __copyAttribs } from "../internal/copy.js";
4
- export class Ellipse {
5
- pos;
6
- attribs;
7
- r;
8
- constructor(pos = [0, 0], r = [1, 1], attribs) {
9
- this.pos = pos;
10
- this.attribs = attribs;
11
- this.r = __asVec(r);
12
- }
13
- get type() {
14
- return "ellipse";
15
- }
16
- copy() {
17
- return new Ellipse(set([], this.pos), set([], this.r), __copyAttribs(this));
18
- }
19
- withAttribs(attribs) {
20
- return new Ellipse(this.pos, this.r, attribs);
21
- }
22
- toHiccup() {
23
- return ["ellipse", this.attribs, this.pos, this.r];
24
- }
4
+ class Ellipse {
5
+ constructor(pos = [0, 0], r = [1, 1], attribs) {
6
+ this.pos = pos;
7
+ this.attribs = attribs;
8
+ this.r = __asVec(r);
9
+ }
10
+ r;
11
+ get type() {
12
+ return "ellipse";
13
+ }
14
+ copy() {
15
+ return new Ellipse(
16
+ set([], this.pos),
17
+ set([], this.r),
18
+ __copyAttribs(this)
19
+ );
20
+ }
21
+ withAttribs(attribs) {
22
+ return new Ellipse(this.pos, this.r, attribs);
23
+ }
24
+ toHiccup() {
25
+ return ["ellipse", this.attribs, this.pos, this.r];
26
+ }
25
27
  }
28
+ export {
29
+ Ellipse
30
+ };
package/api/group.js CHANGED
@@ -1,51 +1,49 @@
1
1
  import { ensureArray } from "@thi.ng/arrays/ensure-array";
2
2
  import { equiv } from "@thi.ng/equiv";
3
3
  import { __copyAttribs } from "../internal/copy.js";
4
- /**
5
- * Geometry/shape group container for other {@link IHiccupShape}s, incl. nested
6
- * groups.
7
- */
8
- export class Group {
9
- attribs;
10
- children;
11
- constructor(attribs, children) {
12
- this.attribs = attribs;
13
- this.children = children ? ensureArray(children) : [];
14
- }
15
- get type() {
16
- return "group";
17
- }
18
- *[Symbol.iterator]() {
19
- yield* this.children;
20
- }
21
- /**
22
- * Appends given `shapes` to this {@link Group.children} array.
23
- *
24
- * @param shapes
25
- */
26
- add(...shapes) {
27
- this.children.push(...shapes);
28
- return this;
29
- }
30
- /**
31
- * Removes all children from the group.
32
- */
33
- clear() {
34
- this.children.length = 0;
35
- }
36
- copy() {
37
- return this.copyTransformed((c) => c.copy());
38
- }
39
- copyTransformed(fn) {
40
- return new Group(__copyAttribs(this), this.children.map(fn));
41
- }
42
- withAttribs(attribs) {
43
- return new Group(attribs, this.children);
44
- }
45
- equiv(o) {
46
- return o instanceof Group && equiv(this.children, o.children);
47
- }
48
- toHiccup() {
49
- return ["g", this.attribs, ...this.children.map((x) => x.toHiccup())];
50
- }
4
+ class Group {
5
+ constructor(attribs, children) {
6
+ this.attribs = attribs;
7
+ this.children = children ? ensureArray(children) : [];
8
+ }
9
+ children;
10
+ get type() {
11
+ return "group";
12
+ }
13
+ *[Symbol.iterator]() {
14
+ yield* this.children;
15
+ }
16
+ /**
17
+ * Appends given `shapes` to this {@link Group.children} array.
18
+ *
19
+ * @param shapes
20
+ */
21
+ add(...shapes) {
22
+ this.children.push(...shapes);
23
+ return this;
24
+ }
25
+ /**
26
+ * Removes all children from the group.
27
+ */
28
+ clear() {
29
+ this.children.length = 0;
30
+ }
31
+ copy() {
32
+ return this.copyTransformed((c) => c.copy());
33
+ }
34
+ copyTransformed(fn) {
35
+ return new Group(__copyAttribs(this), this.children.map(fn));
36
+ }
37
+ withAttribs(attribs) {
38
+ return new Group(attribs, this.children);
39
+ }
40
+ equiv(o) {
41
+ return o instanceof Group && equiv(this.children, o.children);
42
+ }
43
+ toHiccup() {
44
+ return ["g", this.attribs, ...this.children.map((x) => x.toHiccup())];
45
+ }
51
46
  }
47
+ export {
48
+ Group
49
+ };
package/api/line.js CHANGED
@@ -1,31 +1,30 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
- export class Line extends APC {
5
- constructor(points, attribs) {
6
- super(points, attribs);
7
- __ensureNumVerts(this.points.length, 2);
8
- }
9
- get type() {
10
- return "line";
11
- }
12
- copy() {
13
- return __copyShape(Line, this);
14
- }
15
- withAttribs(attribs) {
16
- return new Line(this.points, attribs);
17
- }
18
- toHiccup() {
19
- return ["line", this.attribs, this.points[0], this.points[1]];
20
- }
21
- toHiccupPathSegments() {
22
- const [a, b] = this.points;
23
- return [
24
- a[0] === b[0]
25
- ? ["V", b[1]]
26
- : a[1] === b[1]
27
- ? ["H", b[0]]
28
- : ["L", b],
29
- ];
30
- }
4
+ class Line extends APC {
5
+ constructor(points, attribs) {
6
+ super(points, attribs);
7
+ __ensureNumVerts(this.points.length, 2);
8
+ }
9
+ get type() {
10
+ return "line";
11
+ }
12
+ copy() {
13
+ return __copyShape(Line, this);
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Line(this.points, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["line", this.attribs, this.points[0], this.points[1]];
20
+ }
21
+ toHiccupPathSegments() {
22
+ const [a, b] = this.points;
23
+ return [
24
+ a[0] === b[0] ? ["V", b[1]] : a[1] === b[1] ? ["H", b[0]] : ["L", b]
25
+ ];
26
+ }
31
27
  }
28
+ export {
29
+ Line
30
+ };
package/api/path.js CHANGED
@@ -3,64 +3,68 @@ import { equiv } from "@thi.ng/equiv";
3
3
  import { illegalState } from "@thi.ng/errors/illegal-state";
4
4
  import { copy } from "@thi.ng/vectors/copy";
5
5
  import { __copyAttribs } from "../internal/copy.js";
6
- export class Path {
7
- attribs;
8
- segments;
9
- closed = false;
10
- constructor(segments, attribs) {
11
- this.attribs = attribs;
12
- this.segments = segments ? ensureArray(segments) : [];
13
- }
14
- get type() {
15
- return "path";
16
- }
17
- *[Symbol.iterator]() {
18
- yield* this.segments;
19
- }
20
- clear() {
21
- this.segments.length = 0;
22
- }
23
- copy() {
24
- const p = new Path(this.segments.map((s) => {
25
- const d = { type: s.type };
26
- s.point && (d.point = copy(s.point));
27
- s.geo && (d.geo = s.geo.copy());
28
- return d;
29
- }), __copyAttribs(this));
30
- p.closed = this.closed;
31
- return p;
32
- }
33
- withAttribs(attribs) {
34
- const res = new Path(this.segments, attribs);
35
- res.closed = this.closed;
36
- return res;
37
- }
38
- equiv(o) {
39
- return o instanceof Path && equiv(this.segments, o.segments);
40
- }
41
- add(...segments) {
42
- if (this.closed)
43
- illegalState("path already closed");
44
- this.segments.push(...segments);
45
- }
46
- toHiccup() {
47
- let dest = [];
48
- const segments = this.segments;
49
- const n = segments.length;
50
- if (n > 1) {
51
- for (let i = 0; i < n; i++) {
52
- const s = segments[i];
53
- if (s.geo) {
54
- dest = dest.concat(s.geo.toHiccupPathSegments());
55
- }
56
- else if (s.point) {
57
- dest.push(["M", s.point]);
58
- }
59
- }
60
- if (this.closed) {
61
- dest.push(["Z"]);
62
- }
6
+ class Path {
7
+ constructor(segments, attribs) {
8
+ this.attribs = attribs;
9
+ this.segments = segments ? ensureArray(segments) : [];
10
+ }
11
+ segments;
12
+ closed = false;
13
+ get type() {
14
+ return "path";
15
+ }
16
+ *[Symbol.iterator]() {
17
+ yield* this.segments;
18
+ }
19
+ clear() {
20
+ this.segments.length = 0;
21
+ }
22
+ copy() {
23
+ const p = new Path(
24
+ this.segments.map((s) => {
25
+ const d = { type: s.type };
26
+ s.point && (d.point = copy(s.point));
27
+ s.geo && (d.geo = s.geo.copy());
28
+ return d;
29
+ }),
30
+ __copyAttribs(this)
31
+ );
32
+ p.closed = this.closed;
33
+ return p;
34
+ }
35
+ withAttribs(attribs) {
36
+ const res = new Path(this.segments, attribs);
37
+ res.closed = this.closed;
38
+ return res;
39
+ }
40
+ equiv(o) {
41
+ return o instanceof Path && equiv(this.segments, o.segments);
42
+ }
43
+ add(...segments) {
44
+ if (this.closed)
45
+ illegalState("path already closed");
46
+ this.segments.push(...segments);
47
+ }
48
+ toHiccup() {
49
+ let dest = [];
50
+ const segments = this.segments;
51
+ const n = segments.length;
52
+ if (n > 1) {
53
+ for (let i = 0; i < n; i++) {
54
+ const s = segments[i];
55
+ if (s.geo) {
56
+ dest = dest.concat(s.geo.toHiccupPathSegments());
57
+ } else if (s.point) {
58
+ dest.push(["M", s.point]);
63
59
  }
64
- return ["path", this.attribs || {}, dest];
60
+ }
61
+ if (this.closed) {
62
+ dest.push(["Z"]);
63
+ }
65
64
  }
65
+ return ["path", this.attribs || {}, dest];
66
+ }
66
67
  }
68
+ export {
69
+ Path
70
+ };
package/api/plane.js CHANGED
@@ -1,24 +1,24 @@
1
1
  import { set3 } from "@thi.ng/vectors/set";
2
2
  import { __copyAttribs } from "../internal/copy.js";
3
- export class Plane {
4
- normal;
5
- w;
6
- attribs;
7
- constructor(normal = [0, 1, 0], w = 0, attribs) {
8
- this.normal = normal;
9
- this.w = w;
10
- this.attribs = attribs;
11
- }
12
- get type() {
13
- return "plane";
14
- }
15
- copy() {
16
- return new Plane(set3([], this.normal), this.w, __copyAttribs(this));
17
- }
18
- withAttribs(attribs) {
19
- return new Plane(this.normal, this.w, attribs);
20
- }
21
- toHiccup() {
22
- return ["plane", this.attribs, this.normal, this.w];
23
- }
3
+ class Plane {
4
+ constructor(normal = [0, 1, 0], w = 0, attribs) {
5
+ this.normal = normal;
6
+ this.w = w;
7
+ this.attribs = attribs;
8
+ }
9
+ get type() {
10
+ return "plane";
11
+ }
12
+ copy() {
13
+ return new Plane(set3([], this.normal), this.w, __copyAttribs(this));
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Plane(this.normal, this.w, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["plane", this.attribs, this.normal, this.w];
20
+ }
24
21
  }
22
+ export {
23
+ Plane
24
+ };
package/api/points.js CHANGED
@@ -1,30 +1,34 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { APC } from "./apc.js";
3
- export class Points extends APC {
4
- get type() {
5
- return "points";
6
- }
7
- copy() {
8
- return __copyShape(Points, this);
9
- }
10
- withAttribs(attribs) {
11
- return new Points(this.points, attribs);
12
- }
13
- toHiccup() {
14
- return ["points", this.attribs, this.points];
15
- }
3
+ class Points extends APC {
4
+ get type() {
5
+ return "points";
6
+ }
7
+ copy() {
8
+ return __copyShape(Points, this);
9
+ }
10
+ withAttribs(attribs) {
11
+ return new Points(this.points, attribs);
12
+ }
13
+ toHiccup() {
14
+ return ["points", this.attribs, this.points];
15
+ }
16
16
  }
17
- export class Points3 extends APC {
18
- get type() {
19
- return "points3";
20
- }
21
- copy() {
22
- return __copyShape(Points3, this);
23
- }
24
- withAttribs(attribs) {
25
- return new Points3(this.points, attribs);
26
- }
27
- toHiccup() {
28
- return ["points3", this.attribs, this.points];
29
- }
17
+ class Points3 extends APC {
18
+ get type() {
19
+ return "points3";
20
+ }
21
+ copy() {
22
+ return __copyShape(Points3, this);
23
+ }
24
+ withAttribs(attribs) {
25
+ return new Points3(this.points, attribs);
26
+ }
27
+ toHiccup() {
28
+ return ["points3", this.attribs, this.points];
29
+ }
30
30
  }
31
+ export {
32
+ Points,
33
+ Points3
34
+ };
package/api/polygon.js CHANGED
@@ -1,19 +1,22 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { APC } from "./apc.js";
3
- export class Polygon extends APC {
4
- get type() {
5
- return "poly";
6
- }
7
- add(...points) {
8
- this.points.push(...points);
9
- }
10
- copy() {
11
- return __copyShape(Polygon, this);
12
- }
13
- withAttribs(attribs) {
14
- return new Polygon(this.points, attribs);
15
- }
16
- toHiccup() {
17
- return ["polygon", this.attribs, this.points];
18
- }
3
+ class Polygon extends APC {
4
+ get type() {
5
+ return "poly";
6
+ }
7
+ add(...points) {
8
+ this.points.push(...points);
9
+ }
10
+ copy() {
11
+ return __copyShape(Polygon, this);
12
+ }
13
+ withAttribs(attribs) {
14
+ return new Polygon(this.points, attribs);
15
+ }
16
+ toHiccup() {
17
+ return ["polygon", this.attribs, this.points];
18
+ }
19
19
  }
20
+ export {
21
+ Polygon
22
+ };
package/api/polyline.js CHANGED
@@ -1,26 +1,29 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { APC } from "./apc.js";
3
- export class Polyline extends APC {
4
- get type() {
5
- return "polyline";
6
- }
7
- add(...points) {
8
- this.points.push(...points);
9
- }
10
- copy() {
11
- return __copyShape(Polyline, this);
12
- }
13
- withAttribs(attribs) {
14
- return new Polyline(this.points, attribs);
15
- }
16
- toHiccup() {
17
- return ["polyline", { ...this.attribs, fill: "none" }, this.points];
18
- }
19
- toHiccupPathSegments() {
20
- const res = [];
21
- for (let pts = this.points, n = pts.length, i = 1; i < n; i++) {
22
- res.push(["L", pts[i]]);
23
- }
24
- return res;
3
+ class Polyline extends APC {
4
+ get type() {
5
+ return "polyline";
6
+ }
7
+ add(...points) {
8
+ this.points.push(...points);
9
+ }
10
+ copy() {
11
+ return __copyShape(Polyline, this);
12
+ }
13
+ withAttribs(attribs) {
14
+ return new Polyline(this.points, attribs);
15
+ }
16
+ toHiccup() {
17
+ return ["polyline", { ...this.attribs, fill: "none" }, this.points];
18
+ }
19
+ toHiccupPathSegments() {
20
+ const res = [];
21
+ for (let pts = this.points, n = pts.length, i = 1; i < n; i++) {
22
+ res.push(["L", pts[i]]);
25
23
  }
24
+ return res;
25
+ }
26
26
  }
27
+ export {
28
+ Polyline
29
+ };
package/api/quad.js CHANGED
@@ -1,21 +1,24 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
- export class Quad extends APC {
5
- constructor(points, attribs) {
6
- super(points, attribs);
7
- __ensureNumVerts(this.points.length, 4);
8
- }
9
- get type() {
10
- return "quad";
11
- }
12
- copy() {
13
- return __copyShape(Quad, this);
14
- }
15
- withAttribs(attribs) {
16
- return new Quad(this.points, attribs);
17
- }
18
- toHiccup() {
19
- return ["polygon", this.attribs, this.points];
20
- }
4
+ class Quad extends APC {
5
+ constructor(points, attribs) {
6
+ super(points, attribs);
7
+ __ensureNumVerts(this.points.length, 4);
8
+ }
9
+ get type() {
10
+ return "quad";
11
+ }
12
+ copy() {
13
+ return __copyShape(Quad, this);
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Quad(this.points, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["polygon", this.attribs, this.points];
20
+ }
21
21
  }
22
+ export {
23
+ Quad
24
+ };
package/api/quad3.js CHANGED
@@ -1,21 +1,24 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
- export class Quad3 extends APC {
5
- constructor(points, attribs) {
6
- super(points, attribs);
7
- __ensureNumVerts(this.points.length, 4);
8
- }
9
- get type() {
10
- return "quad3";
11
- }
12
- copy() {
13
- return __copyShape(Quad3, this);
14
- }
15
- withAttribs(attribs) {
16
- return new Quad3(this.points, attribs);
17
- }
18
- toHiccup() {
19
- return ["polygon", this.attribs, this.points];
20
- }
4
+ class Quad3 extends APC {
5
+ constructor(points, attribs) {
6
+ super(points, attribs);
7
+ __ensureNumVerts(this.points.length, 4);
8
+ }
9
+ get type() {
10
+ return "quad3";
11
+ }
12
+ copy() {
13
+ return __copyShape(Quad3, this);
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Quad3(this.points, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["polygon", this.attribs, this.points];
20
+ }
21
21
  }
22
+ export {
23
+ Quad3
24
+ };