@thi.ng/geom 7.0.1 → 8.0.1

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 +196 -1
  2. package/README.md +357 -114
  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 +81 -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 +36 -1
  133. package/index.js +36 -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
@@ -0,0 +1,28 @@
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
+ import type { Attribs, IHiccupPathSegment, IHiccupShape3 } from "../api.js";
4
+ import { APC } from "./apc.js";
5
+ export declare class Polyline3 extends APC implements IHiccupShape3<Polyline3>, IHiccupPathSegment {
6
+ readonly type = "polyline3";
7
+ readonly dim = 3;
8
+ add(...points: Vec[]): void;
9
+ copy(): Polyline3;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Polyline3;
11
+ withAttribs(attribs: Attribs): Polyline3;
12
+ toHiccup(): (string | Vec[] | {
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;
25
+ })[];
26
+ toHiccupPathSegments(): any[];
27
+ }
28
+ //# sourceMappingURL=polyline3.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { __copyShape } from "../internal/copy.js";
2
+ import { APC } from "./apc.js";
3
+ class Polyline3 extends APC {
4
+ type = "polyline3";
5
+ dim = 3;
6
+ add(...points) {
7
+ this.points.push(...points);
8
+ }
9
+ copy() {
10
+ return __copyShape(Polyline3, this);
11
+ }
12
+ copyTransformed(fn) {
13
+ return __copyShape(Polyline3, this, fn(this.points));
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Polyline3(this.points, attribs);
17
+ }
18
+ toHiccup() {
19
+ return [this.type, { ...this.attribs, fill: "none" }, this.points];
20
+ }
21
+ toHiccupPathSegments() {
22
+ const res = [];
23
+ for (let pts = this.points, n = pts.length, i = 1; i < n; i++) {
24
+ res.push(["L", pts[i]]);
25
+ }
26
+ return res;
27
+ }
28
+ }
29
+ export {
30
+ Polyline3
31
+ };
package/api/quad.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 Quad extends APC implements IHiccupShape {
5
+ export declare class Quad extends APC implements IHiccupShape2<Quad> {
6
+ readonly type = "quad";
7
+ readonly dim = 2;
5
8
  constructor(points: Iterable<Vec>, attribs?: Attribs);
6
- get type(): string;
7
9
  copy(): Quad;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Quad;
8
11
  withAttribs(attribs: Attribs): Quad;
9
12
  toHiccup(): (string | Vec[] | Attribs | undefined)[];
10
13
  }
package/api/quad.js CHANGED
@@ -2,16 +2,18 @@ import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
4
  class Quad extends APC {
5
+ type = "quad";
6
+ dim = 2;
5
7
  constructor(points, attribs) {
6
8
  super(points, attribs);
7
9
  __ensureNumVerts(this.points.length, 4);
8
10
  }
9
- get type() {
10
- return "quad";
11
- }
12
11
  copy() {
13
12
  return __copyShape(Quad, this);
14
13
  }
14
+ copyTransformed(fn) {
15
+ return __copyShape(Quad, this, fn(this.points));
16
+ }
15
17
  withAttribs(attribs) {
16
18
  return new Quad(this.points, attribs);
17
19
  }
package/api/quad3.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, IHiccupShape3 } from "../api.js";
3
4
  import { APC } from "./apc.js";
4
- export declare class Quad3 extends APC implements IHiccupShape {
5
+ export declare class Quad3 extends APC implements IHiccupShape3<Quad3> {
6
+ readonly type = "quad3";
7
+ readonly dim = 3;
5
8
  constructor(points: Iterable<Vec>, attribs?: Attribs);
6
- get type(): string;
7
9
  copy(): Quad3;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Quad3;
8
11
  withAttribs(attribs: Attribs): Quad3;
9
12
  toHiccup(): (string | Vec[] | Attribs | undefined)[];
10
13
  }
package/api/quad3.js CHANGED
@@ -2,21 +2,23 @@ import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
4
  class Quad3 extends APC {
5
+ type = "quad3";
6
+ dim = 3;
5
7
  constructor(points, attribs) {
6
8
  super(points, attribs);
7
9
  __ensureNumVerts(this.points.length, 4);
8
10
  }
9
- get type() {
10
- return "quad3";
11
- }
12
11
  copy() {
13
12
  return __copyShape(Quad3, this);
14
13
  }
14
+ copyTransformed(fn) {
15
+ return __copyShape(Quad3, this, fn(this.points));
16
+ }
15
17
  withAttribs(attribs) {
16
18
  return new Quad3(this.points, attribs);
17
19
  }
18
20
  toHiccup() {
19
- return ["polygon", this.attribs, this.points];
21
+ return ["polygon3", this.attribs, this.points];
20
22
  }
21
23
  }
22
24
  export {
@@ -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, HiccupPathSegment, IHiccupPathSegment, IHiccupShape2 } from "../api.js";
3
4
  import { APC } from "./apc.js";
4
- export declare class Quadratic extends APC implements IHiccupShape, IHiccupPathSegment {
5
+ export declare class Quadratic extends APC implements IHiccupShape2<Quadratic>, IHiccupPathSegment {
6
+ readonly type = "quadratic";
7
+ readonly dim = 2;
5
8
  constructor(points: Iterable<Vec>, attribs?: Attribs);
6
- get type(): string;
7
9
  copy(): Quadratic;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Quadratic;
8
11
  withAttribs(attribs: Attribs): Quadratic;
9
12
  toHiccup(): (string | Attribs | (string | Vec)[][] | undefined)[];
10
- toHiccupPathSegments(): (string | Vec)[][];
13
+ toHiccupPathSegments(): HiccupPathSegment[];
11
14
  }
12
15
  //# sourceMappingURL=quadratic.d.ts.map
package/api/quadratic.js CHANGED
@@ -2,29 +2,35 @@ import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
4
  class Quadratic extends APC {
5
+ type = "quadratic";
6
+ dim = 2;
5
7
  constructor(points, attribs) {
6
8
  super(points, attribs);
7
9
  __ensureNumVerts(this.points.length, 3);
8
10
  }
9
- get type() {
10
- return "quadratic";
11
- }
12
11
  copy() {
13
12
  return __copyShape(Quadratic, this);
14
13
  }
14
+ copyTransformed(fn) {
15
+ return __copyShape(Quadratic, this, fn(this.points));
16
+ }
15
17
  withAttribs(attribs) {
16
18
  return new Quadratic(this.points, attribs);
17
19
  }
18
20
  toHiccup() {
21
+ const [a, b, c] = this.points;
19
22
  return [
20
23
  "path",
21
24
  this.attribs,
22
- [["M", this.points[0]], ...this.toHiccupPathSegments()]
25
+ [
26
+ ["M", a],
27
+ ["Q", b, c]
28
+ ]
23
29
  ];
24
30
  }
25
31
  toHiccupPathSegments() {
26
- const pts = this.points;
27
- return [["Q", pts[1], pts[2]]];
32
+ const [_, b, c] = this.points;
33
+ return [["Q", b, c]];
28
34
  }
29
35
  }
30
36
  export {
@@ -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 Quadratic3 extends APC implements IHiccupShape3<Quadratic3>, IHiccupPathSegment {
6
+ readonly type = "quadratic3";
7
+ readonly dim = 3;
8
+ constructor(points: Iterable<Vec>, attribs?: Attribs);
9
+ copy(): Quadratic3;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Quadratic3;
11
+ withAttribs(attribs: Attribs): Quadratic3;
12
+ toHiccup(): (string | Attribs | (string | Vec)[][] | undefined)[];
13
+ toHiccupPathSegments(): HiccupPathSegment[];
14
+ }
15
+ //# sourceMappingURL=quadratic3.d.ts.map
@@ -0,0 +1,38 @@
1
+ import { __copyShape } from "../internal/copy.js";
2
+ import { __ensureNumVerts } from "../internal/pclike.js";
3
+ import { APC } from "./apc.js";
4
+ class Quadratic3 extends APC {
5
+ type = "quadratic3";
6
+ dim = 3;
7
+ constructor(points, attribs) {
8
+ super(points, attribs);
9
+ __ensureNumVerts(this.points.length, 3);
10
+ }
11
+ copy() {
12
+ return __copyShape(Quadratic3, this);
13
+ }
14
+ copyTransformed(fn) {
15
+ return __copyShape(Quadratic3, this, fn(this.points));
16
+ }
17
+ withAttribs(attribs) {
18
+ return new Quadratic3(this.points, attribs);
19
+ }
20
+ toHiccup() {
21
+ const [a, b, c] = this.points;
22
+ return [
23
+ "path3",
24
+ this.attribs,
25
+ [
26
+ ["M", a],
27
+ ["Q", b, c]
28
+ ]
29
+ ];
30
+ }
31
+ toHiccupPathSegments() {
32
+ const [_, b, c] = this.points;
33
+ return [["Q", b, c]];
34
+ }
35
+ }
36
+ export {
37
+ Quadratic3
38
+ };
package/api/ray.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 Ray implements IHiccupShape {
2
+ import type { Attribs, IHiccupShape2 } from "../api.js";
3
+ export declare class Ray implements IHiccupShape2<Ray> {
4
4
  pos: Vec;
5
5
  dir: Vec;
6
6
  attribs?: Attribs | undefined;
7
+ readonly type = "ray";
8
+ readonly dim = 2;
7
9
  constructor(pos: Vec, dir: Vec, attribs?: Attribs | undefined);
8
- get type(): string;
9
10
  copy(): Ray;
10
11
  withAttribs(attribs: Attribs): Ray;
11
12
  toHiccup(): (string | Vec | Attribs | undefined)[];
package/api/ray.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { maddN2 } from "@thi.ng/vectors/maddn";
2
- import { set } from "@thi.ng/vectors/set";
2
+ import { set2 } from "@thi.ng/vectors/set";
3
3
  import { __copyAttribs } from "../internal/copy.js";
4
4
  class Ray {
5
5
  constructor(pos, dir, attribs) {
@@ -7,14 +7,13 @@ class Ray {
7
7
  this.dir = dir;
8
8
  this.attribs = attribs;
9
9
  }
10
- get type() {
11
- return "ray";
12
- }
10
+ type = "ray";
11
+ dim = 2;
13
12
  copy() {
14
13
  return new Ray(
15
- set([], this.pos),
16
- set([], this.dir),
17
- __copyAttribs(this)
14
+ set2([], this.pos),
15
+ set2([], this.dir),
16
+ __copyAttribs(this.attribs)
18
17
  );
19
18
  }
20
19
  withAttribs(attribs) {
package/api/ray3.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Vec } from "@thi.ng/vectors";
2
+ import type { Attribs, IHiccupShape3 } from "../api.js";
3
+ export declare class Ray3 implements IHiccupShape3<Ray3> {
4
+ pos: Vec;
5
+ dir: Vec;
6
+ attribs?: Attribs | undefined;
7
+ readonly type = "ray3";
8
+ readonly dim = 3;
9
+ constructor(pos: Vec, dir: Vec, attribs?: Attribs | undefined);
10
+ copy(): Ray3;
11
+ withAttribs(attribs: Attribs): Ray3;
12
+ toHiccup(): (string | Vec | Attribs | undefined)[];
13
+ }
14
+ //# sourceMappingURL=ray3.d.ts.map
package/api/ray3.js ADDED
@@ -0,0 +1,33 @@
1
+ import { maddN3 } from "@thi.ng/vectors/maddn";
2
+ import { set3 } from "@thi.ng/vectors/set";
3
+ import { __copyAttribs } from "../internal/copy.js";
4
+ class Ray3 {
5
+ constructor(pos, dir, attribs) {
6
+ this.pos = pos;
7
+ this.dir = dir;
8
+ this.attribs = attribs;
9
+ }
10
+ type = "ray3";
11
+ dim = 3;
12
+ copy() {
13
+ return new Ray3(
14
+ set3([], this.pos),
15
+ set3([], this.dir),
16
+ __copyAttribs(this.attribs)
17
+ );
18
+ }
19
+ withAttribs(attribs) {
20
+ return new Ray3(this.pos, this.dir, attribs);
21
+ }
22
+ toHiccup() {
23
+ return [
24
+ "line3",
25
+ this.attribs,
26
+ this.pos,
27
+ maddN3([], this.dir, 1e6, this.pos)
28
+ ];
29
+ }
30
+ }
31
+ export {
32
+ Ray3
33
+ };
package/api/rect.d.ts CHANGED
@@ -1,13 +1,15 @@
1
- import type { AABBLike, Attribs, IHiccupShape } from "@thi.ng/geom-api";
2
1
  import { type Vec } from "@thi.ng/vectors/api";
3
- export declare class Rect implements AABBLike, IHiccupShape {
2
+ import type { AABBLike, Attribs, IHiccupShape2 } from "../api.js";
3
+ export declare class Rect implements AABBLike, IHiccupShape2<Rect> {
4
4
  pos: Vec;
5
5
  attribs?: Attribs | undefined;
6
+ readonly type = "rect";
7
+ readonly dim = 2;
6
8
  size: Vec;
7
9
  constructor(pos?: Vec, size?: number | Vec, attribs?: Attribs | undefined);
8
- get type(): string;
9
10
  copy(): Rect;
10
11
  withAttribs(attribs: Attribs): Rect;
12
+ min(): Vec;
11
13
  max(): Vec;
12
14
  offset(offset: number): this;
13
15
  toHiccup(): (string | number | Vec | Attribs | undefined)[];
package/api/rect.js CHANGED
@@ -1,41 +1,44 @@
1
1
  import { add2 } from "@thi.ng/vectors/add";
2
2
  import { addN2 } from "@thi.ng/vectors/addn";
3
3
  import { ZERO2 } from "@thi.ng/vectors/api";
4
+ import { maddN2 } from "@thi.ng/vectors/maddn";
4
5
  import { max2 } from "@thi.ng/vectors/max";
5
6
  import { set2 } from "@thi.ng/vectors/set";
6
- import { subN2 } from "@thi.ng/vectors/subn";
7
7
  import { __asVec } from "../internal/args.js";
8
8
  import { __copyAttribs } from "../internal/copy.js";
9
9
  class Rect {
10
10
  constructor(pos = [0, 0], size = 1, attribs) {
11
11
  this.pos = pos;
12
12
  this.attribs = attribs;
13
- this.size = __asVec(size);
13
+ this.size = max2(null, __asVec(size), ZERO2);
14
14
  }
15
+ type = "rect";
16
+ dim = 2;
15
17
  size;
16
- get type() {
17
- return "rect";
18
- }
19
18
  copy() {
20
19
  return new Rect(
21
20
  set2([], this.pos),
22
21
  set2([], this.size),
23
- __copyAttribs(this)
22
+ __copyAttribs(this.attribs)
24
23
  );
25
24
  }
26
25
  withAttribs(attribs) {
27
26
  return new Rect(this.pos, this.size, attribs);
28
27
  }
28
+ min() {
29
+ return set2([], this.pos);
30
+ }
29
31
  max() {
30
32
  return add2([], this.pos, this.size);
31
33
  }
32
34
  offset(offset) {
33
- subN2(null, this.pos, offset);
35
+ const c = maddN2([], this.size, 0.5, this.pos);
34
36
  max2(null, addN2(null, this.size, offset * 2), ZERO2);
37
+ maddN2(this.pos, this.size, -0.5, c);
35
38
  return this;
36
39
  }
37
40
  toHiccup() {
38
- return ["rect", this.attribs, this.pos, this.size[0], this.size[1]];
41
+ return [this.type, this.attribs, this.pos, this.size[0], this.size[1]];
39
42
  }
40
43
  }
41
44
  export {
package/api/sphere.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 Sphere implements IHiccupShape {
2
+ import type { Attribs, IHiccupShape3 } from "../api.js";
3
+ export declare class Sphere implements IHiccupShape3<Sphere> {
4
4
  pos: Vec;
5
5
  r: number;
6
6
  attribs?: Attribs | undefined;
7
+ readonly type = "sphere";
8
+ readonly dim = 3;
7
9
  constructor(pos?: Vec, r?: number, attribs?: Attribs | undefined);
8
- get type(): string;
9
10
  copy(): Sphere;
10
11
  withAttribs(attribs: Attribs): Sphere;
11
12
  toHiccup(): (string | number | Vec | Attribs | undefined)[];
package/api/sphere.js CHANGED
@@ -6,17 +6,20 @@ class Sphere {
6
6
  this.r = r;
7
7
  this.attribs = attribs;
8
8
  }
9
- get type() {
10
- return "sphere";
11
- }
9
+ type = "sphere";
10
+ dim = 3;
12
11
  copy() {
13
- return new Sphere(set3([], this.pos), this.r, __copyAttribs(this));
12
+ return new Sphere(
13
+ set3([], this.pos),
14
+ this.r,
15
+ __copyAttribs(this.attribs)
16
+ );
14
17
  }
15
18
  withAttribs(attribs) {
16
19
  return new Sphere(this.pos, this.r, attribs);
17
20
  }
18
21
  toHiccup() {
19
- return ["sphere", this.attribs, this.pos, this.r];
22
+ return [this.type, this.attribs, this.pos, this.r];
20
23
  }
21
24
  }
22
25
  export {
package/api/text.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
2
1
  import type { Vec } from "@thi.ng/vectors";
2
+ import type { Attribs, IHiccupShape2 } from "../api.js";
3
3
  /**
4
4
  * Basic stub for text elements. Currently, only a minimal set of geometry
5
5
  * operations are implemented for this type, however this type implements
@@ -7,12 +7,13 @@ import type { Vec } from "@thi.ng/vectors";
7
7
  * so is useful as wrapper for inclusion of text elements in {@link Group}s with
8
8
  * other shape types.
9
9
  */
10
- export declare class Text implements IHiccupShape {
10
+ export declare class Text implements IHiccupShape2<Text> {
11
11
  pos: Vec;
12
12
  body: any;
13
13
  attribs?: Attribs | undefined;
14
+ readonly type = "text";
15
+ readonly dim = 2;
14
16
  constructor(pos: Vec, body: any, attribs?: Attribs | undefined);
15
- get type(): string;
16
17
  copy(): Text;
17
18
  withAttribs(attribs: Attribs): Text;
18
19
  toHiccup(): any[];
package/api/text.js CHANGED
@@ -6,17 +6,20 @@ class Text {
6
6
  this.body = body;
7
7
  this.attribs = attribs;
8
8
  }
9
- get type() {
10
- return "text";
11
- }
9
+ type = "text";
10
+ dim = 2;
12
11
  copy() {
13
- return new Text(set([], this.pos), this.body, __copyAttribs(this));
12
+ return new Text(
13
+ set([], this.pos),
14
+ this.body,
15
+ __copyAttribs(this.attribs)
16
+ );
14
17
  }
15
18
  withAttribs(attribs) {
16
19
  return new Text(this.pos, this.body, attribs);
17
20
  }
18
21
  toHiccup() {
19
- return ["text", this.attribs, this.pos, this.body];
22
+ return [this.type, this.attribs, this.pos, this.body];
20
23
  }
21
24
  }
22
25
  export {
package/api/triangle.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 Triangle extends APC implements IHiccupShape {
5
+ export declare class Triangle extends APC implements IHiccupShape2<Triangle> {
6
+ readonly type = "tri";
7
+ readonly dim = 2;
5
8
  constructor(points: Iterable<Vec>, attribs?: Attribs);
6
- get type(): string;
7
9
  copy(): Triangle;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Triangle;
8
11
  withAttribs(attribs: Attribs): Triangle;
9
12
  toHiccup(): (string | Vec[] | Attribs | undefined)[];
10
13
  }
package/api/triangle.js CHANGED
@@ -2,16 +2,18 @@ import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
4
  class Triangle extends APC {
5
+ type = "tri";
6
+ dim = 2;
5
7
  constructor(points, attribs) {
6
8
  super(points, attribs);
7
9
  __ensureNumVerts(this.points.length, 3);
8
10
  }
9
- get type() {
10
- return "tri";
11
- }
12
11
  copy() {
13
12
  return __copyShape(Triangle, this);
14
13
  }
14
+ copyTransformed(fn) {
15
+ return __copyShape(Triangle, this, fn(this.points));
16
+ }
15
17
  withAttribs(attribs) {
16
18
  return new Triangle(this.points, attribs);
17
19
  }
@@ -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 Triangle3 extends APC implements IHiccupShape3<Triangle3> {
6
+ readonly type = "tri3";
7
+ readonly dim = 3;
8
+ constructor(points: Iterable<Vec>, attribs?: Attribs);
9
+ copy(): Triangle3;
10
+ copyTransformed(fn: Fn<ReadonlyVec[], Vec[]>): Triangle3;
11
+ withAttribs(attribs: Attribs): Triangle3;
12
+ toHiccup(): (string | Vec[] | Attribs | undefined)[];
13
+ }
14
+ //# sourceMappingURL=triangle3.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { __copyShape } from "../internal/copy.js";
2
+ import { __ensureNumVerts } from "../internal/pclike.js";
3
+ import { APC } from "./apc.js";
4
+ class Triangle3 extends APC {
5
+ type = "tri3";
6
+ dim = 3;
7
+ constructor(points, attribs) {
8
+ super(points, attribs);
9
+ __ensureNumVerts(this.points.length, 3);
10
+ }
11
+ copy() {
12
+ return __copyShape(Triangle3, this);
13
+ }
14
+ copyTransformed(fn) {
15
+ return __copyShape(Triangle3, this, fn(this.points));
16
+ }
17
+ withAttribs(attribs) {
18
+ return new Triangle3(this.points, attribs);
19
+ }
20
+ toHiccup() {
21
+ return ["polygon3", this.attribs, this.points];
22
+ }
23
+ }
24
+ export {
25
+ Triangle3
26
+ };