@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/points3.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Attribs } from "./api.js";
2
+ import type { Vec } from "@thi.ng/vectors";
3
+ import { Points3 } from "./api/points3.js";
4
+ export declare const points3: (pts?: Iterable<Vec>, attribs?: Attribs) => Points3;
5
+ //# sourceMappingURL=points3.d.ts.map
package/points3.js ADDED
@@ -0,0 +1,5 @@
1
+ import { Points3 } from "./api/points3.js";
2
+ const points3 = (pts, attribs) => new Points3(pts, attribs);
3
+ export {
4
+ points3
5
+ };
package/polygon.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Attribs } from "@thi.ng/geom-api";
1
+ import type { Attribs } from "./api.js";
2
2
  import type { Vec } from "@thi.ng/vectors";
3
3
  import { Polygon } from "./api/polygon.js";
4
4
  export declare const polygon: (pts?: Iterable<Vec>, attribs?: Attribs) => Polygon;
@@ -9,7 +9,6 @@ export declare const polygon: (pts?: Iterable<Vec>, attribs?: Attribs) => Polygo
9
9
  * @param n
10
10
  * @param profile
11
11
  * @param attribs
12
- * @returns
13
12
  */
14
13
  export declare const star: (r: number, n: number, profile: number[], attribs?: Attribs) => Polygon;
15
14
  /**
@@ -21,10 +20,12 @@ export declare const star: (r: number, n: number, profile: number[], attribs?: A
21
20
  * vertex will be inset to 50% of the base radius.
22
21
  *
23
22
  * @example
24
- * ```ts
23
+ * ```ts tangle:../export/star-with-centroid.ts
25
24
  * import { starWithCentroid } from "@thi.ng/geom";
26
25
  *
27
- * starWithCentroid([100,200], 50, 5, [1, 0.5])
26
+ * console.log(
27
+ * starWithCentroid([100,200], 50, 5, [1, 0.5])
28
+ * );
28
29
  * // Polygon {
29
30
  * // points: [
30
31
  * // [150.000, 200.000],
@@ -47,7 +48,6 @@ export declare const star: (r: number, n: number, profile: number[], attribs?: A
47
48
  * @param n
48
49
  * @param profile
49
50
  * @param attribs
50
- * @returns
51
51
  */
52
52
  export declare const starWithCentroid: (pos: Vec, r: number, n: number, profile: number[], attribs?: Attribs) => Polygon;
53
53
  //# sourceMappingURL=polygon.d.ts.map
package/polygon3.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Attribs } from "./api.js";
2
+ import type { Vec } from "@thi.ng/vectors";
3
+ import { Polygon3 } from "./api/polygon3.js";
4
+ export declare const polygon3: (pts?: Iterable<Vec>, attribs?: Attribs) => Polygon3;
5
+ //# sourceMappingURL=polygon3.d.ts.map
package/polygon3.js ADDED
@@ -0,0 +1,5 @@
1
+ import { Polygon3 } from "./api/polygon3.js";
2
+ const polygon3 = (pts, attribs) => new Polygon3(pts, attribs);
3
+ export {
4
+ polygon3
5
+ };
package/polyline.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { Attribs } from "@thi.ng/geom-api";
1
+ import type { Attribs } from "./api.js";
2
2
  import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
3
  import { Polyline } from "./api/polyline.js";
