@thi.ng/geom 7.0.1 → 8.0.0

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 (251) hide show
  1. package/CHANGELOG.md +190 -1
  2. package/README.md +349 -112
  3. package/aabb.d.ts +26 -1
  4. package/api/aabb.d.ts +5 -4
  5. package/api/aabb.js +10 -7
  6. package/api/apc.d.ts +5 -3
  7. package/api/arc.d.ts +6 -5
  8. package/api/arc.js +3 -4
  9. package/api/bpatch.d.ts +6 -3
  10. package/api/bpatch.js +5 -3
  11. package/api/circle.d.ts +4 -3
  12. package/api/circle.js +9 -6
  13. package/api/complex-polygon.d.ts +7 -3
  14. package/api/complex-polygon.js +14 -4
  15. package/api/cubic.d.ts +8 -5
  16. package/api/cubic.js +12 -6
  17. package/api/cubic3.d.ts +15 -0
  18. package/api/cubic3.js +38 -0
  19. package/api/ellipse.d.ts +4 -3
  20. package/api/ellipse.js +7 -8
  21. package/api/extra.d.ts +15 -0
  22. package/api/extra.js +19 -0
  23. package/api/group.d.ts +12 -11
  24. package/api/group.js +4 -5
  25. package/api/group3.d.ts +30 -0
  26. package/api/group3.js +48 -0
  27. package/api/line.d.ts +8 -5
  28. package/api/line.js +8 -8
  29. package/api/line3.d.ts +15 -0
  30. package/api/line3.js +29 -0
  31. package/api/path.d.ts +14 -11
  32. package/api/path.js +17 -12
  33. package/api/path3.d.ts +28 -0
  34. package/api/path3.js +91 -0
  35. package/api/plane.d.ts +4 -3
  36. package/api/plane.js +7 -4
  37. package/api/points.d.ts +8 -10
  38. package/api/points.js +7 -20
  39. package/api/points3.d.ts +13 -0
  40. package/api/points3.js +21 -0
  41. package/api/polygon.d.ts +7 -4
  42. package/api/polygon.js +5 -3
  43. package/api/polygon3.d.ts +14 -0
  44. package/api/polygon3.js +24 -0
  45. package/api/polyline.d.ts +18 -4
  46. package/api/polyline.js +8 -5
  47. package/api/polyline3.d.ts +28 -0
  48. package/api/polyline3.js +31 -0
  49. package/api/quad.d.ts +7 -4
  50. package/api/quad.js +5 -3
  51. package/api/quad3.d.ts +7 -4
  52. package/api/quad3.js +6 -4
  53. package/api/quadratic.d.ts +8 -5
  54. package/api/quadratic.js +12 -6
  55. package/api/quadratic3.d.ts +15 -0
  56. package/api/quadratic3.js +38 -0
  57. package/api/ray.d.ts +4 -3
  58. package/api/ray.js +6 -7
  59. package/api/ray3.d.ts +14 -0
  60. package/api/ray3.js +33 -0
  61. package/api/rect.d.ts +5 -3
  62. package/api/rect.js +11 -8
  63. package/api/sphere.d.ts +4 -3
  64. package/api/sphere.js +8 -5
  65. package/api/text.d.ts +4 -3
  66. package/api/text.js +8 -5
  67. package/api/triangle.d.ts +7 -4
  68. package/api/triangle.js +5 -3
  69. package/api/triangle3.d.ts +14 -0
  70. package/api/triangle3.js +26 -0
  71. package/api.d.ts +193 -0
  72. package/api.js +10 -0
  73. package/apply-transforms.d.ts +33 -11
  74. package/apply-transforms.js +24 -4
  75. package/arc-length.d.ts +18 -4
  76. package/arc-length.js +18 -3
  77. package/arc.d.ts +1 -1
  78. package/area.d.ts +6 -10
  79. package/area.js +3 -3
  80. package/as-cubic.d.ts +31 -5
  81. package/as-cubic.js +86 -24
  82. package/as-path.d.ts +14 -7
  83. package/as-path.js +49 -24
  84. package/as-polygon.d.ts +20 -5
  85. package/as-polygon.js +46 -12
  86. package/as-polyline.d.ts +18 -5
  87. package/as-polyline.js +29 -23
  88. package/as-sector.d.ts +13 -0
  89. package/as-sector.js +18 -0
  90. package/as-svg.d.ts +31 -9
  91. package/as-svg.js +21 -18
  92. package/bounds.d.ts +12 -2
  93. package/bounds.js +15 -0
  94. package/bpatch.d.ts +26 -1
  95. package/center-of-weight.d.ts +22 -0
  96. package/center-of-weight.js +23 -0
  97. package/center.d.ts +11 -5
  98. package/center.js +9 -4
  99. package/centroid-of-bounds.d.ts +12 -0
  100. package/centroid-of-bounds.js +9 -0
  101. package/centroid.d.ts +14 -4
  102. package/centroid.js +16 -17
  103. package/circle.d.ts +1 -1
  104. package/classify-point.d.ts +3 -1
  105. package/classify-point.js +7 -4
  106. package/clip-convex.d.ts +27 -8
  107. package/clip-convex.js +52 -17
  108. package/closest-point.d.ts +1 -1
  109. package/complex-polygon-from-path.d.ts +1 -1
  110. package/complex-polygon.d.ts +1 -1
  111. package/convex-hull.d.ts +9 -2
  112. package/convex-hull.js +3 -3
  113. package/convolve.d.ts +72 -0
  114. package/convolve.js +33 -0
  115. package/cubic.d.ts +1 -1
  116. package/cubic.js +7 -7
  117. package/cubic3.d.ts +8 -0
  118. package/cubic3.js +14 -0
  119. package/edges.d.ts +2 -2
  120. package/ellipse.d.ts +1 -1
  121. package/extra.d.ts +14 -0
  122. package/extra.js +5 -0
  123. package/fit-into-bounds.d.ts +14 -4
  124. package/fit-into-bounds.js +6 -6
  125. package/flip.d.ts +21 -5
  126. package/flip.js +19 -12
  127. package/from-tessellation.d.ts +54 -0
  128. package/from-tessellation.js +27 -0
  129. package/group.d.ts +2 -2
  130. package/group3.d.ts +16 -0
  131. package/group3.js +5 -0
  132. package/index.d.ts +35 -1
  133. package/index.js +35 -1
  134. package/internal/bounds.d.ts +3 -4
  135. package/internal/copy.d.ts +8 -7
  136. package/internal/copy.js +3 -7
  137. package/internal/dispatch.d.ts +1 -1
  138. package/internal/error.d.ts +3 -0
  139. package/internal/error.js +6 -0
  140. package/internal/pclike.d.ts +3 -2
  141. package/internal/pclike.js +6 -0
  142. package/internal/points-as-shape.d.ts +11 -2
  143. package/internal/points-as-shape.js +10 -1
  144. package/internal/split.d.ts +2 -2
  145. package/internal/split.js +13 -8
  146. package/internal/transform.d.ts +6 -22
  147. package/internal/transform.js +2 -21
  148. package/internal/vertices.d.ts +3 -2
  149. package/internal/vertices.js +3 -1
  150. package/intersects.d.ts +5 -4
  151. package/intersects.js +6 -4
  152. package/line.d.ts +1 -1
  153. package/line3.d.ts +6 -0
  154. package/line3.js +9 -0
  155. package/map-point.d.ts +1 -1
  156. package/normalized-path.d.ts +17 -0
  157. package/normalized-path.js +23 -0
  158. package/offset.d.ts +16 -2
  159. package/offset.js +2 -2
  160. package/package.json +149 -35
  161. package/path-builder.d.ts +42 -13
  162. package/path-builder.js +68 -42
  163. package/path-from-cubics.d.ts +26 -0
  164. package/path-from-cubics.js +39 -0
  165. package/path-from-svg.d.ts +1 -1
  166. package/path-from-svg.js +29 -29
  167. package/path.d.ts +2 -52
  168. package/path.js +1 -58
  169. package/path3.d.ts +16 -0
  170. package/path3.js +5 -0
  171. package/plane.d.ts +11 -1
  172. package/plane.js +3 -0
  173. package/point-at.d.ts +1 -1
  174. package/point-inside.d.ts +3 -1
  175. package/point-inside.js +4 -1
  176. package/points.d.ts +2 -3
  177. package/points.js +2 -4
  178. package/points3.d.ts +5 -0
  179. package/points3.js +5 -0
  180. package/polygon.d.ts +5 -5
  181. package/polygon3.d.ts +5 -0
  182. package/polygon3.js +5 -0
  183. package/polyline.d.ts +2 -2
  184. package/polyline3.d.ts +5 -0
  185. package/polyline3.js +5 -0
  186. package/proximity.d.ts +5 -3
  187. package/proximity.js +2 -2
  188. package/quad.d.ts +2 -7
  189. package/quad.js +1 -29
  190. package/quad3.d.ts +8 -0
  191. package/quad3.js +30 -0
  192. package/quadratic.d.ts +1 -1
  193. package/quadratic3.d.ts +7 -0
  194. package/quadratic3.js +11 -0
  195. package/ray.d.ts +1 -1
  196. package/ray.js +2 -2
  197. package/ray3.d.ts +5 -0
  198. package/ray3.js +6 -0
  199. package/rect.d.ts +1 -1
  200. package/resample.d.ts +45 -4
  201. package/resample.js +26 -16
  202. package/rotate-around-axis.d.ts +33 -0
  203. package/rotate-around-axis.js +57 -0
  204. package/rotate.d.ts +15 -2
  205. package/rotate.js +47 -45
  206. package/rounded-rect.d.ts +25 -0
  207. package/rounded-rect.js +18 -0
  208. package/scale-with-center.d.ts +2 -2
  209. package/scale.d.ts +24 -2
  210. package/scale.js +59 -43
  211. package/scatter.d.ts +1 -1
  212. package/simplify.d.ts +8 -2
  213. package/simplify.js +7 -4
  214. package/smooth-poly.d.ts +27 -0
  215. package/smooth-poly.js +11 -0
  216. package/sphere.d.ts +1 -1
  217. package/split-arclength.d.ts +6 -2
  218. package/split-at.d.ts +18 -2
  219. package/split-at.js +66 -34
  220. package/split-near.d.ts +13 -2
  221. package/split-near.js +23 -27
  222. package/subdiv-curve.d.ts +81 -27
  223. package/subdiv-curve.js +44 -28
  224. package/tangent-at.d.ts +1 -1
  225. package/tessellate.d.ts +72 -18
  226. package/tessellate.js +53 -8
  227. package/text.d.ts +1 -1
  228. package/transform-vertices.d.ts +30 -6
  229. package/transform-vertices.js +36 -38
  230. package/transform.d.ts +30 -2
  231. package/transform.js +54 -40
  232. package/translate.d.ts +12 -2
  233. package/translate.js +42 -43
  234. package/triangle.d.ts +1 -1
  235. package/triangle3.d.ts +6 -0
  236. package/triangle3.js +8 -0
  237. package/union.d.ts +11 -2
  238. package/union.js +6 -7
  239. package/unmap-point.d.ts +1 -1
  240. package/vertices.d.ts +3 -3
  241. package/vertices.js +14 -4
  242. package/volume.d.ts +1 -1
  243. package/warp-points.d.ts +35 -4
  244. package/warp-points.js +2 -0
  245. package/with-attribs.d.ts +4 -5
  246. package/internal/rotate.d.ts +0 -5
  247. package/internal/rotate.js +0 -8
  248. package/internal/scale.d.ts +0 -5
  249. package/internal/scale.js +0 -12
  250. package/internal/translate.d.ts +0 -5
  251. package/internal/translate.js +0 -8
