@thi.ng/geom 3.2.6 → 3.4.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 (146) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.md +52 -5
  3. package/aabb.d.ts +3 -0
  4. package/aabb.js +4 -0
  5. package/api/aabb.d.ts +3 -1
  6. package/api/aabb.js +16 -4
  7. package/api/apc.d.ts +3 -2
  8. package/api/arc.d.ts +1 -0
  9. package/api/arc.js +3 -0
  10. package/api/bpatch.d.ts +3 -2
  11. package/api/bpatch.js +3 -0
  12. package/api/circle.d.ts +1 -0
  13. package/api/circle.js +3 -0
  14. package/api/cubic.d.ts +3 -2
  15. package/api/cubic.js +3 -0
  16. package/api/ellipse.d.ts +1 -0
  17. package/api/ellipse.js +5 -2
  18. package/api/group.d.ts +1 -0
  19. package/api/group.js +3 -0
  20. package/api/line.d.ts +3 -2
  21. package/api/line.js +3 -0
  22. package/api/path.d.ts +1 -0
  23. package/api/path.js +5 -0
  24. package/api/plane.d.ts +1 -0
  25. package/api/plane.js +5 -2
  26. package/api/points.d.ts +5 -3
  27. package/api/points.js +6 -0
  28. package/api/polygon.d.ts +3 -2
  29. package/api/polygon.js +3 -0
  30. package/api/polyline.d.ts +2 -1
  31. package/api/polyline.js +3 -0
  32. package/api/quad.d.ts +3 -2
  33. package/api/quad.js +3 -0
  34. package/api/quad3.d.ts +3 -2
  35. package/api/quad3.js +3 -0
  36. package/api/quadratic.d.ts +3 -2
  37. package/api/quadratic.js +3 -0
  38. package/api/ray.d.ts +1 -0
  39. package/api/ray.js +3 -0
  40. package/api/rect.d.ts +3 -1
  41. package/api/rect.js +14 -2
  42. package/api/sphere.d.ts +1 -0
  43. package/api/sphere.js +3 -0
  44. package/api/text.d.ts +1 -0
  45. package/api/text.js +3 -0
  46. package/api/triangle.d.ts +3 -2
  47. package/api/triangle.js +3 -0
  48. package/apply-transforms.d.ts +33 -0
  49. package/apply-transforms.js +59 -0
  50. package/arc-length.d.ts +10 -9
  51. package/arc-length.js +11 -10
  52. package/area.d.ts +24 -23
  53. package/area.js +26 -23
  54. package/as-cubic.d.ts +36 -0
  55. package/as-cubic.js +45 -4
  56. package/as-path.d.ts +7 -0
  57. package/as-path.js +7 -0
  58. package/as-polygon.d.ts +20 -0
  59. package/as-polygon.js +20 -0
  60. package/as-polyline.d.ts +23 -0
  61. package/as-polyline.js +23 -0
  62. package/bounds.d.ts +30 -2
  63. package/bounds.js +50 -17
  64. package/center.d.ts +11 -0
  65. package/center.js +11 -0
  66. package/centroid.d.ts +27 -0
  67. package/centroid.js +32 -4
  68. package/classify-point.d.ts +23 -0
  69. package/classify-point.js +23 -0
  70. package/clip-convex.d.ts +13 -0
  71. package/clip-convex.js +16 -1
  72. package/closest-point.d.ts +26 -0
  73. package/closest-point.js +27 -0
  74. package/convex-hull.d.ts +21 -0
  75. package/convex-hull.js +27 -2
  76. package/edges.d.ts +26 -0
  77. package/edges.js +35 -0
  78. package/fit-into-bounds.d.ts +22 -3
  79. package/fit-into-bounds.js +25 -5
  80. package/flip.d.ts +23 -0
  81. package/flip.js +23 -0
  82. package/index.d.ts +3 -0
  83. package/index.js +3 -0
  84. package/internal/args.d.ts +2 -0
  85. package/internal/args.js +2 -0
  86. package/internal/bounds.d.ts +4 -4
  87. package/internal/bounds.js +4 -4
  88. package/internal/copy.d.ts +3 -1
  89. package/internal/copy.js +3 -0
  90. package/internal/dispatch.d.ts +2 -0
  91. package/internal/dispatch.js +2 -0
  92. package/internal/rotate.d.ts +5 -0
  93. package/internal/rotate.js +4 -0
  94. package/internal/scale.d.ts +5 -0
  95. package/internal/scale.js +6 -0
  96. package/intersects.d.ts +27 -2
  97. package/intersects.js +31 -1
  98. package/map-point.d.ts +15 -0
  99. package/map-point.js +15 -0
  100. package/offset.d.ts +17 -0
  101. package/offset.js +21 -5
  102. package/package.json +31 -13
  103. package/point-at.d.ts +25 -0
  104. package/point-at.js +25 -0
  105. package/point-inside.d.ts +19 -0
  106. package/point-inside.js +19 -0
  107. package/rect.d.ts +3 -1
  108. package/rect.js +7 -2
  109. package/resample.d.ts +19 -0
  110. package/resample.js +19 -0
  111. package/rotate.d.ts +30 -0
  112. package/rotate.js +79 -0
  113. package/scale.d.ts +37 -0
  114. package/scale.js +112 -0
  115. package/scatter.d.ts +13 -0
  116. package/scatter.js +13 -0
  117. package/simplify.d.ts +18 -0
  118. package/simplify.js +21 -3
  119. package/split-at.d.ts +15 -0
  120. package/split-at.js +15 -0
  121. package/split-near.d.ts +6 -6
  122. package/split-near.js +6 -6
  123. package/subdiv-curve.d.ts +17 -0
  124. package/subdiv-curve.js +17 -0
  125. package/tangent-at.d.ts +19 -0
  126. package/tangent-at.js +19 -0
  127. package/tessellate.d.ts +12 -1
  128. package/tessellate.js +11 -0
  129. package/transform-vertices.d.ts +35 -10
  130. package/transform-vertices.js +35 -10
  131. package/transform.d.ts +34 -8
  132. package/transform.js +36 -10
  133. package/translate.d.ts +29 -0
  134. package/translate.js +29 -0
  135. package/union.d.ts +10 -0
  136. package/union.js +10 -0
  137. package/unmap-point.d.ts +10 -7
  138. package/unmap-point.js +10 -7
  139. package/vertices.d.ts +29 -2
  140. package/vertices.js +33 -5
  141. package/volume.d.ts +5 -2
  142. package/volume.js +5 -2
  143. package/warp-points.d.ts +15 -1
  144. package/warp-points.js +17 -4
  145. package/with-attribs.d.ts +10 -1
  146. package/with-attribs.js +10 -4
