@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
@@ -1,57 +1,55 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
- import { ComplexPolygon } from "./api/complex-polygon.js";
3
- import { Cubic } from "./api/cubic.js";
4
- import { Line } from "./api/line.js";
5
2
  import { Path } from "./api/path.js";
6
- import { Points, Points3 } from "./api/points.js";
3
+ import { Points } from "./api/points.js";
7
4
  import { Polygon } from "./api/polygon.js";
8
5
  import { Polyline } from "./api/polyline.js";
9
- import { Quad } from "./api/quad.js";
10
- import { Quadratic } from "./api/quadratic.js";
11
- import { Triangle } from "./api/triangle.js";
12
6
  import { asPolygon } from "./as-polygon.js";
13
7
  import { asPolyline } from "./as-polyline.js";
14
- import { __copyAttribs } from "./internal/copy.js";
15
8
  import { __dispatch } from "./internal/dispatch.js";
9
+ import { __ensureNoArc } from "./internal/error.js";
16
10
  import {
17
11
  __segmentTransformer,
18
- __transformedShapePoints as tx,
19
- __transformedShapePoints3 as tx3
12
+ __transformedPointsWith
20
13
  } from "./internal/transform.js";
21
14
  const transformVertices = defmulti(
22
15
  __dispatch,
23
16
  {
24
- circle: "rect",
25
- ellipse: "circle"
17
+ arc: "$aspolyline",
18
+ circle: "$aspoly",
19
+ complexpoly: "group",
20
+ ellipse: "$aspoly",
21
+ group3: "group",
22
+ bpatch: "points",
23
+ cubic: "points",
24
+ cubic3: "points",
25
+ line: "points",
26
+ line3: "points",
27
+ path3: "path",
28
+ points3: "points",
29
+ poly: "points",
30
+ poly3: "points",
31
+ polyline: "points",
32
+ polyline3: "points",
33
+ quad: "points",
34
+ quad3: "points",
35
+ quadratic: "points",
36
+ quadratic3: "points",
37
+ rect: "$aspoly",
38
+ tri: "points",
39
+ tri3: "points"
26
40
  },
27
41
  {
28
- arc: ($, fn) => transformVertices(asPolyline($)[0], fn),
29
- complexpoly: ($, fn) => new ComplexPolygon(
30
- transformVertices($.boundary, fn),
31
- $.children.map((child) => transformVertices(child, fn))
32
- ),
33
- cubic: tx(Cubic),
42
+ $aspoly: ($, fn) => transformVertices(asPolygon($)[0], fn),
43
+ $aspolyline: ($, fn) => transformVertices(asPolyline($)[0], fn),
44
+ extra: ($) => $,
34
45
  group: ($, fn) => $.copyTransformed((x) => transformVertices(x, fn)),
35
- line: tx(Line),
36
- path: ($, fn) => {
37
- const $transformSegments = __segmentTransformer(
38
- (geo) => transformVertices(geo, fn),
39
- fn
40
- );
41
- return new Path(
42
- $transformSegments($.segments),
43
- $.subPaths.map($transformSegments),
44
- __copyAttribs($)
45
- );
46
- },
47
- points: tx(Points),
48
- points3: tx3(Points3),
49
- poly: tx(Polygon),
50
- polyline: tx(Polyline),
51
- quad: tx(Quad),
52
- quadratic: tx(Quadratic),
53
- rect: ($, fn) => transformVertices(asPolygon($)[0], fn),
54
- tri: tx(Triangle)
46
+ path: ($, fn) => $.copyTransformed(
47
+ __segmentTransformer((geo) => {
48
+ __ensureNoArc(geo);
49
+ return transformVertices(geo, fn);
50
+ }, fn)
51
+ ),
52
+ points: ($, fn) => $.copyTransformed((pts) => __transformedPointsWith(pts, fn))
55
53
  }
56
54
  );