4
- export declare const polyline: (pts: Iterable<Vec>, attribs?: Attribs) => Polyline;
4
+ export declare const polyline: (pts?: Iterable<Vec>, attribs?: Attribs) => Polyline;
5
5
  /**
6
6
  * Creates a polyline spiral from given params. The number of twists is defined
7
7
  * by the angle range. Resolution depends on angle range and number of steps.
package/polyline3.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Attribs } from "./api.js";
2
+ import type { Vec } from "@thi.ng/vectors";
3
+ import { Polyline3 } from "./api/polyline3.js";
4
+ export declare const polyline3: (pts: Iterable<Vec>, attribs?: Attribs) => Polyline3;
5
+ //# sourceMappingURL=polyline3.d.ts.map
package/polyline3.js ADDED
@@ -0,0 +1,5 @@
1
+ import { Polyline3 } from "./api/polyline3.js";
2
+ const polyline3 = (pts, attribs) => new Polyline3(pts, attribs);
3
+ export {
4
+ polyline3
5
+ };
package/proximity.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import type { IShape } from "@thi.ng/geom-api";
2
1
  import type { ReadonlyVec } from "@thi.ng/vectors";
2
+ import type { IShape } from "./api.js";
3
3
  /**
4
4
  * Computes {@link closestPoint} on `shape` to `p`, and if successful, returns
5
- * eucledian distance between that point and `p`.
5
+ * the distance between that point and `p`, using optionally given `dist`ance
6
+ * function (by default uses Eucledian distance).
6
7
  *
7
8
  * @param shape
8
9
  * @param p
10
+ * @param dist
9
11
  */
10
- export declare const proximity: (shape: IShape, p: ReadonlyVec) => number | undefined;
12
+ export declare const proximity: (shape: IShape, p: ReadonlyVec, dist?: import("@thi.ng/vectors").DistanceFn) => number | undefined;
11
13
  //# sourceMappingURL=proximity.d.ts.map
package/proximity.js CHANGED
@@ -1,6 +1,6 @@
1
- import { dist } from "@thi.ng/vectors/dist";
1
+ import { dist as $dist } from "@thi.ng/vectors/dist";
2
2
  import { closestPoint } from "./closest-point.js";