package/bounds.d.ts CHANGED
@@ -1,4 +1,32 @@
1
- import type { MultiFn1 } from "@thi.ng/defmulti";
1
+ import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { AABBLike, IShape } from "@thi.ng/geom-api";
3
- export declare const bounds: MultiFn1<IShape, AABBLike | undefined>;
3
+ /**
4
+ * Computes and returns bounding rect/box for the given shape, optionally with
5
+ * extra uniform margin/padding (default: 0). For groups, the compound bounds of
6
+ * all children will be returned.
7
+ *
8
+ * @remarks
9
+ * Currently implemented for:
10
+ *
11
+ * - {@link AABB}
12
+ * - {@link Arc}
13
+ * - {@link BPatch}
14
+ * - {@link Circle}
15
+ * - {@link Cubic}
16
+ * - {@link Ellipse}
17
+ * - {@link Group}
18
+ * - {@link Line}
19
+ * - {@link Path}
20
+ * - {@link Polygon}
21
+ * - {@link Polyline}
22
+ * - {@link Points}
23
+ * - {@link Points3}
24
+ * - {@link Quad}
25
+ * - {@link Quadratic}
26
+ * - {@link Text} - (no way to compute size, only position & any margin)
27
+ *
28
+ * @param shape
29
+ * @param margin
30
+ */
31
+ export declare const bounds: MultiFn1O<IShape, number, AABBLike | undefined>;
4
32
  //# sourceMappingURL=bounds.d.ts.map
package/bounds.js CHANGED
@@ -7,18 +7,46 @@ import { comp } from "@thi.ng/transducers/comp";
7
7
  import { filter } from "@thi.ng/transducers/filter";
8
8
  import { iterator1 } from "@thi.ng/transducers/iterator";
9
9
  import { map } from "@thi.ng/transducers/map";
10
+ import { addN2 } from "@thi.ng/vectors/addn";
10
11
  import { max } from "@thi.ng/vectors/max";
11
12
  import { min } from "@thi.ng/vectors/min";
12
13
  import { mul2 } from "@thi.ng/vectors/mul";
13
14
  import { mulN2 } from "@thi.ng/vectors/muln";