package/api/group3.js ADDED
@@ -0,0 +1,48 @@
1
+ import { ensureArray } from "@thi.ng/arrays/ensure-array";
2
+ import { equiv } from "@thi.ng/equiv";
3
+ import { __copyAttribs } from "../internal/copy.js";
4
+ class Group3 {
5
+ constructor(attribs, children) {
6
+ this.attribs = attribs;
7
+ this.children = children ? ensureArray(children) : [];
8
+ }
9
+ type = "group3";
10
+ dim = 3;
11
+ children;
12
+ *[Symbol.iterator]() {
13
+ yield* this.children;
14
+ }
15
+ /**
16
+ * Appends given `shapes` to this {@link Group.children} array.
17
+ *
18
+ * @param shapes
19
+ */
20
+ add(...shapes) {
21
+ this.children.push(...shapes);
22
+ return this;
23
+ }
24
+ /**
25
+ * Removes all children from the group.
26
+ */
27
+ clear() {
28
+ this.children.length = 0;
29
+ }
30
+ copy() {
31
+ return this.copyTransformed((c) => c.copy());
32
+ }
33
+ copyTransformed(fn) {
34
+ return new Group3(__copyAttribs(this.attribs), this.children.map(fn));
35
+ }
36
+ withAttribs(attribs) {
37
+ return new Group3(attribs, this.children);
38
+ }
39
+ equiv(o) {
40
+ return o instanceof Group3 && equiv(this.attribs, o.attribs) && equiv(this.children, o.children);
41
+ }
42
+ toHiccup() {
43
+ return ["g", this.attribs, ...this.children.map((x) => x.toHiccup())];
44
+ }
45
+ }
46
+ export {
47
+ Group3
48
+ };
package/api/line.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import type { Attribs, IHiccupPathSegment, IHiccupShape } from "@thi.ng/geom-api";
2
- import type { Vec } from "@thi.ng/vectors";
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, IHiccupPathSegment, IHiccupShape2 } from "../api.js";
3
4
  import { APC } from "./apc.js";