3
- const proximity = (shape, p) => {
3
+ const proximity = (shape, p, dist = $dist) => {
4
4
  const q = closestPoint(shape, p);
5
5
  return q ? dist(p, q) : void 0;
6
6
  };
package/quad.d.ts CHANGED
@@ -1,11 +1,6 @@
1
- import type { Attribs } from "@thi.ng/geom-api";
2
- import { type ReadonlyVec, type Vec } from "@thi.ng/vectors/api";
3
- import type { Plane } from "./api/plane.js";
1
+ import type { Attribs } from "./api.js";
2
+ import type { Vec } from "@thi.ng/vectors";
4
3
  import { Quad } from "./api/quad.js";
5
- import { Quad3 } from "./api/quad3.js";
6
4
  export declare function quad(a: Vec, b: Vec, c: Vec, d: Vec, attribs?: Attribs): Quad;
7
5
  export declare function quad(pts: Iterable<Vec>, attribs?: Attribs): Quad;
8
- export declare function quad3(a: Vec, b: Vec, c: Vec, d: Vec, attribs?: Attribs): Quad;
9
- export declare function quad3(pts: Iterable<Vec>, attribs?: Attribs): Quad;
10
- export declare const quadOnPlane: (plane: Plane, pos: ReadonlyVec, size: number | ReadonlyVec, attribs?: Attribs) => Quad3;
11
6
  //# sourceMappingURL=quad.d.ts.map
package/quad.js CHANGED
@@ -1,36 +1,8 @@
1
- import { isNumber } from "@thi.ng/checks/is-number";
2
- import { closestPointPlane } from "@thi.ng/geom-closest-point/plane";
3
- import { alignmentQuat } from "@thi.ng/matrices/alignment-quat";
4
- import { mulVQ } from "@thi.ng/matrices/mulv";
5
- import { add3 } from "@thi.ng/vectors/add";
6
- import { Z3 } from "@thi.ng/vectors/api";
7
1
  import { Quad } from "./api/quad.js";
8
- import { Quad3 } from "./api/quad3.js";
9
- import { __argAttribs } from "./internal/args.js";
10
2
  import { __pclike } from "./internal/pclike.js";
11
3
  function quad(...args) {
12
4
  return __pclike(Quad, args);
13
5
  }
14
- function quad3(...args) {
15
- const attr = __argAttribs(args);
16
- return new Quad3(args.length === 1 ? args[0] : args, attr);
17
- }
18
- const quadOnPlane = (plane, pos, size, attribs) => {
19
- pos = closestPointPlane(pos, plane.normal, plane.w);
20
- const [w, h] = isNumber(size) ? [size, size] : size;
21
- const q = alignmentQuat(Z3, plane.normal);
22
- return new Quad3(
23
- [
24
- [-w, -h, 0],
25
- [w, -h, 0],
26
- [w, h, 0],
27
- [-w, h, 0]
28
- ].map((p) => add3(null, mulVQ(null, q, p), pos)),
29
- attribs
30
- );
31
- };
32
6
  export {
33
- quad,
34
- quad3,
35
- quadOnPlane
7
+ quad
36
8
  };
package/quad3.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { Attribs } from "./api.js";
2
+ import { type ReadonlyVec, type Vec } from "@thi.ng/vectors/api";
3
+ import type { Plane } from "./api/plane.js";
4
+ import { Quad3 } from "./api/quad3.js";
5
+ export declare function quad3(a: Vec, b: Vec, c: Vec, d: Vec, attribs?: Attribs): Quad3;
6
+ export declare function quad3(pts: Iterable<Vec>, attribs?: Attribs): Quad3;
7
+ export declare const quadOnPlane: (plane: Plane, pos: ReadonlyVec, size: number | ReadonlyVec, attribs?: Attribs) => Quad3;
8
+ //# sourceMappingURL=quad3.d.ts.map
package/quad3.js ADDED
@@ -0,0 +1,30 @@
1
+ import { isNumber } from "@thi.ng/checks/is-number";
2
+ import { closestPointPlane } from "@thi.ng/geom-closest-point/plane";
3
+ import { alignmentQuat } from "@thi.ng/matrices/alignment-quat";
4
+ import { mulVQ } from "@thi.ng/matrices/mulv";
5
+ import { add3 } from "@thi.ng/vectors/add";
6
+ import { Z3 } from "@thi.ng/vectors/api";
7
+ import { Quad3 } from "./api/quad3.js";
8
+ import { __argAttribs } from "./internal/args.js";
9
+ function quad3(...args) {
10
+ const attr = __argAttribs(args);
11
+ return new Quad3(args.length === 1 ? args[0] : args, attr);
12
+ }
13
+ const quadOnPlane = (plane, pos, size, attribs) => {
14
+ pos = closestPointPlane(pos, plane.normal, plane.w);
15
+ const [w, h] = isNumber(size) ? [size, size] : size;
16
+ const q = alignmentQuat(Z3, plane.normal);
17
+ return new Quad3(
18
+ [
19
+ [-w, -h, 0],
20
+ [w, -h, 0],
21
+ [w, h, 0],
22
+ [-w, h, 0]
23
+ ].map((p) => add3(null, mulVQ(null, q, p), pos)),
24
+ attribs
25
+ );
26
+ };
27
+ export {
28
+ quad3,
29
+ quadOnPlane
30
+ };
package/quadratic.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Attribs } from "@thi.ng/geom-api";
1
+ import type { Attribs } from "./api.js";
2
2
  import type { Vec } from "@thi.ng/vectors";
3
3
  import { Quadratic } from "./api/quadratic.js";
4
4
  export declare function quadratic(a: Vec, b: Vec, c: Vec, attribs?: Attribs): Quadratic;