14
- import { set2 } from "@thi.ng/vectors/set";
15
15
  import { sub2 } from "@thi.ng/vectors/sub";
16
16
  import { subN2 } from "@thi.ng/vectors/subn";
17
- import { aabbFromMinMax } from "./aabb.js";
17
+ import { aabbFromMinMaxWithMargin } from "./aabb.js";
18
18
  import { Rect } from "./api/rect.js";
19
19
  import { __collBounds } from "./internal/bounds.js";
20
20
  import { __dispatch } from "./internal/dispatch.js";
21
- import { rectFromMinMax } from "./rect.js";
21
+ import { rectFromMinMaxWithMargin } from "./rect.js";
22
+ /**
23
+ * Computes and returns bounding rect/box for the given shape, optionally with
24
+ * extra uniform margin/padding (default: 0). For groups, the compound bounds of
25
+ * all children will be returned.
26
+ *
27
+ * @remarks
28
+ * Currently implemented for:
29
+ *
30
+ * - {@link AABB}
31
+ * - {@link Arc}
32
+ * - {@link BPatch}
33
+ * - {@link Circle}
34
+ * - {@link Cubic}
35
+ * - {@link Ellipse}
36
+ * - {@link Group}
37
+ * - {@link Line}
38
+ * - {@link Path}
39
+ * - {@link Polygon}
40
+ * - {@link Polyline}
41
+ * - {@link Points}
42
+ * - {@link Points3}
43
+ * - {@link Quad}
44
+ * - {@link Quadratic}
45
+ * - {@link Text} - (no way to compute size, only position & any margin)
46
+ *
47
+ * @param shape
48
+ * @param margin
49
+ */
22
50
  export const bounds = defmulti(__dispatch, {
23
51
  aabb: "rect",
24
52
  bpatch: "points",
@@ -27,24 +55,29 @@ export const bounds = defmulti(__dispatch, {
27
55
  quad: "points",
28
56
  tri: "points",
29
57
  }, {
30
- arc: ($) => rectFromMinMax(...arcBounds($.pos, $.r, $.axis, $.start, $.end)),
31
- circle: ($) => new Rect(subN2([], $.pos, $.r), mulN2(null, [2, 2], $.r)),
32
- cubic: ({ points }) => rectFromMinMax(...cubicBounds(points[0], points[1], points[2], points[3])),
33
- ellipse: ($) => new Rect(sub2([], $.pos, $.r), mul2(null, [2, 2], $.r)),
34
- group: ($) => {
58
+ arc: ($, margin = 0) => rectFromMinMaxWithMargin(...arcBounds($.pos, $.r, $.axis, $.start, $.end), margin),
59
+ circle: ($, margin = 0) => new Rect(subN2([], $.pos, $.r + margin), mulN2(null, [2, 2], $.r + margin)),
60
+ cubic: ({ points }, margin = 0) => rectFromMinMaxWithMargin(...cubicBounds(points[0], points[1], points[2], points[3]), margin),
61
+ ellipse: ($, margin = 0) => {
62
+ const r = addN2([], $.r, margin);
63
+ return new Rect(sub2([], $.pos, r), mul2(null, [2, 2], r));
64
+ },
65
+ group: ($, margin = 0) => {
35
66
  const res = __collBounds($.children, bounds);
36
- return res ? new Rect(...res) : undefined;
67
+ return res ? new Rect(...res).offset(margin) : undefined;
37
68
  },
38
- line: ({ points: [a, b] }) => rectFromMinMax(min([], a, b), max([], a, b)),
39
- path: (path) => {
69
+ line: ({ points: [a, b] }, margin = 0) => rectFromMinMaxWithMargin(min([], a, b), max([], a, b), margin),
70
+ path: (path, margin = 0) => {
40
71
  const b = __collBounds([
41
72
  ...iterator1(comp(map((s) => s.geo), filter((s) => !!s)), path.segments),
42
73
  ], bounds);
43
- return b ? new Rect(...b) : undefined;
74
+ return b ? new Rect(...b).offset(margin) : undefined;
44
75
  },
45
- points: ($) => rectFromMinMax(...bounds2($.points)),
46
- points3: ($) => aabbFromMinMax(...bounds3($.points)),
47
- quadratic: ({ points }) => rectFromMinMax(...quadraticBounds(points[0], points[1], points[2])),
48
- rect: ($) => $.copy(),
49
- text: ($) => new Rect(set2([], $.pos), [0, 0]),
76
+ points: ($, margin = 0) => rectFromMinMaxWithMargin(...bounds2($.points), margin),
77
+ points3: ($, margin = 0) => aabbFromMinMaxWithMargin(...bounds3($.points), margin),
78
+ quadratic: ({ points }, margin = 0) => rectFromMinMaxWithMargin(...quadraticBounds(points[0], points[1], points[2]), margin),
79
+ rect: ($, margin = 0) => margin === 0
80
+ ? $.copy()
81
+ : $.copy().offset(margin),
82
+ text: ($, margin = 0) => new Rect(subN2([], $.pos, margin), margin * 2),
50
83
  });
package/center.d.ts CHANGED
@@ -1,5 +1,16 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  import { ReadonlyVec } from "@thi.ng/vectors/api";
4
+ /**
5
+ * Returns copy of given shape centered around optionally provided point `p`
6
+ * (default: worldspace origin).
7
+ *
8
+ * @remarks
9
+ * Implemented for all shape types supported by {@link centroid} and
10
+ * {@link translate}.
11
+ *
12
+ * @param shape
13
+ * @param p
14
+ */
4
15
  export declare const center: MultiFn1O<IShape, ReadonlyVec, IShape | undefined>;
5
16
  //# sourceMappingURL=center.d.ts.map
package/center.js CHANGED
@@ -10,6 +10,17 @@ import { centroid } from "./centroid.js";
10
10
  import { __copyAttribs } from "./internal/copy.js";
11
11
  import { __dispatch } from "./internal/dispatch.js";
12
12
  import { translate } from "./translate.js";
13
+ /**
14
+ * Returns copy of given shape centered around optionally provided point `p`
15
+ * (default: worldspace origin).
16
+ *
17
+ * @remarks
18
+ * Implemented for all shape types supported by {@link centroid} and
19
+ * {@link translate}.
20
+ *
21
+ * @param shape
22
+ * @param p
23
+ */
13
24
  export const center = defmulti(__dispatch, {}, {
14
25
  [DEFAULT]: ($, origin = ZERO3) => {
15
26
  const c = centroid($);
package/centroid.d.ts CHANGED
@@ -1,5 +1,32 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  import type { Vec } from "@thi.ng/vectors";
4
+ /**
5
+ * Computes centroid of given shape, writes result in optionally provided output
6
+ * vector (or creates new one if omitted).
7
+ *
8
+ * @remarks
9
+ * Currently implemented for:
10
+ *
11
+ * - {@link AABB}
12
+ * - {@link Arc}
13
+ * - {@link BPatch}
14
+ * - {@link Circle}
15
+ * - {@link Cubic}
16
+ * - {@link Ellipse}
17
+ * - {@link Group}
18
+ * - {@link Line}
19
+ * - {@link Path}
20
+ * - {@link Polygon}
21
+ * - {@link Polyline}
22
+ * - {@link Points}
23
+ * - {@link Points3}
24
+ * - {@link Quad}
25
+ * - {@link Quadratic}
26
+ * - {@link Text} - (no way to compute size, only position & any margin)
27
+ *
28
+ * @param shape
29
+ * @param out
30
+ */
4
31
  export declare const centroid: MultiFn1O<IShape, Vec, Vec | undefined>;
5
32
  //# sourceMappingURL=centroid.d.ts.map
package/centroid.js CHANGED
@@ -2,16 +2,44 @@ import { defmulti } from "@thi.ng/defmulti/defmulti";
2
2
  import { centerOfWeight2 } from "@thi.ng/geom-poly-utils/center-of-weight";
3
3
  import { centroid as _centroid } from "@thi.ng/geom-poly-utils/centroid";
4
4
  import { add } from "@thi.ng/vectors/add";
5
- import { divN } from "@thi.ng/vectors/divn";
5
+ import { addmN } from "@thi.ng/vectors/addmn";
6
6
  import { maddN } from "@thi.ng/vectors/maddn";
7
7
  import { mixN } from "@thi.ng/vectors/mixn";
8
8
  import { mulN } from "@thi.ng/vectors/muln";
9
9
  import { set } from "@thi.ng/vectors/set";
10
10
  import { bounds } from "./bounds.js";
11
11
  import { __dispatch } from "./internal/dispatch.js";
12
+ /**
13
+ * Computes centroid of given shape, writes result in optionally provided output
14
+ * vector (or creates new one if omitted).
15
+ *
16
+ * @remarks
17
+ * Currently implemented for:
18
+ *
19
+ * - {@link AABB}
20
+ * - {@link Arc}
21
+ * - {@link BPatch}
22
+ * - {@link Circle}
23
+ * - {@link Cubic}
24
+ * - {@link Ellipse}
25
+ * - {@link Group}
26
+ * - {@link Line}
27
+ * - {@link Path}
28
+ * - {@link Polygon}
29
+ * - {@link Polyline}
30
+ * - {@link Points}
31
+ * - {@link Points3}
32
+ * - {@link Quad}
33
+ * - {@link Quadratic}
34
+ * - {@link Text} - (no way to compute size, only position & any margin)
35
+ *
36
+ * @param shape
37
+ * @param out
38
+ */
12
39
  export const centroid = defmulti(__dispatch, {
13
40
  arc: "circle",
14
41
  aabb: "rect",
42
+ bpatch: "points",
15
43
  ellipse: "circle",
16
44
  line3: "line",
17
45
  points3: "points",
@@ -22,14 +50,14 @@ export const centroid = defmulti(__dispatch, {
22
50
  tri3: "tri",
23
51
  }, {
24
52
  circle: ($, out) => set(out || [], $.pos),
25
- group: ($) => {
53
+ group: ($, out) => {
26
54
  const b = bounds($);
27
- return b ? centroid(b) : undefined;
55
+ return b ? centroid(b, out) : undefined;
28
56
  },
29
57
  line: ({ points }, out) => mixN(out || [], points[0], points[1], 0.5),
30
58
  points: ($, out) => _centroid($.points, out),
31
59
  plane: ($, out) => mulN(out || [], $.normal, $.w),
32
60
  poly: ($, out) => centerOfWeight2($.points, out),
33
61
  rect: ($, out) => maddN(out || [], $.size, 0.5, $.pos),
34
- tri: ({ points }, out) => divN(null, add(null, add(out || [], points[0], points[1]), points[2]), 3),
62
+ tri: ({ points }, out) => addmN(null, add(out || [], points[0], points[1]), points[2], 1 / 3),
35
63
  });
@@ -1,5 +1,28 @@
1
1
  import type { MultiFn2O } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  import type { ReadonlyVec } from "@thi.ng/vectors";
4
+ /**
5
+ * Classifies point `p` with respect to given shape. Returns -1 if `p` is
6
+ * inside, 1 if outside or 0 if `p` is on the shape boundary (using optional
7
+ * tolerance `eps`, default: 1e-6).
8
+ *
9
+ * @remarks
10
+ * Currently only implemented for:
11
+ *
12
+ * - {@link Circle}
13
+ * - {@link Plane}
14
+ * - {@link Sphere}
15
+ * - {@link Triangle}
16
+ *
17
+ * The {@link @thi.ng/geom-sdf#} package provides a much more comprehensive
18
+ * feature set (incl. support for more shapes) to perform similar checks as this
19
+ * function.
20
+ *
21
+ * Also see {@link pointInside}.
22
+ *
23
+ * @param shape
24
+ * @param p
25
+ * @param eps
26
+ */
4
27
  export declare const classifyPoint: MultiFn2O<IShape, ReadonlyVec, number, number>;
5
28
  //# sourceMappingURL=classify-point.d.ts.map
package/classify-point.js CHANGED
@@ -4,6 +4,29 @@ import { sign } from "@thi.ng/math/abs";
4
4
  import { EPS } from "@thi.ng/math/api";
5
5
  import { dot } from "@thi.ng/vectors/dot";
6
6
  import { __dispatch } from "./internal/dispatch.js";
7
+ /**
8
+ * Classifies point `p` with respect to given shape. Returns -1 if `p` is
9
+ * inside, 1 if outside or 0 if `p` is on the shape boundary (using optional
10
+ * tolerance `eps`, default: 1e-6).
11
+ *
12
+ * @remarks
13
+ * Currently only implemented for:
14
+ *
15
+ * - {@link Circle}
16
+ * - {@link Plane}
17
+ * - {@link Sphere}
18
+ * - {@link Triangle}
19
+ *
20
+ * The {@link @thi.ng/geom-sdf#} package provides a much more comprehensive
21
+ * feature set (incl. support for more shapes) to perform similar checks as this
22
+ * function.
23
+ *
24
+ * Also see {@link pointInside}.
25
+ *
26
+ * @param shape
27
+ * @param p
28
+ * @param eps
29
+ */
7
30
  export const classifyPoint = defmulti(__dispatch, { sphere: "circle" }, {
8
31
  circle: ($, p, eps = EPS) => classifyPointInCircle(p, $.pos, $.r, eps),
9
32
  plane: ($, p, eps) => sign(dot($.normal, p) - $.w, eps),
package/clip-convex.d.ts CHANGED
@@ -1,5 +1,18 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  import type { ReadonlyVec } from "@thi.ng/vectors";
4
+ /**
5
+ * Takes a shape and a boundary (both convex). Uses the Sutherland-Hodgman
6
+ * algorithm to compute a clipped version of the first shape (against the
7
+ * boundary). Returns `undefined` if there're no remaining result vertices.
8
+ *
9
+ * @remarks
10
+ * Internally uses {@link @thi.ng/geom-clip-poly#sutherlandHodgeman}. For
11
+ * groups, calls itself for each child shape individually and returns a new
12
+ * group of results (if any).
13
+ *
14
+ * @param shape
15
+ * @param boundary
16
+ */
4
17
  export declare const clipConvex: MultiFn2<IShape, IShape | ReadonlyVec[], IShape | undefined>;
5
18
  //# sourceMappingURL=clip-convex.d.ts.map
package/clip-convex.js CHANGED
@@ -8,6 +8,19 @@ import { Polygon } from "./api/polygon.js";
8
8
  import { __copyAttribs } from "./internal/copy.js";
9
9
  import { __dispatch } from "./internal/dispatch.js";
10
10
  import { ensureVertices, vertices } from "./vertices.js";
11
+ /**
12
+ * Takes a shape and a boundary (both convex). Uses the Sutherland-Hodgman
13
+ * algorithm to compute a clipped version of the first shape (against the
14
+ * boundary). Returns `undefined` if there're no remaining result vertices.
15
+ *
16
+ * @remarks
17
+ * Internally uses {@link @thi.ng/geom-clip-poly#sutherlandHodgeman}. For
18
+ * groups, calls itself for each child shape individually and returns a new
19
+ * group of results (if any).
20
+ *
21
+ * @param shape
22
+ * @param boundary
23
+ */
11
24
  export const clipConvex = defmulti(__dispatch, {
12
25
  circle: "rect",
13
26
  ellipse: "rect",
@@ -23,7 +36,9 @@ export const clipConvex = defmulti(__dispatch, {
23
36
  if (res)
24
37
  clipped.push(res);
25
38
  }
26
- return new Group({ ...attribs }, clipped);
39
+ return clipped.length
40
+ ? new Group({ ...attribs }, clipped)
41
+ : undefined;
27
42
  },
28
43
  line: ($, boundary) => {
29
44
  const segments = clipLineSegmentPoly($.points[0], $.points[1], ensureVertices(boundary));
@@ -1,5 +1,31 @@
1
1
  import type { MultiFn2O } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
4
+ /**
5
+ * Computes closest point to `p` on boundary of given shape. Writes result in
6
+ * optionally provided output vector (or creates new one if omitted).
7
+ *
8
+ * @remarks
9
+ * Currently implemented for:
10
+ *
11
+ * - {@link AABB}
12
+ * - {@link Arc}
13
+ * - {@link Circle}
14
+ * - {@link Cubic}
15
+ * - {@link Line}
16
+ * - {@link Plane}
17
+ * - {@link Points}
18
+ * - {@link Points3}
19
+ * - {@link Polygon}
20
+ * - {@link Polyline}
21
+ * - {@link Quad}
22
+ * - {@link Quadratic}
23
+ * - {@link Rect}
24
+ * - {@link Sphere}
25
+ *
26
+ * @param shape
27
+ * @param p
28
+ * @param out
29
+ */
4
30
  export declare const closestPoint: MultiFn2O<IShape, ReadonlyVec, Vec, Vec | undefined>;
5
31
  //# sourceMappingURL=closest-point.d.ts.map
package/closest-point.js CHANGED
@@ -9,8 +9,35 @@ import { closestPointCubic } from "@thi.ng/geom-splines/cubic-closest-point";
9
9
  import { closestPointQuadratic } from "@thi.ng/geom-splines/quadratic-closest-point";
10
10
  import { add2, add3 } from "@thi.ng/vectors/add";
11
11
  import { __dispatch } from "./internal/dispatch.js";
12
+ /**
13
+ * Computes closest point to `p` on boundary of given shape. Writes result in
14
+ * optionally provided output vector (or creates new one if omitted).
15
+ *
16
+ * @remarks
17
+ * Currently implemented for:
18
+ *
19
+ * - {@link AABB}
20
+ * - {@link Arc}
21
+ * - {@link Circle}
22
+ * - {@link Cubic}
23
+ * - {@link Line}
24
+ * - {@link Plane}
25
+ * - {@link Points}
26
+ * - {@link Points3}
27
+ * - {@link Polygon}
28
+ * - {@link Polyline}
29
+ * - {@link Quad}
30
+ * - {@link Quadratic}
31
+ * - {@link Rect}
32
+ * - {@link Sphere}
33
+ *
34
+ * @param shape
35
+ * @param p
36
+ * @param out
37
+ */
12
38
  export const closestPoint = defmulti(__dispatch, {
13
39
  quad: "poly",
40
+ points3: "points",
14
41
  sphere: "circle",
15
42
  tri: "poly",
16
43
  }, {
package/convex-hull.d.ts CHANGED
@@ -1,4 +1,25 @@
1
1
  import type { MultiFn1 } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
+ /**
4
+ * Computes the convex hull for given shape and returns it as {@link Polygon}.
5
+ *
6
+ * @remarks
7
+ * Internally uses {@link @thi.ng/geom-hull#grahamScan2}.
8
+ *
9
+ * Currently implemented for:
10
+ *
11
+ * - {@link Arc}
12
+ * - {@link Circle}
13
+ * - {@link Ellipse}
14
+ * - {@link Group} (only the listed child shape types are considered)
15
+ * - {@link Points}
16
+ * - {@link Polygon}
17
+ * - {@link Polyline}
18
+ * - {@link Quad}
19
+ * - {@link Rect}
20
+ * - {@link Triangle}
21
+ *
22
+ * @param shape
23
+ */
3
24
  export declare const convexHull: MultiFn1<IShape, IShape>;
4
25
  //# sourceMappingURL=convex-hull.d.ts.map
package/convex-hull.js CHANGED
@@ -4,15 +4,40 @@ import { Polygon } from "./api/polygon.js";
4
4
  import { __copyAttribs } from "./internal/copy.js";
5
5
  import { __dispatch } from "./internal/dispatch.js";
6
6
  import { vertices } from "./vertices.js";
7
+ /**
8
+ * Computes the convex hull for given shape and returns it as {@link Polygon}.
9
+ *
10
+ * @remarks
11
+ * Internally uses {@link @thi.ng/geom-hull#grahamScan2}.
12
+ *
13
+ * Currently implemented for:
14
+ *
15
+ * - {@link Arc}
16
+ * - {@link Circle}
17
+ * - {@link Ellipse}
18
+ * - {@link Group} (only the listed child shape types are considered)
19
+ * - {@link Points}
20
+ * - {@link Polygon}
21
+ * - {@link Polyline}
22
+ * - {@link Quad}
23
+ * - {@link Rect}
24
+ * - {@link Triangle}
25
+ *
26
+ * @param shape
27
+ */
7
28
  export const convexHull = defmulti(__dispatch, {
29
+ arc: "group",
8
30
  circle: "tri",
31
+ cubic: "group",
9
32
  ellipse: "tri",
33
+ line: "tri",
10
34
  poly: "points",
11
35
  polyline: "points",
12
36
  quad: "points",
37
+ quadratic: "group",
13
38
  rect: "tri",
14
39
  }, {
15
- group: ($) => new Polygon(vertices($), __copyAttribs($)),
40
+ group: ($) => new Polygon(grahamScan2(vertices($)), __copyAttribs($)),
16
41
  points: ($) => new Polygon(grahamScan2($.points), __copyAttribs($)),
17
- tri: ($) => $.copy(),
42
+ tri: ($) => new Polygon(vertices($), __copyAttribs($)),
18
43
  });
package/edges.d.ts CHANGED
@@ -1,5 +1,31 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
3
3
  import type { VecPair } from "@thi.ng/vectors";
4
+ /**
5
+ * Extracts the edges of given shape's boundary and returns them as an iterable
6
+ * of vector pairs. Some shapes also support
7
+ * {@link @thi.ng/geom-api#SamplingOpts}.
8
+ *
9
+ * @remarks
10
+ * Currently implemented for:
11
+ *
12
+ * - {@link AABB}
13
+ * - {@link Arc}
14
+ * - {@link BPatch}
15
+ * - {@link Circle}
16
+ * - {@link Cubic}
17
+ * - {@link Ellipse}
18
+ * - {@link Line}
19
+ * - {@link Path}
20
+ * - {@link Polygon}
21
+ * - {@link Polyline}
22
+ * - {@link Quad}
23
+ * - {@link Quadratic}
24
+ * - {@link Rect}
25
+ * - {@link Triangle}
26
+ *
27
+ * @param shape
28
+ * @param opts
29
+ */
4
30
  export declare const edges: MultiFn1O<IShape, number | Partial<SamplingOpts>, Iterable<VecPair>>;
5
31
  //# sourceMappingURL=edges.d.ts.map
package/edges.js CHANGED
@@ -1,10 +1,41 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { asPolygon } from "./as-polygon.js";
3
+ import { asPolyline } from "./as-polyline.js";
2
4
  import { __dispatch } from "./internal/dispatch.js";
3
5
  import { __edges } from "./internal/edges.js";
4
6
  import { vertices } from "./vertices.js";
7
+ /**
8
+ * Extracts the edges of given shape's boundary and returns them as an iterable
9
+ * of vector pairs. Some shapes also support
10
+ * {@link @thi.ng/geom-api#SamplingOpts}.
11
+ *
12
+ * @remarks
13
+ * Currently implemented for:
14
+ *
15
+ * - {@link AABB}
16
+ * - {@link Arc}
17
+ * - {@link BPatch}
18
+ * - {@link Circle}
19
+ * - {@link Cubic}
20
+ * - {@link Ellipse}
21
+ * - {@link Line}
22
+ * - {@link Path}
23
+ * - {@link Polygon}
24
+ * - {@link Polyline}
25
+ * - {@link Quad}
26
+ * - {@link Quadratic}
27
+ * - {@link Rect}
28
+ * - {@link Triangle}
29
+ *
30
+ * @param shape
31
+ * @param opts
32
+ */
5
33
  export const edges = defmulti(__dispatch, {
34
+ cubic: "arc",
35
+ ellipse: "circle",
6
36
  line: "polyline",
7
37
  quad: "poly",
38
+ quadratic: "arc",
8
39
  tri: "poly",
9
40
  }, {
10
41
  aabb: ($) => {
@@ -24,6 +55,10 @@ export const edges = defmulti(__dispatch, {
24
55
  [d, h], // right
25
56
  ];
26
57
  },
58
+ arc: ($, opts) => __edges(asPolyline($, opts).points, false),
59
+ bpatch: ($) => $.edges(),
60
+ circle: ($, opts) => __edges(asPolygon($, opts).points, true),
61
+ path: ($, opts) => __edges(asPolygon($, opts).points, $.closed),
27
62
  poly: ($) => __edges($.points, true),
28
63
  polyline: ($) => __edges($.points),
29
64
  rect: ($) => __edges(vertices($), true),
@@ -1,7 +1,26 @@
1
1
  import type { IShape } from "@thi.ng/geom-api";
2
2
  import type { AABB } from "./api/aabb.js";
3
3
  import { Rect } from "./api/rect.js";
4
- export declare const fitIntoBounds2: (shape: IShape, dest: Rect) => IShape | undefined;
5
- export declare const fitIntoBounds3: (shape: IShape, dest: AABB) => IShape | undefined;
6
- export declare const fitAllIntoBounds2: (shapes: IShape[], dest: Rect) => IShape[] | undefined;
4
+ /**
5
+ * Uniformly rescales & repositions given 2D `shape` such that it fits into
6
+ * destination bounds. Returns transformed copy of `shape`.
7
+ *
8
+ * @param shape
9
+ * @param dest
10
+ */
11
+ export declare const fitIntoBounds2: (shape: IShape, dest: Rect) => IShape<IShape<any>> | undefined;
12
+ /**
13
+ * 3D version of {@link fitIntoBounds2}.
14
+ *
15
+ * @param shape
16
+ * @param dest
17
+ */
18
+ export declare const fitIntoBounds3: (shape: IShape, dest: AABB) => IShape<IShape<any>> | undefined;
19
+ /**
20
+ * Version of {@link fitIntoBounds2} for multiple source shapes.
21
+ *
22
+ * @param shapes
23
+ * @param dest
24
+ */
25
+ export declare const fitAllIntoBounds2: (shapes: IShape[], dest: Rect) => IShape<IShape<any>>[] | undefined;
7
26
  //# sourceMappingURL=fit-into-bounds.d.ts.map