57
55
  export {
package/transform.d.ts CHANGED
@@ -1,6 +1,23 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
3
2
  import type { ReadonlyMat } from "@thi.ng/matrices";
3
+ import type { IShape, IShape2, IShape3 } from "./api.js";
4
+ import type { Arc } from "./api/arc.js";
5
+ import type { Circle } from "./api/circle.js";
6
+ import type { Ellipse } from "./api/ellipse.js";
7
+ import { Path } from "./api/path.js";
8
+ import { Quad } from "./api/quad.js";
9
+ import type { Rect } from "./api/rect.js";
10
+ /**
11
+ * Function overrides for {@link transform}.
12
+ */
13
+ export type TransformFn = {
14
+ (shape: Arc, mat: ReadonlyMat): Path;
15
+ (shape: Circle, mat: ReadonlyMat): Path;
16
+ (shape: Ellipse, mat: ReadonlyMat): Path;
17
+ (shape: Rect, mat: ReadonlyMat): Quad;
18
+ <T extends IShape2>(shape: T, mat: ReadonlyMat): T;
19
+ <T extends IShape3>(shape: T, mat: ReadonlyMat): T;
20
+ } & MultiFn2<IShape, ReadonlyMat, IShape>;
4
21
  /**
5
22
  * Transforms given shape with provided matrix.
6
23
  *
@@ -18,26 +35,37 @@ import type { ReadonlyMat } from "@thi.ng/matrices";
18
35
  * Currently implemented for:
19
36
  *
20
37
  * - {@link Arc}
38
+ * - {@link BPatch}
21
39
  * - {@link Circle}
22
40
  * - {@link ComplexPolygon}
23
41
  * - {@link Cubic}
42
+ * - {@link Cubic3}
24
43
  * - {@link Ellipse}
44
+ * - {@link Extra}
25
45
  * - {@link Group}
46
+ * - {@link Group3}
26
47
  * - {@link Line}
48
+ * - {@link Line3}
27
49
  * - {@link Path}
50
+ * - {@link Path3}
28
51
  * - {@link Points}
29
52
  * - {@link Points3}
30
53
  * - {@link Polygon}
54
+ * - {@link Polygon3}
31
55
  * - {@link Polyline}
56
+ * - {@link Polyline3}
32
57
  * - {@link Quad}
58
+ * - {@link Quad3}
33
59
  * - {@link Quadratic}
60
+ * - {@link Quadratic3}
34
61
  * - {@link Ray}
35
62
  * - {@link Rect}
36
63
  * - {@link Text}
37
64
  * - {@link Triangle}
65
+ * - {@link Triangle3}
38
66
  *
39
67
  * @param shape
40
68
  * @param mat
41
69
  */
42
- export declare const transform: MultiFn2<IShape, ReadonlyMat, IShape>;
70
+ export declare const transform: TransformFn;
43
71
  //# sourceMappingURL=transform.d.ts.map
package/transform.js CHANGED
@@ -1,60 +1,74 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
- import { mulV } from "@thi.ng/matrices/mulv";
3
- import { ComplexPolygon } from "./api/complex-polygon.js";
4
- import { Cubic } from "./api/cubic.js";
5
- import { Line } from "./api/line.js";
2
+ import { mulV23, mulV344 } from "@thi.ng/matrices/mulv";
6
3
  import { Path } from "./api/path.js";
7
- import { Points, Points3 } from "./api/points.js";
8
- import { Polygon } from "./api/polygon.js";
9
- import { Polyline } from "./api/polyline.js";
4
+ import { Path3 } from "./api/path3.js";
5
+ import { Points } from "./api/points.js";
6
+ import { Points3 } from "./api/points3.js";
10
7
  import { Quad } from "./api/quad.js";
11
- import { Quadratic } from "./api/quadratic.js";
12
8
  import { Text } from "./api/text.js";
13
- import { Triangle } from "./api/triangle.js";
14
9
  import { asPath } from "./as-path.js";
15
10
  import { __copyAttribs } from "./internal/copy.js";
16
11
  import { __dispatch } from "./internal/dispatch.js";
12
+ import { __ensureNoArc } from "./internal/error.js";
17
13
  import {
18
14
  __segmentTransformer,
19
- __transformedShape as tx,
20
- __transformedShape3 as tx3
15
+ __transformedPoints
21
16
  } from "./internal/transform.js";
22
17
  import { vertices } from "./vertices.js";
23
18
  const transform = defmulti(
24
19
  __dispatch,
25
20
  {
26
- circle: "arc",
27
- ellipse: "circle"
21
+ arc: "$aspath",
22
+ circle: "$aspath",
23
+ complexpoly: "group",
24
+ bpatch: "points",
25
+ cubic: "points",
26
+ cubic3: "points3",
27
+ ellipse: "$aspath",
28
+ group3: "group",
29
+ line: "points",
30
+ line3: "points3",
31
+ poly: "points",
32
+ poly3: "points3",
33
+ polyline: "points",
34
+ polyline3: "points3",
35
+ quad: "points",
36
+ quad3: "points3",
37
+ quadratic: "points",
38
+ quadratic3: "points3",
39
+ tri: "points",
40
+ tri3: "points3"
28
41
  },
29
42
  {
30
- arc: ($, mat) => transform(asPath($), mat),
31
- complexpoly: ($, mat) => new ComplexPolygon(
32
- transform($.boundary, mat),
33
- $.children.map((child) => transform(child, mat))
34
- ),
35
- cubic: tx(Cubic),
43
+ $aspath: ($, mat) => transform(asPath($), mat),
44
+ extra: ($) => $,
36
45
  group: ($, mat) => $.copyTransformed((x) => transform(x, mat)),
37
- line: tx(Line),
38
- path: ($, mat) => {
39
- const $transformSegments = __segmentTransformer(
40
- (geo) => transform(geo, mat),
41
- (p) => mulV([], mat, p)
42
- );
43
- return new Path(
44
- $transformSegments($.segments),
45
- $.subPaths.map($transformSegments),
46
- __copyAttribs($)
47
- );
48
- },
49
- points: tx(Points),
50
- points3: tx3(Points3),
51
- poly: tx(Polygon),
52
- polyline: tx(Polyline),
53
- quad: tx(Quad),
54
- quadratic: tx(Quadratic),
55
- rect: ($, mat) => transform(new Quad(vertices($), __copyAttribs($)), mat),
56
- text: ($, mat) => new Text(mulV([], mat, $.pos), $.body, __copyAttribs($)),
57
- tri: tx(Triangle)
46
+ path: ($, mat) => $.copyTransformed(
47
+ __segmentTransformer(
48
+ (geo) => {
49
+ __ensureNoArc(geo);
50
+ return transform(geo, mat);
51
+ },
52
+ (p) => mulV23([], mat, p)
53
+ )
54
+ ),
55
+ path3: ($, mat) => $.copyTransformed(
56
+ __segmentTransformer(
57
+ (geo) => {
58
+ __ensureNoArc(geo);
59
+ return transform(geo, mat);
60
+ },
61
+ (p) => mulV344([], mat, p)
62
+ )
63
+ ),
64
+ points: ($, mat) => $.copyTransformed(
65
+ (points) => __transformedPoints(points, mat, mulV23)
66
+ ),
67
+ points3: ($, mat) => $.copyTransformed(
68
+ (points) => __transformedPoints(points, mat, mulV344)
69
+ ),
70
+ rect: ($, mat) => transform(new Quad(vertices($), __copyAttribs($.attribs)), mat),
71
+ text: ($, mat) => new Text(mulV23([], mat, $.pos), $.body, __copyAttribs($.attribs))
58
72
  }
59
73
  );
60
74
  export {
package/translate.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
3
2
  import type { ReadonlyVec } from "@thi.ng/vectors";
3
+ import type { IShape } from "./api.js";
4
+ /**
5
+ * Function overrides for {@link translate}.
6
+ */
7
+ export type TranslateFn = {
8
+ <T extends IShape>(shape: T, offset: ReadonlyVec): T;
9
+ } & MultiFn2<IShape, ReadonlyVec, IShape>;
4
10
  /**
5
11
  * Translates given shape by given `offset` vector.
6
12
  *
@@ -9,11 +15,15 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
9
15
  *
10
16
  * - {@link AABB}
11
17
  * - {@link Arc}
18
+ * - {@link BPatch}
12
19
  * - {@link Circle}
13
20
  * - {@link ComplexPolygon}
14
21
  * - {@link Cubic}
22
+ * - {@link Cubic3}
15
23
  * - {@link Ellipse}
24
+ * - {@link Extra}
16
25
  * - {@link Group}
26
+ * - {@link Group3}
17
27
  * - {@link Line}
18
28
  * - {@link Path}
19
29
  * - {@link Points}
@@ -31,5 +41,5 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
31
41
  * @param shape
32
42
  * @param offset
33
43
  */
34
- export declare const translate: MultiFn2<IShape, ReadonlyVec, IShape>;
44
+ export declare const translate: TranslateFn;
35
45
  //# sourceMappingURL=translate.d.ts.map
package/translate.js CHANGED
@@ -1,80 +1,79 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
- import { add2, add3 } from "@thi.ng/vectors/add";
2
+ import { add, add2, add3 } from "@thi.ng/vectors/add";
3
3
  import { set2, set3 } from "@thi.ng/vectors/set";
4
4
  import { AABB } from "./api/aabb.js";
5
5
  import { Circle } from "./api/circle.js";
6
- import { ComplexPolygon } from "./api/complex-polygon.js";
7
- import { Cubic } from "./api/cubic.js";
8
6
  import { Ellipse } from "./api/ellipse.js";
9
- import { Line } from "./api/line.js";
10
- import { Path } from "./api/path.js";
11
- import { Points, Points3 } from "./api/points.js";
12
- import { Polygon } from "./api/polygon.js";
13
- import { Polyline } from "./api/polyline.js";
14
- import { Quad } from "./api/quad.js";
15
- import { Quadratic } from "./api/quadratic.js";
16
7
  import { Ray } from "./api/ray.js";
8
+ import { Ray3 } from "./api/ray3.js";
17
9
  import { Rect } from "./api/rect.js";
18
10
  import { Sphere } from "./api/sphere.js";
19
11
  import { Text } from "./api/text.js";
20
- import { Triangle } from "./api/triangle.js";
21
12
  import { __copyAttribs } from "./internal/copy.js";
22
13
  import { __dispatch } from "./internal/dispatch.js";
23
14
  import { __segmentTransformer } from "./internal/transform.js";
24
- import { __translatedShape as tx } from "./internal/translate.js";
25
15
  const translate = defmulti(
26
16
  __dispatch,
27
- {},
17
+ {
18
+ bpatch: "points",
19
+ cubic: "points",
20
+ cubic3: "points3",
21
+ complexpoly: "group",
22
+ group3: "group",
23
+ line: "points",
24
+ line3: "points3",
25
+ path3: "path",
26
+ poly: "points",
27
+ poly3: "points3",
28
+ polyline: "points",
29
+ polyline3: "points3",
30
+ quad: "points",
31
+ quad3: "points3",
32
+ quadratic: "points",
33
+ quadratic3: "points3",
34
+ tri: "points",
35
+ tri3: "points3"
36
+ },
28
37
  {
29
38
  aabb: ($, delta) => new AABB(
30
39
  add3([], $.pos, delta),
31
40
  set3([], $.size),
32
- __copyAttribs($)
41
+ __copyAttribs($.attribs)
33
42
  ),
34
43
  arc: ($, delta) => {
35
44
  const a = $.copy();
36
45
  add2(null, a.pos, delta);
37
46
  return a;
38
47
  },
39
- circle: ($, delta) => new Circle(add2([], $.pos, delta), $.r, __copyAttribs($)),
40
- complexpoly: ($, delta) => new ComplexPolygon(
41
- translate($.boundary, delta),
42
- $.children.map((child) => translate(child, delta))
43
- ),
44
- cubic: tx(Cubic),
48
+ circle: ($, delta) => new Circle(add2([], $.pos, delta), $.r, __copyAttribs($.attribs)),
45
49
  ellipse: ($, delta) => new Ellipse(
46
50
  add2([], $.pos, delta),
47
51
  set2([], $.r),
48
- __copyAttribs($)
52
+ __copyAttribs($.attribs)
49
53
  ),
54
+ extra: ($) => $,
50
55
  group: ($, delta) => $.copyTransformed((x) => translate(x, delta)),
51
- line: tx(Line),
52
- path: ($, delta) => {
53
- const $translateSegments = __segmentTransformer(
56
+ path: ($, delta) => $.copyTransformed(
57
+ __segmentTransformer(
54
58
  (geo) => translate(geo, delta),
55
- (p) => add2([], p, delta)
56
- );
57
- return new Path(
58
- $translateSegments($.segments),
59
- $.subPaths.map($translateSegments),
60
- __copyAttribs($)
61
- );
62
- },
63
- points: tx(Points),
64
- points3: tx(Points3),
65
- poly: tx(Polygon),
66
- polyline: tx(Polyline),
67
- quad: tx(Quad),
68
- quadratic: tx(Quadratic),
69
- ray: ($, delta) => new Ray(add2([], $.pos, delta), $.dir, __copyAttribs($)),
59
+ (p) => add([], p, delta)
60
+ )
61
+ ),
62
+ points: ($, delta) => $.copyTransformed(
63
+ (points) => points.map((x) => add2([], x, delta))
64
+ ),
65
+ points3: ($, delta) => $.copyTransformed(
66
+ (points) => points.map((x) => add3([], x, delta))
67
+ ),
68
+ ray: ($, delta) => new Ray(add2([], $.pos, delta), $.dir, __copyAttribs($.attribs)),
69
+ ray3: ($, delta) => new Ray3(add3([], $.pos, delta), $.dir, __copyAttribs($.attribs)),
70
70
  rect: ($, delta) => new Rect(
71
71
  add2([], $.pos, delta),
72
72
  set2([], $.size),
73
- __copyAttribs($)
73
+ __copyAttribs($.attribs)
74
74
  ),
75
- sphere: ($, delta) => new Sphere(add3([], $.pos, delta), $.r, __copyAttribs($)),
76
- text: ($, delta) => new Text(add2([], $.pos, delta), $.body, __copyAttribs($)),
77
- tri: tx(Triangle)
75
+ sphere: ($, delta) => new Sphere(add3([], $.pos, delta), $.r, __copyAttribs($.attribs)),
76
+ text: ($, delta) => new Text(add2([], $.pos, delta), $.body, __copyAttribs($.attribs))
78
77
  }
79
78
  );
80
79
  export {
package/triangle.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 { Triangle } from "./api/triangle.js";
4
4
  export declare function triangle(a: Vec, b: Vec, c: Vec, attribs?: Attribs): Triangle;
package/triangle3.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { Attribs } from "./api.js";
2
+ import type { Vec } from "@thi.ng/vectors";
3
+ import { Triangle3 } from "./api/triangle3.js";
4
+ export declare function triangle3(a: Vec, b: Vec, c: Vec, attribs?: Attribs): Triangle3;
5
+ export declare function triangle3(pts: Iterable<Vec>, attribs?: Attribs): Triangle3;
6
+ //# sourceMappingURL=triangle3.d.ts.map
package/triangle3.js ADDED
@@ -0,0 +1,8 @@
1
+ import { Triangle3 } from "./api/triangle3.js";
2
+ import { __pclike } from "./internal/pclike.js";
3
+ function triangle3(...args) {
4
+ return __pclike(Triangle3, args);
5
+ }
6
+ export {
7
+ triangle3
8
+ };
package/union.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
2
+ import type { IShape } from "./api.js";
3
+ import { AABB } from "./api/aabb.js";
4
+ import { Rect } from "./api/rect.js";
5
+ /**
6
+ * Function overrides for {@link union}.
7
+ */
8
+ export type UnionFn = {
9
+ (a: AABB, b: AABB): AABB;
10
+ (a: Rect, b: Rect): Rect;
11
+ } & MultiFn2<IShape, IShape, IShape>;
3
12
  /**
4
13
  * Computes shape "union" of given 2 shapes.
5
14
  *
@@ -10,5 +19,5 @@ import type { IShape } from "@thi.ng/geom-api";
10
19
  * @param a
11
20
  * @param b
12
21
  */
13
- export declare const union: MultiFn2<IShape, IShape, IShape[]>;
22
+ export declare const union: UnionFn;
14
23
  //# sourceMappingURL=union.d.ts.map
package/union.js CHANGED
@@ -5,14 +5,13 @@ import { __unionBounds } from "./internal/bounds.js";
5
5
  import { __dispatch } from "./internal/dispatch.js";
6
6
  const union = defmulti(
7
7
  __dispatch,
8
- {},
9
8
  {
10
- aabb: (a, b) => [
11
- new AABB(...__unionBounds(a.pos, a.size, b.pos, b.size))
12
- ],
13
- rect: (a, b) => [
14
- new Rect(...__unionBounds(a.pos, a.size, b.pos, b.size))
15
- ]
9
+ rect: "aabb"
10
+ },
11
+ {
12
+ aabb: (a, b) => new a.constructor(
13
+ ...__unionBounds(a.pos, a.size, b.pos, b.size)
14
+ )
16
15
  }
17
16
  );
18
17
  export {
package/unmap-point.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { MultiFn2O } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
2
+ import type { IShape } from "./api.js";
3
3
  import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
4
4
  /**
5
5
  * Projects given point `uv` (normalized coords) into the target space defined
package/vertices.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
3
- import { type SamplingOpts } from "@thi.ng/geom-api/sample";
4
2
  import type { Vec } from "@thi.ng/vectors";
3
+ import type { IShape, SamplingOpts } from "./api.js";
5
4
  /**
6
5
  * Extracts/samples vertices from given shape's boundary and returns them as
7
6
  * array. Some shapes also support
8
- * [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html).
7
+ * [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-resample/interfaces/SamplingOpts.html).
9
8
  *
10
9
  * @remarks
11
10
  * The given sampling options (if any) can also be overridden per shape using
@@ -21,6 +20,7 @@ import type { Vec } from "@thi.ng/vectors";
21
20
  * - {@link ComplexPolygon}
22
21
  * - {@link Cubic}
23
22
  * - {@link Ellipse}
23
+ * - {@link Extra}
24
24
  * - {@link Group}
25
25
  * - {@link Line}
26
26
  * - {@link Path}
package/vertices.js CHANGED
@@ -1,8 +1,9 @@
1
+ import { peek } from "@thi.ng/arrays/peek";
1
2
  import { isArray } from "@thi.ng/checks/is-array";
2
3
  import { isNumber } from "@thi.ng/checks/is-number";
3
4
  import { defmulti } from "@thi.ng/defmulti/defmulti";
4
- import { DEFAULT_SAMPLES } from "@thi.ng/geom-api/sample";
5
5
  import { sample as _arcVertices } from "@thi.ng/geom-arc/sample";
6
+ import { DEFAULT_SAMPLES } from "@thi.ng/geom-resample/api";
6
7
  import { resample } from "@thi.ng/geom-resample/resample";
7
8
  import { sampleCubic } from "@thi.ng/geom-splines/cubic-sample";
8
9
  import { sampleQuadratic } from "@thi.ng/geom-splines/quadratic-sample";
@@ -16,15 +17,23 @@ import { ComplexPolygon } from "./api/complex-polygon.js";
16
17
  import { Polygon } from "./api/polygon.js";
17
18
  import { __dispatch } from "./internal/dispatch.js";
18
19
  import { __circleOpts, __sampleAttribs } from "./internal/vertices.js";
19
- import { peek } from "@thi.ng/arrays/peek";
20
20
  const vertices = defmulti(
21
21
  __dispatch,
22
22
  {
23
- line: "polyline",
24
23
  bpatch: "points",
24
+ cubic3: "cubic",
25
+ group3: "group",
26
+ line: "polyline",
27
+ line3: "polyline",
28
+ path3: "path",
25
29
  points3: "points",
30
+ poly3: "poly",
31
+ polyline3: "polyline",
26
32
  quad: "poly",
27
- tri: "poly"
33
+ quad3: "poly",
34
+ quadratic3: "quadratic",
35
+ tri: "poly",
36
+ tri3: "poly"
28
37
  },
29
38
  {
30
39
  // e +----+ h
@@ -100,6 +109,7 @@ const vertices = defmulti(
100
109
  }
101
110
  return buf;
102
111
  },
112
+ extra: () => [],
103
113
  group: ($, opts) => {
104
114
  opts = __sampleAttribs(opts, $.attribs);
105
115
  return $.children.reduce(
package/volume.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { MultiFn1 } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
2
+ import type { IShape } from "./api.js";
3
3
  /**
4
4
  * Returns the volume of given 3D shape. Returns 0 for all others.
5
5
  *
package/warp-points.d.ts CHANGED
@@ -1,16 +1,47 @@
1
- import type { IShape } from "@thi.ng/geom-api";
2
1
  import type { ReadonlyVec, Vec } from "@thi.ng/vectors/api";
2
+ import type { IShape } from "./api.js";
3
3
  import type { BPatch } from "./api/bpatch.js";
4
4
  import type { Rect } from "./api/rect.js";
5
5
  /**
6
- * Transfers/remaps points (in world space) given in relation to `src` shape to
7
- * be relative to the space of `dest` shape. Writes results to `out` (or creates
8
- * new array).
6
+ * Transfers/remaps point `p` (in world space) given in relation to `src` shape
7
+ * to be relative to the space of `dest` shape. Writes results to `out` (or
8
+ * creates new vector).
9
9
  *
10
10
  * @remarks
11
11
  * The type of `src` must be supported by {@link mapPoint}. The type of `dest`
12
12
  * must be supported by {@link unmapPoint}.
13
13
  *
14
+ * @example
15
+ * ```ts tangle:../export/warp-point.ts
16
+ * import { rect, warpPoint } from "@thi.ng/geom";
17
+ *
18
+ * const p = [1075, -1975];
19
+ *
20
+ * // source rect [1000,-2000] .. [1100,-1900]
21
+ * const src = rect([1000,-2000], 100);
22
+ *
23
+ * // destination rect [0,0] .. [0.5,0.5]
24
+ * const dest = rect(0.5);
25
+ *
26
+ * // map `p` into the space of `dest` via `src`
27
+ * console.log(warpPoint(p, dest, src));
28
+ * // [ 0.375, 0.125 ]
29
+ * ```
30
+ *
31
+ * @param p
32
+ * @param dest
33
+ * @param src
34
+ * @param out
35
+ */
36
+ export declare const warpPoint: (p: ReadonlyVec, dest: IShape, src: IShape, out?: Vec) => Vec;
37
+ /**
38
+ * Array version of {@link warpPoint}, transferring all points in the array from
39
+ * world space to the local space of `dest` via the local space of `src`.
40
+ *
41
+ * @remarks
42
+ * Note: Different arg orderThe type of `src` must be supported by {@link mapPoint}. The type of `dest`
43
+ * must be supported by {@link unmapPoint}.
44
+ *
14
45
  * @param pts
15
46
  * @param dest
16
47
  * @param src
package/warp-points.js CHANGED
@@ -2,6 +2,7 @@ import { bounds2 } from "@thi.ng/geom-poly-utils/bounds";
2
2
  import { mapPoint } from "./map-point.js";
3
3
  import { rectFromMinMax } from "./rect.js";
4
4
  import { unmapPoint } from "./unmap-point.js";
5
+ const warpPoint = (p, dest, src, out) => unmapPoint(dest, mapPoint(src, p), out);
5
6
  const warpPoints = (pts, dest, src, out = []) => {
6
7
  for (let n = pts.length, i = 0; i < n; i++) {
7
8
  out.push(unmapPoint(dest, mapPoint(src, pts[i])));
@@ -16,6 +17,7 @@ const warpPointsBPatch = (pts, dest, src, out = []) => {
16
17
  return out;
17
18
  };
18
19
  export {
20
+ warpPoint,
19
21
  warpPoints,
20
22
  warpPointsBPatch
21
23
  };