4
- export declare class Line extends APC implements IHiccupShape, IHiccupPathSegment {
5
+ export declare class Line extends APC implements IHiccupShape2<Line>, IHiccupPathSegment {
6
+ readonly type = "line";
7
+ readonly dim = 2;
5
8
  constructor(points: Iterable<Vec>, attribs?: Attribs);
6
- get type(): string;
7
9
  copy(): Line;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Line;
8
11
  withAttribs(attribs: Attribs): Line;
9
12
  toHiccup(): (string | Vec | Attribs | undefined)[];
10
- toHiccupPathSegments(): ((string | Vec)[] | (string | number)[])[];
13
+ toHiccupPathSegments(): import("../api.js").HiccupPathSegment[];
11
14
  }
12
15
  //# sourceMappingURL=line.d.ts.map
package/api/line.js CHANGED
@@ -1,28 +1,28 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
+ import { __hiccupLineSegment } from "../internal/vertices.js";
3
4
  import { APC } from "./apc.js";
4
5
  class Line extends APC {
6
+ type = "line";
7
+ dim = 2;
5
8
  constructor(points, attribs) {
6
9
  super(points, attribs);
7
10
  __ensureNumVerts(this.points.length, 2);
8
11
  }
9
- get type() {
10
- return "line";
11
- }
12
12
  copy() {
13
13
  return __copyShape(Line, this);
14
14
  }
15
+ copyTransformed(fn) {
16
+ return __copyShape(Line, this, fn(this.points));
17
+ }
15
18
  withAttribs(attribs) {
16
19
  return new Line(this.points, attribs);
17
20
  }
18
21
  toHiccup() {
19
- return ["line", this.attribs, this.points[0], this.points[1]];
22
+ return [this.type, this.attribs, this.points[0], this.points[1]];
20
23
  }
21
24
  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
- ];
25
+ return [__hiccupLineSegment(this.points[0], this.points[1])];
26
26
  }