@@ -0,0 +1,7 @@
1
+ import type { Attribs } from "./api.js";
2
+ import type { Vec } from "@thi.ng/vectors";
3
+ import { Quadratic3 } from "./api/quadratic3.js";
4
+ export declare function quadratic3(a: Vec, b: Vec, c: Vec, attribs?: Attribs): Quadratic3;
5
+ export declare function quadratic3(pts: Iterable<Vec>, attribs?: Attribs): Quadratic3;
6
+ export declare const quadraticFromLine3: (a: Vec, b: Vec, attribs?: Attribs) => Quadratic3;
7
+ //# sourceMappingURL=quadratic3.d.ts.map
package/quadratic3.js ADDED
@@ -0,0 +1,11 @@
1
+ import { quadraticFromLine as _line } from "@thi.ng/geom-splines/quadratic-line";
2
+ import { Quadratic3 } from "./api/quadratic3.js";
3
+ import { __pclike } from "./internal/pclike.js";
4
+ function quadratic3(...args) {
5
+ return __pclike(Quadratic3, args);
6
+ }
7
+ const quadraticFromLine3 = (a, b, attribs) => new Quadratic3(_line(a, b), attribs);
8
+ export {
9
+ quadratic3,
10
+ quadraticFromLine3
11
+ };
package/ray.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Attribs } from "@thi.ng/geom-api";
1
+ import type { Attribs } from "./api.js";
2
2
  import type { Vec } from "@thi.ng/vectors";
3
3
  import { Ray } from "./api/ray.js";
4
4
  export declare const ray: (pos: Vec, dir: Vec, attribs?: Attribs, normalize?: boolean) => Ray;
package/ray.js CHANGED
@@ -1,6 +1,6 @@
1
- import { normalize as _norm } from "@thi.ng/vectors/normalize";
1
+ import { normalize2 } from "@thi.ng/vectors/normalize";
2
2
  import { Ray } from "./api/ray.js";
3
- const ray = (pos, dir, attribs, normalize = true) => new Ray(pos, normalize ? _norm(null, dir) : dir, attribs);
3
+ const ray = (pos, dir, attribs, normalize = true) => new Ray(pos, normalize ? normalize2(null, dir) : dir, attribs);
4
4
  export {
5
5
  ray
6
6
  };
package/ray3.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Attribs } from "./api.js";
2
+ import type { Vec } from "@thi.ng/vectors";
3
+ import { Ray3 } from "./api/ray3.js";
4
+ export declare const ray3: (pos: Vec, dir: Vec, attribs?: Attribs, normalize?: boolean) => Ray3;
5
+ //# sourceMappingURL=ray3.d.ts.map
package/ray3.js ADDED
@@ -0,0 +1,6 @@
1
+ import { normalize3 } from "@thi.ng/vectors/normalize";
2
+ import { Ray3 } from "./api/ray3.js";
3
+ const ray3 = (pos, dir, attribs, normalize = true) => new Ray3(pos, normalize ? normalize3(null, dir) : dir, attribs);
4
+ export {
5
+ ray3
6
+ };
package/rect.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Attribs } from "@thi.ng/geom-api";
1
+ import type { Attribs } from "./api.js";
2
2
  import { type ReadonlyVec, type Vec } from "@thi.ng/vectors/api";
3
3
  import type { Circle } from "./api/circle.js";
4
4
  import type { Polygon } from "./api/polygon.js";