27
27
  }
28
28
  export {
package/api/line3.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, HiccupPathSegment, IHiccupPathSegment, IHiccupShape3 } from "../api.js";
4
+ import { APC } from "./apc.js";
5
+ export declare class Line3 extends APC implements IHiccupShape3<Line3>, IHiccupPathSegment {
6
+ readonly type = "line3";
7
+ readonly dim = 3;
8
+ constructor(points: Iterable<Vec>, attribs?: Attribs);
9
+ copy(): Line3;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Line3;
11
+ withAttribs(attribs: Attribs): Line3;
12
+ toHiccup(): (string | Vec | Attribs | undefined)[];
13
+ toHiccupPathSegments(): HiccupPathSegment[];
14
+ }
15
+ //# sourceMappingURL=line3.d.ts.map
package/api/line3.js ADDED
@@ -0,0 +1,29 @@
1
+ import { __copyShape } from "../internal/copy.js";
2
+ import { __ensureNumVerts } from "../internal/pclike.js";
3
+ import { APC } from "./apc.js";
4
+ class Line3 extends APC {
5
+ type = "line3";
6
+ dim = 3;
7
+ constructor(points, attribs) {
8
+ super(points, attribs);
9
+ __ensureNumVerts(this.points.length, 2);
10
+ }
11
+ copy() {
12
+ return __copyShape(Line3, this);
13
+ }
14
+ copyTransformed(fn) {
15
+ return __copyShape(Line3, this, fn(this.points));
16
+ }
17
+ withAttribs(attribs) {
18
+ return new Line3(this.points, attribs);
19
+ }
20
+ toHiccup() {
21
+ return [this.type, this.attribs, this.points[0], this.points[1]];
22
+ }
23
+ toHiccupPathSegments() {
24
+ return [["L", this.points[1]]];
25
+ }
26
+ }
27
+ export {
28
+ Line3
29
+ };
package/api/path.d.ts CHANGED
@@ -1,25 +1,28 @@
1
- import type { IClear } from "@thi.ng/api";
2
- import type { Attribs, IHiccupShape, PathSegment } from "@thi.ng/geom-api";
3
- export declare class Path implements IClear, IHiccupShape {
1
+ import type { Fn, IClear, IEmpty } from "@thi.ng/api";
2
+ import type { Attribs, IHiccupShape2, IPath, PathSegment2 } from "../api.js";
3
+ export declare class Path implements IClear, IEmpty<Path>, IHiccupShape2<Path>, IPath<PathSegment2> {
4
4
  attribs?: Attribs | undefined;
5
- segments: PathSegment[];
6
- subPaths: PathSegment[][];
7
- constructor(segments?: Iterable<PathSegment>, subPaths?: Iterable<PathSegment[]>, attribs?: Attribs | undefined);
8
- get type(): string;
5
+ readonly type = "path";
6
+ readonly dim = 2;
7
+ segments: PathSegment2[];
8
+ subPaths: PathSegment2[][];
9
+ constructor(segments?: Iterable<PathSegment2>, subPaths?: Iterable<PathSegment2[]>, attribs?: Attribs | undefined);
9
10
  /**
10
11
  * Returns true, if the last main segment is a closing segment, e.g. if the
11
12
  * path represents a closed shape.
12
13
  */
13
14
  get closed(): boolean;
14
- [Symbol.iterator](): Generator<PathSegment, void, undefined>;
15
+ [Symbol.iterator](): Generator<PathSegment2, void, undefined>;
15
16
  clear(): void;
17
+ empty(): Path;
16
18
  close(): this;
17
19
  copy(): Path;
20
+ copyTransformed(fn: Fn<PathSegment2[], PathSegment2[]>): Path;
18
21
  withAttribs(attribs: Attribs): Path;
19
22
  equiv(o: any): boolean;
20
- isComplex(): number;
21
- addSegments(...segments: PathSegment[]): this;
22
- addSubPaths(...paths: PathSegment[][]): this;
23
+ isComplex(): boolean;
24
+ addSegments(...segments: PathSegment2[]): this;
25
+ addSubPaths(...paths: PathSegment2[][]): this;
23
26
  toHiccup(): (string | any[] | Attribs)[];
24
27
  }
25
28
  //# sourceMappingURL=path.d.ts.map
package/api/path.js CHANGED
@@ -2,19 +2,18 @@ import { ensureArray } from "@thi.ng/arrays/ensure-array";
2
2
  import { peek } from "@thi.ng/arrays/peek";
3
3
  import { equiv } from "@thi.ng/equiv";
4
4
  import { illegalState } from "@thi.ng/errors/illegal-state";
5
+ import { flatten1 } from "@thi.ng/transducers/flatten1";
5
6
  import { __copyAttribs, __copySegment } from "../internal/copy.js";
6
- const CLOSE = Object.freeze({ type: "z" });
7
7
  class Path {
8
8
  constructor(segments, subPaths, attribs) {
9
9
  this.attribs = attribs;
10
10
  this.segments = segments ? ensureArray(segments) : [];
11
11
  this.subPaths = subPaths ? ensureArray(subPaths) : [];
12
12
  }
13
+ type = "path";
14
+ dim = 2;
13
15
  segments;
14
16
  subPaths;
15
- get type() {
16
- return "path";
17
- }
18
17
  /**
19
18
  * Returns true, if the last main segment is a closing segment, e.g. if the
20
19
  * path represents a closed shape.
@@ -24,30 +23,36 @@ class Path {
24
23
  }
25
24
  *[Symbol.iterator]() {
26
25
  yield* this.segments;
26
+ yield* flatten1(this.subPaths);
27
27
  }
28
28
  clear() {
29
29
  this.segments.length = 0;
30
30
  }
31
+ empty() {
32
+ return new Path();
33
+ }
31
34
  close() {
32
- if (!this.closed) this.segments.push(CLOSE);
35
+ if (!this.closed) this.segments.push({ type: "z" });
33
36
  return this;
34
37
  }
35
38
  copy() {
36
- const p = new Path(
37
- this.segments.map(__copySegment),
38
- this.subPaths.map((sub) => sub.map(__copySegment)),
39
- __copyAttribs(this)
39
+ return this.copyTransformed((segments) => segments.map(__copySegment));
40
+ }
41
+ copyTransformed(fn) {
42
+ return new Path(
43
+ fn(this.segments),
44
+ this.subPaths.map(fn),
45
+ __copyAttribs(this.attribs)
40
46
  );
41
- return p;
42
47
  }
43
48
  withAttribs(attribs) {
44
49
  return new Path(this.segments, this.subPaths, attribs);
45
50
  }
46
51
  equiv(o) {
47
- return o instanceof Path && equiv(this.segments, o.segments);
52
+ return o instanceof Path && equiv(this.segments, o.segments) && equiv(this.subPaths, o.subPaths);
48
53
  }
49
54
  isComplex() {
50
- return this.subPaths.length;
55
+ return !!this.subPaths.length;
51
56
  }
52
57
  addSegments(...segments) {
53
58
  for (let s of segments) {
package/api/path3.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { Fn, IClear, IEmpty } from "@thi.ng/api";
2
+ import type { Attribs, IHiccupShape3, IPath, PathSegment3 } from "../api.js";
3
+ export declare class Path3 implements IClear, IEmpty<Path3>, IHiccupShape3<Path3>, IPath<PathSegment3> {
4
+ attribs?: Attribs | undefined;
5
+ readonly type = "path3";
6
+ readonly dim = 3;
7
+ segments: PathSegment3[];
8
+ subPaths: PathSegment3[][];
9
+ constructor(segments?: Iterable<PathSegment3>, subPaths?: Iterable<PathSegment3[]>, attribs?: Attribs | undefined);
10
+ /**
11
+ * Returns true, if the last main segment is a closing segment, e.g. if the
12
+ * path represents a closed shape.
13
+ */
14
+ get closed(): boolean;
15
+ [Symbol.iterator](): Generator<PathSegment3, void, undefined>;
16
+ clear(): void;
17
+ empty(): Path3;
18
+ close(): this;
19
+ copy(): Path3;
20
+ copyTransformed(fn: Fn<PathSegment3[], PathSegment3[]>): Path3;
21
+ withAttribs(attribs: Attribs): Path3;
22
+ equiv(o: any): boolean;
23
+ isComplex(): boolean;
24
+ addSegments(...segments: PathSegment3[]): this;
25
+ addSubPaths(...paths: PathSegment3[][]): this;
26
+ toHiccup(): (string | any[] | Attribs)[];
27
+ }
28
+ //# sourceMappingURL=path3.d.ts.map
package/api/path3.js ADDED
@@ -0,0 +1,91 @@
1
+ import { ensureArray } from "@thi.ng/arrays/ensure-array";
2
+ import { peek } from "@thi.ng/arrays/peek";
3
+ import { equiv } from "@thi.ng/equiv";
4
+ import { illegalState } from "@thi.ng/errors/illegal-state";
5
+ import { flatten1 } from "@thi.ng/transducers/flatten1";
6
+ import { __copyAttribs, __copySegment } from "../internal/copy.js";
7
+ class Path3 {
8
+ constructor(segments, subPaths, attribs) {
9
+ this.attribs = attribs;
10
+ this.segments = segments ? ensureArray(segments) : [];
11
+ this.subPaths = subPaths ? ensureArray(subPaths) : [];
12
+ }
13
+ type = "path3";
14
+ dim = 3;
15
+ segments;
16
+ subPaths;
17
+ /**
18
+ * Returns true, if the last main segment is a closing segment, e.g. if the
19
+ * path represents a closed shape.
20
+ */
21
+ get closed() {
22
+ return peek(this.segments)?.type === "z";
23
+ }
24
+ *[Symbol.iterator]() {
25
+ yield* this.segments;
26
+ yield* flatten1(this.subPaths);
27
+ }
28
+ clear() {
29
+ this.segments.length = 0;
30
+ }
31
+ empty() {
32
+ return new Path3();
33
+ }
34
+ close() {
35
+ if (!this.closed) this.segments.push({ type: "z" });
36
+ return this;
37
+ }
38
+ copy() {
39
+ return this.copyTransformed((segments) => segments.map(__copySegment));
40
+ }
41
+ copyTransformed(fn) {
42
+ return new Path3(
43
+ fn(this.segments),
44
+ this.subPaths.map(fn),
45
+ __copyAttribs(this.attribs)
46
+ );
47
+ }
48
+ withAttribs(attribs) {
49
+ return new Path3(this.segments, this.subPaths, attribs);
50
+ }
51
+ equiv(o) {
52
+ return o instanceof Path3 && equiv(this.segments, o.segments) && equiv(this.subPaths, o.subPaths);
53
+ }
54
+ isComplex() {
55
+ return !!this.subPaths.length;
56
+ }
57
+ addSegments(...segments) {
58
+ for (let s of segments) {
59
+ this.closed && illegalState("path already closed");
60
+ this.segments.push(s);
61
+ }
62
+ return this;
63
+ }
64
+ addSubPaths(...paths) {
65
+ this.subPaths.push(...paths);
66
+ return this;
67
+ }
68
+ toHiccup() {
69
+ const acc = [];
70
+ const $hiccupSegments = (segments) => {
71
+ for (let i = 0, n = segments.length; i < n; i++) {
72
+ const s = segments[i];
73
+ if (s.geo) {
74
+ acc.push(...s.geo.toHiccupPathSegments());
75
+ } else if (s.point) {
76
+ acc.push(["M", s.point]);
77
+ } else {
78
+ acc.push([s.type]);
79
+ }
80
+ }
81
+ };
82
+ if (this.segments.length > 1) {
83
+ $hiccupSegments(this.segments);
84
+ }
85
+ for (let p of this.subPaths) $hiccupSegments(p);
86
+ return ["path3", this.attribs || {}, acc];
87
+ }
88
+ }
89
+ export {
90
+ Path3
91
+ };
package/api/plane.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
2
1
  import type { Vec } from "@thi.ng/vectors";
3
- export declare class Plane implements IHiccupShape {
2
+ import type { Attribs, IHiccupShape3 } from "../api.js";
3
+ export declare class Plane implements IHiccupShape3<Plane> {
4
4
  normal: Vec;
5
5
  w: number;
6
6
  attribs?: Attribs | undefined;
7
+ readonly type = "plane";
8
+ readonly dim = 3;
7
9
  constructor(normal?: Vec, w?: number, attribs?: Attribs | undefined);
8
- get type(): string;
9
10
  copy(): Plane;
10
11
  withAttribs(attribs: Attribs): Plane;
11
12
  toHiccup(): (string | number | Vec | Attribs | undefined)[];
package/api/plane.js CHANGED
@@ -6,11 +6,14 @@ class Plane {
6
6
  this.w = w;
7
7
  this.attribs = attribs;
8
8
  }
9
- get type() {
10
- return "plane";
11
- }
9
+ type = "plane";
10
+ dim = 3;
12
11
  copy() {
13
- return new Plane(set3([], this.normal), this.w, __copyAttribs(this));
12
+ return new Plane(
13
+ set3([], this.normal),
14
+ this.w,
15
+ __copyAttribs(this.attribs)
16
+ );
14
17
  }
15
18
  withAttribs(attribs) {
16
19
  return new Plane(this.normal, this.w, attribs);
package/api/points.d.ts CHANGED
@@ -1,15 +1,13 @@
1
- import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, IHiccupShape2 } from "../api.js";
2
4
  import { APC } from "./apc.js";
3
- export declare class Points extends APC implements IHiccupShape {
4
- get type(): string;
5
+ export declare class Points extends APC implements IHiccupShape2<Points> {
6
+ readonly type = "points";
7
+ readonly dim = 2;
5
8
  copy(): Points;
9
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Points;
6
10
  withAttribs(attribs: Attribs): Points;
7
- toHiccup(): (string | import("@thi.ng/vectors").Vec[] | Attribs | undefined)[];
8
- }
9
- export declare class Points3 extends APC implements IHiccupShape {
10
- get type(): string;
11
- copy(): Points3;
12
- withAttribs(attribs: Attribs): Points3;
13
- toHiccup(): (string | import("@thi.ng/vectors").Vec[] | Attribs | undefined)[];
11
+ toHiccup(): (string | Vec[] | Attribs | undefined)[];
14
12
  }
15
13
  //# sourceMappingURL=points.d.ts.map
package/api/points.js CHANGED
@@ -1,34 +1,21 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { APC } from "./apc.js";
3
3
  class Points extends APC {
4
- get type() {
5
- return "points";
6
- }
4
+ type = "points";
5
+ dim = 2;
7
6
  copy() {
8
7
  return __copyShape(Points, this);
9
8
  }
10
- withAttribs(attribs) {
11
- return new Points(this.points, attribs);
12
- }
13
- toHiccup() {
14
- return ["points", this.attribs, this.points];
15
- }
16
- }
17
- class Points3 extends APC {
18
- get type() {
19
- return "points3";
20
- }
21
- copy() {
22
- return __copyShape(Points3, this);
9
+ copyTransformed(fn) {
10
+ return __copyShape(Points, this, fn(this.points));
23
11
  }
24
12
  withAttribs(attribs) {
25
- return new Points3(this.points, attribs);
13
+ return new Points(this.points, attribs);
26
14
  }
27
15
  toHiccup() {
28
- return ["points3", this.attribs, this.points];
16
+ return [this.type, this.attribs, this.points];
29
17
  }
30
18
  }
31
19
  export {
32
- Points,
33
- Points3
20
+ Points
34
21
  };
@@ -0,0 +1,13 @@
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, IHiccupShape3 } from "../api.js";
4
+ import { APC } from "./apc.js";
5
+ export declare class Points3 extends APC implements IHiccupShape3<Points3> {
6
+ readonly type = "points3";
7
+ readonly dim = 3;
8
+ copy(): Points3;
9
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Points3;
10
+ withAttribs(attribs: Attribs): Points3;
11
+ toHiccup(): (string | Vec[] | Attribs | undefined)[];
12
+ }
13
+ //# sourceMappingURL=points3.d.ts.map
package/api/points3.js ADDED
@@ -0,0 +1,21 @@
1
+ import { __copyShape } from "../internal/copy.js";
2
+ import { APC } from "./apc.js";
3
+ class Points3 extends APC {
4
+ type = "points3";
5
+ dim = 3;
6
+ copy() {
7
+ return __copyShape(Points3, this);
8
+ }
9
+ copyTransformed(fn) {
10
+ return __copyShape(Points3, this, fn(this.points));
11
+ }
12
+ withAttribs(attribs) {
13
+ return new Points3(this.points, attribs);
14
+ }
15
+ toHiccup() {
16
+ return [this.type, this.attribs, this.points];
17
+ }
18
+ }
19
+ export {
20
+ Points3
21
+ };
package/api/polygon.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
2
- import type { Vec } from "@thi.ng/vectors";
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, IHiccupShape2 } from "../api.js";
3
4
  import { APC } from "./apc.js";
4
- export declare class Polygon extends APC implements IHiccupShape {
5
- get type(): string;
5
+ export declare class Polygon extends APC implements IHiccupShape2<Polygon> {
6
+ readonly type = "poly";
7
+ readonly dim = 2;
6
8
  add(...points: Vec[]): void;
7
9
  copy(): Polygon;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Polygon;
8
11
  withAttribs(attribs: Attribs): Polygon;
9
12
  toHiccup(): (string | Vec[] | Attribs | undefined)[];
10
13
  }
package/api/polygon.js CHANGED
@@ -1,15 +1,17 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { APC } from "./apc.js";
3
3
  class Polygon extends APC {
4
- get type() {
5
- return "poly";
6
- }
4
+ type = "poly";
5
+ dim = 2;
7
6
  add(...points) {
8
7
  this.points.push(...points);
9
8
  }
10
9
  copy() {
11
10
  return __copyShape(Polygon, this);
12
11
  }
12
+ copyTransformed(fn) {
13
+ return __copyShape(Polygon, this, fn(this.points));
14
+ }
13
15
  withAttribs(attribs) {
14
16
  return new Polygon(this.points, attribs);
15
17
  }
@@ -0,0 +1,14 @@
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, IHiccupShape3 } from "../api.js";
4
+ import { APC } from "./apc.js";
5
+ export declare class Polygon3 extends APC implements IHiccupShape3<Polygon3> {
6
+ readonly type = "poly3";
7
+ readonly dim = 3;
8
+ add(...points: Vec[]): void;
9
+ copy(): Polygon3;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Polygon3;
11
+ withAttribs(attribs: Attribs): Polygon3;
12
+ toHiccup(): (string | Vec[] | Attribs | undefined)[];
13
+ }
14
+ //# sourceMappingURL=polygon3.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { __copyShape } from "../internal/copy.js";
2
+ import { APC } from "./apc.js";
3
+ class Polygon3 extends APC {
4
+ type = "poly3";
5
+ dim = 3;
6
+ add(...points) {
7
+ this.points.push(...points);
8
+ }
9
+ copy() {
10
+ return __copyShape(Polygon3, this);
11
+ }
12
+ copyTransformed(fn) {
13
+ return __copyShape(Polygon3, this, fn(this.points));
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Polygon3(this.points, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["polygon3", this.attribs, this.points];
20
+ }
21
+ }
22
+ export {
23
+ Polygon3
24
+ };
package/api/polyline.d.ts CHANGED
@@ -1,13 +1,27 @@
1
- import type { Attribs, IHiccupPathSegment, IHiccupShape } from "@thi.ng/geom-api";
2
- import type { Vec } from "@thi.ng/vectors";
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, IHiccupPathSegment, IHiccupShape2 } from "../api.js";
3
4
  import { APC } from "./apc.js";
4
- export declare class Polyline extends APC implements IHiccupShape, IHiccupPathSegment {
5
- get type(): string;
5
+ export declare class Polyline extends APC implements IHiccupShape2<Polyline>, IHiccupPathSegment {
6
+ readonly type = "polyline";
7
+ readonly dim = 2;
6
8
  add(...points: Vec[]): void;
7
9
  copy(): Polyline;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Polyline;
8
11
  withAttribs(attribs: Attribs): Polyline;
9
12
  toHiccup(): (string | Vec[] | {
10
13
  fill: string;
14
+ __samples?: Partial<import("../api.js").SamplingOpts> | number;
15
+ __prec?: number;
16
+ rotate?: number;
17
+ rotateX?: number;
18
+ rotateY?: number;
19
+ rotateZ?: number;
20
+ scale?: number | ReadonlyVec;
21
+ translate?: ReadonlyVec;
22
+ transform?: ReadonlyVec;
23
+ stroke?: any;
24
+ weight?: number;
11
25
  })[];
12
26
  toHiccupPathSegments(): any[];
13
27
  }
package/api/polyline.js CHANGED
@@ -1,25 +1,28 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
+ import { __hiccupLineSegment } from "../internal/vertices.js";
2
3
  import { APC } from "./apc.js";
3
4
  class Polyline extends APC {
4
- get type() {
5
- return "polyline";
6
- }
5
+ type = "polyline";
6
+ dim = 2;
7
7
  add(...points) {
8
8
  this.points.push(...points);
9
9
  }
10
10
  copy() {
11
11
  return __copyShape(Polyline, this);
12
12
  }
13
+ copyTransformed(fn) {
14
+ return __copyShape(Polyline, this, fn(this.points));
15
+ }
13
16
  withAttribs(attribs) {
14
17
  return new Polyline(this.points, attribs);
15
18
  }
16
19
  toHiccup() {
17
- return ["polyline", { ...this.attribs, fill: "none" }, this.points];
20
+ return [this.type, { ...this.attribs, fill: "none" }, this.points];
18
21
  }
19
22
  toHiccupPathSegments() {
20
23
  const res = [];
21
24
  for (let pts = this.points, n = pts.length, i = 1; i < n; i++) {
22
- res.push(["L", pts[i]]);
25
+ res.push(__hiccupLineSegment(pts[i - 1], pts[i]));
23
26
  }
24
27
  return res;
25
28
  }