package/resample.d.ts CHANGED
@@ -1,27 +1,68 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
- import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
2
+ import type { IShape, IShape2, IShape3, SamplingOpts } from "./api.js";
3
+ import type { ComplexPolygon } from "./api/complex-polygon.js";
4
+ import type { Cubic } from "./api/cubic.js";
5
+ import type { Cubic3 } from "./api/cubic3.js";
6
+ import type { Group } from "./api/group.js";
7
+ import type { Line } from "./api/line.js";
8
+ import type { Line3 } from "./api/line3.js";
9
+ import type { Polygon } from "./api/polygon.js";
10
+ import type { Polygon3 } from "./api/polygon3.js";
11
+ import type { Polyline } from "./api/polyline.js";
12
+ import type { Polyline3 } from "./api/polyline3.js";
13
+ import type { Quad3 } from "./api/quad3.js";
14
+ import type { Quadratic } from "./api/quadratic.js";
15
+ import type { Quadratic3 } from "./api/quadratic3.js";
3
16
  /**
4
- * Resamples given 2D shape with given options and returns result as polygon (if
17
+ * Function overrides for {@link resample}.
18
+ */
19
+ export type ResampleFn = {
20
+ (shape: ComplexPolygon, opts: number | Partial<SamplingOpts>): ComplexPolygon;
21
+ (shape: Cubic, opts: number | Partial<SamplingOpts>): Polyline;
22
+ (shape: Cubic3, opts: number | Partial<SamplingOpts>): Polyline3;
23
+ (shape: Group, opts: number | Partial<SamplingOpts>): Group;
24
+ (shape: Line, opts: number | Partial<SamplingOpts>): Polyline;
25
+ (shape: Line3, opts: number | Partial<SamplingOpts>): Polyline3;
26
+ (shape: Polyline, opts: number | Partial<SamplingOpts>): Polyline;
27
+ (shape: Polyline3, opts: number | Partial<SamplingOpts>): Polyline3;
28
+ (shape: Quadratic, opts: number | Partial<SamplingOpts>): Polyline;
29
+ (shape: Quadratic3, opts: number | Partial<SamplingOpts>): Polyline3;
30
+ (shape: Quad3, opts: number | Partial<SamplingOpts>): Polygon3;
31
+ (shape: IShape2, opts: number | Partial<SamplingOpts>): Polygon;
32
+ (shape: IShape3, opts: number | Partial<SamplingOpts>): IShape3;
33
+ } & MultiFn2<IShape, number | Partial<SamplingOpts>, IShape>;
34
+ /**
35
+ * Resamples given shape with given options and returns result as polygon (if
5
36
  * closed) or polyline (if open).
6
37
  *
7
38
  * @remarks
8
39
  * If the shape has a `__samples` attribute, it will be removed in the result to
9
- * avoid recursive application.
40
+ * ensure idempotent behavior.
10
41
  *
11
42
  * Currently implemented for:
12
43
  *
44
+ * - {@link Arc}
13
45
  * - {@link Circle}
14
46
  * - {@link ComplexPolygon}
47
+ * - {@link Cubic}
48
+ * - {@link Cubic3}
15
49
  * - {@link Ellipse}
16
50
  * - {@link Line}
51
+ * - {@link Line3}
17
52
  * - {@link Polygon}
53
+ * - {@link Polygon3}
18
54
  * - {@link Polyline}
55
+ * - {@link Polyline3}
19
56
  * - {@link Quad}
57
+ * - {@link Quad3}
58
+ * - {@link Quadratic}
59
+ * - {@link Quadratic3}
20
60
  * - {@link Rect}
21
61
  * - {@link Triangle}
62
+ * - {@link Triangle3}
22
63
  *
23
64
  * @param shape
24
65
  * @param opts
25
66
  */
26
- export declare const resample: MultiFn2<IShape, number | Partial<SamplingOpts>, IShape>;
67
+ export declare const resample: ResampleFn;
27
68
  //# sourceMappingURL=resample.d.ts.map
package/resample.js CHANGED
@@ -1,29 +1,39 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
2
  import { resample as _resample } from "@thi.ng/geom-resample/resample";
3
- import { ComplexPolygon } from "./api/complex-polygon.js";
4
- import { Polygon } from "./api/polygon.js";
5
- import { Polyline } from "./api/polyline.js";
6
3
  import { asPolygon } from "./as-polygon.js";
7
- import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
4
+ import { asPolyline } from "./as-polyline.js";
8
5
  import { __dispatch } from "./internal/dispatch.js";
9
6
  const resample = defmulti(
10
7
  __dispatch,
11
8
  {
12
- ellipse: "circle",
13
- line: "polyline",
14
- quad: "poly",
15
- tri: "poly",
16
- rect: "circle"
9
+ arc: "$aspolyline",
10
+ circle: "$aspoly",
11
+ complexpoly: "group",
12
+ cubic: "$aspolyline",
13
+ cubic3: "$aspolyline",
14
+ ellipse: "$aspoly",
15
+ line: "$aspolyline",
16
+ line3: "$aspolyline",
17
+ poly3: "poly",
18
+ polyline3: "polyline",
19
+ quad: "$aspoly",
20
+ quad3: "$aspoly",
21
+ quadratic: "$aspolyline",
22
+ quadratic3: "$aspolyline",
23
+ rect: "$aspoly",
24
+ tri: "$aspoly",
25
+ tri3: "$aspoly"
17
26
  },
18
27
  {
19
- circle: ($, opts) => asPolygon($, opts)[0],
20
- complexpoly: ($, opts) => new ComplexPolygon(
21
- resample($.boundary, opts),
22
- $.children.map((child) => resample(child, opts)),
23
- __attribs($)
28
+ $aspoly: ($, opts) => asPolygon($, opts)[0],
29
+ $aspolyline: ($, opts) => asPolyline($, opts)[0],
30
+ group: ($, opts) => $.copyTransformed((child) => resample(child, opts)),
31
+ poly: ($, opts) => $.copyTransformed(
32
+ (points) => _resample(points, opts, true, true)
24
33
  ),
25
- poly: ($, opts) => new Polygon(_resample($.points, opts, true, true), __attribs($)),
26
- polyline: ($, opts) => new Polyline(_resample($.points, opts, false, true), __attribs($))
34
+ polyline: ($, opts) => $.copyTransformed(
35
+ (points) => _resample(points, opts, false, true)
36
+ )
27
37
  }
28
38
  );
29
39
  export {
@@ -0,0 +1,33 @@
1
+ import type { MultiFn3 } from "@thi.ng/defmulti";
2
+ import type { ReadonlyVec } from "@thi.ng/vectors";
3
+ import type { IShape3 } from "./api.js";
4
+ export type RotateAroundAxisFn = {
5
+ <T extends IShape3>(shape: T, axis: ReadonlyVec, theta: number): T;
6
+ } & MultiFn3<IShape3, ReadonlyVec, number, IShape3>;
7
+ /**
8
+ * Rotates given 3D shape by `theta` (in radians) around `axis`.
9
+ *
10
+ * @remarks
11
+ * Currently implemented for:
12
+ *
13
+ * - {@link Cubic3}
14
+ * - {@link Group3}
15
+ * - {@link Polygon3}
16
+ * - {@link Polyline3}
17
+ * - {@link Line3}
18
+ * - {@link Path3}
19
+ * - {@link Points3}
20
+ * - {@link Quad3}
21
+ * - {@link Quadratic3}
22
+ * - {@link Ray3}
23
+ * - {@link Triangle3}
24
+ *
25
+ * @param shape
26
+ * @param axis
27
+ * @param theta
28
+ */
29
+ export declare const rotateAroundAxis: RotateAroundAxisFn;
30
+ export declare const rotateX: (shape: IShape3, theta: number) => IShape3;
31
+ export declare const rotateY: (shape: IShape3, theta: number) => IShape3;
32
+ export declare const rotateZ: (shape: IShape3, theta: number) => IShape3;
33
+ //# sourceMappingURL=rotate-around-axis.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { mulV33 } from "@thi.ng/matrices/mulv";
3
+ import { rotationAroundAxis33 } from "@thi.ng/matrices/rotation-around-axis";
4
+ import { X3, Y3, Z3 } from "@thi.ng/vectors/api";
5
+ import { rotateAroundAxis3 } from "@thi.ng/vectors/rotate-around-axis";
6
+ import { Ray3 } from "./api/ray3.js";
7
+ import { __copyAttribs } from "./internal/copy.js";
8
+ import { __dispatch } from "./internal/dispatch.js";
9
+ import { __segmentTransformer } from "./internal/transform.js";
10
+ const rotateAroundAxis = defmulti(
11
+ __dispatch,
12
+ {
13
+ cubic3: "points3",
14
+ line3: "points3",
15
+ poly3: "points3",
16
+ polyline3: "points3",
17
+ quad3: "points3",
18
+ quadratic3: "points3",
19
+ tri3: "points3"
20
+ },
21
+ {
22
+ group3: ($, axis, theta) => $.copyTransformed(
23
+ (x) => rotateAroundAxis(x, axis, theta)
24
+ ),
25
+ path3: ($, axis, theta) => {
26
+ const mat = rotationAroundAxis33([], axis, theta);
27
+ return $.copyTransformed(
28
+ __segmentTransformer(
29
+ (geo) => rotateAroundAxis(geo, axis, theta),
30
+ (p) => mulV33([], mat, p)
31
+ )
32
+ );
33
+ },
34
+ points3: ($, axis, theta) => {
35
+ const mat = rotationAroundAxis33([], axis, theta);
36
+ return $.copyTransformed(
37
+ (points) => points.map((p) => mulV33([], mat, p))
38
+ );
39
+ },
40
+ ray3: ($, axis, theta) => {
41
+ return new Ray3(
42
+ rotateAroundAxis3([], $.pos, axis, theta),
43
+ rotateAroundAxis3([], $.dir, axis, theta),
44
+ __copyAttribs($.attribs)
45
+ );
46
+ }
47
+ }
48
+ );
49
+ const rotateX = (shape, theta) => rotateAroundAxis(shape, X3, theta);
50
+ const rotateY = (shape, theta) => rotateAroundAxis(shape, Y3, theta);
51
+ const rotateZ = (shape, theta) => rotateAroundAxis(shape, Z3, theta);
52
+ export {
53
+ rotateAroundAxis,
54
+ rotateX,
55
+ rotateY,
56
+ rotateZ
57
+ };
package/rotate.d.ts CHANGED
@@ -1,5 +1,16 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
2
+ import type { IShape2 } from "./api.js";
3
+ import type { Arc } from "./api/arc.js";
4
+ import type { Ellipse } from "./api/ellipse.js";
5
+ import type { Path } from "./api/path.js";
6
+ import type { Polygon } from "./api/polygon.js";
7
+ import type { Rect } from "./api/rect.js";
8
+ export type RotateFn = {
9
+ (shape: Arc, theta: number): Path;
10
+ (shape: Ellipse, theta: number): Path;
11
+ (shape: Rect, theta: number): Polygon;
12
+ <T extends IShape2>(shape: T, theta: number): T;
13
+ } & MultiFn2<IShape2, number, IShape2>;
3
14
  /**
4
15
  * Rotates given 2D shape by `theta` (in radians).
5
16
  *
@@ -7,10 +18,12 @@ import type { IShape } from "@thi.ng/geom-api";
7
18
  * Currently implemented for:
8
19
  *
9
20
  * - {@link Arc}
21
+ * - {@link BPatch}
10
22
  * - {@link Circle}
11
23
  * - {@link ComplexPolygon}
12
24
  * - {@link Cubic}
13
25
  * - {@link Ellipse}
26
+ * - {@link Extra}
14
27
  * - {@link Group}
15
28
  * - {@link Line}
16
29
  * - {@link Path}
@@ -27,5 +40,5 @@ import type { IShape } from "@thi.ng/geom-api";
27
40
  * @param shape
28
41
  * @param theta
29
42
  */
30
- export declare const rotate: MultiFn2<IShape, number, IShape>;
43
+ export declare const rotate: RotateFn;
31
44
  //# sourceMappingURL=rotate.d.ts.map
package/rotate.js CHANGED
@@ -1,68 +1,70 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { mulV22 } from "@thi.ng/matrices/mulv";
3
+ import { rotation22 } from "@thi.ng/matrices/rotation";
2
4
  import { rotate as $rotate } from "@thi.ng/vectors/rotate";
3
5
  import { Circle } from "./api/circle.js";
4
- import { ComplexPolygon } from "./api/complex-polygon.js";
5
- import { Cubic } from "./api/cubic.js";
6
- import { Line } from "./api/line.js";
7
- import { Path } from "./api/path.js";
8
- import { Points } from "./api/points.js";
9
- import { Polygon } from "./api/polygon.js";
10
- import { Polyline } from "./api/polyline.js";
11
- import { Quad } from "./api/quad.js";
12
- import { Quadratic } from "./api/quadratic.js";
13
6
  import { Ray } from "./api/ray.js";
14
7
  import { Text } from "./api/text.js";
15
- import { Triangle } from "./api/triangle.js";
16
8
  import { asPath } from "./as-path.js";
17
9
  import { asPolygon } from "./as-polygon.js";
18
10
  import { __copyAttribs } from "./internal/copy.js";
19
11
  import { __dispatch } from "./internal/dispatch.js";
20
- import { __rotatedShape as tx } from "./internal/rotate.js";
12
+ import { __ensureNoArc } from "./internal/error.js";
21
13
  import { __segmentTransformer } from "./internal/transform.js";
22
14
  const rotate = defmulti(
23
15
  __dispatch,
24
- {},
25
16
  {
26
- arc: ($, theta) => {
27
- const a = $.copy();
28
- $rotate(null, a.pos, theta);
29
- return a;
30
- },
31
- circle: ($, theta) => new Circle($rotate([], $.pos, theta), $.r, __copyAttribs($)),
32
- complexpoly: ($, theta) => new ComplexPolygon(
33
- rotate($.boundary, theta),
34
- $.children.map((child) => rotate(child, theta))
17
+ arc: "$aspath",
18
+ bpatch: "points",
19
+ complexpoly: "group",
20
+ cubic: "points",
21
+ ellipse: "$aspath",
22
+ line: "points",
23
+ poly: "points",
24
+ polyline: "points",
25
+ quad: "points",
26
+ quadratic: "points",
27
+ rect: "$aspoly",
28
+ tri: "points"
29
+ },
30
+ {
31
+ $aspath: ($, theta) => rotate(asPath($), theta),
32
+ $aspoly: ($, theta) => rotate(asPolygon($)[0], theta),
33
+ circle: ($, theta) => new Circle(
34
+ $rotate([], $.pos, theta),
35
+ $.r,
36
+ __copyAttribs($.attribs)
35
37
  ),
36
- cubic: tx(Cubic),
37
- ellipse: ($, theta) => rotate(asPath($), theta),
38
+ extra: ($) => $,
38
39
  group: ($, theta) => $.copyTransformed((x) => rotate(x, theta)),
39
- line: tx(Line),
40
40
  path: ($, theta) => {
41
- const $rotateSegments = __segmentTransformer(
42
- (geo) => rotate(geo, theta),
43
- (p) => $rotate([], p, theta)
44
- );
45
- return new Path(
46
- $rotateSegments($.segments),
47
- $.subPaths.map($rotateSegments),
48
- __copyAttribs($)
41
+ const mat = rotation22([], theta);
42
+ return $.copyTransformed(
43
+ __segmentTransformer(
44
+ (geo) => {
45
+ __ensureNoArc(geo);
46
+ return rotate(geo, theta);
47
+ },
48
+ (p) => mulV22([], mat, p)
49
+ )
49
50
  );
50
51
  },
51
- points: tx(Points),
52
- poly: tx(Polygon),
53
- polyline: tx(Polyline),
54
- quad: tx(Quad),
55
- quadratic: tx(Quadratic),
56
- ray: ($, theta) => {
57
- return new Ray(
58
- $rotate([], $.pos, theta),
59
- $rotate([], $.dir, theta),
60
- __copyAttribs($)
52
+ points: ($, theta) => {
53
+ const mat = rotation22([], theta);
54
+ return $.copyTransformed(
55
+ (points) => points.map((p) => mulV22([], mat, p))
61
56
  );
62
57
  },
63
- rect: ($, theta) => rotate(asPolygon($)[0], theta),
64
- text: ($, theta) => new Text($rotate([], $.pos, theta), $.body, __copyAttribs($)),
65
- tri: tx(Triangle)
58
+ ray: ($, theta) => new Ray(
59
+ $rotate([], $.pos, theta),
60
+ $rotate([], $.dir, theta),
61
+ __copyAttribs($.attribs)
62
+ ),
63
+ text: ($, theta) => new Text(
64
+ $rotate([], $.pos, theta),
65
+ $.body,
66
+ __copyAttribs($.attribs)
67
+ )
66
68
  }
67
69
  );
68
70
  export {