@thi.ng/geom 3.3.1 → 3.4.2

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 (134) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/README.md +51 -5
  3. package/api/aabb.d.ts +2 -1
  4. package/api/aabb.js +6 -1
  5. package/api/apc.d.ts +3 -2
  6. package/api/arc.d.ts +1 -0
  7. package/api/arc.js +3 -0
  8. package/api/bpatch.d.ts +3 -2
  9. package/api/bpatch.js +3 -0
  10. package/api/circle.d.ts +1 -0
  11. package/api/circle.js +3 -0
  12. package/api/cubic.d.ts +3 -2
  13. package/api/cubic.js +3 -0
  14. package/api/ellipse.d.ts +1 -0
  15. package/api/ellipse.js +3 -0
  16. package/api/group.d.ts +1 -0
  17. package/api/group.js +3 -0
  18. package/api/line.d.ts +3 -2
  19. package/api/line.js +3 -0
  20. package/api/path.d.ts +1 -0
  21. package/api/path.js +5 -0
  22. package/api/plane.d.ts +1 -0
  23. package/api/plane.js +3 -0
  24. package/api/points.d.ts +5 -3
  25. package/api/points.js +6 -0
  26. package/api/polygon.d.ts +3 -2
  27. package/api/polygon.js +3 -0
  28. package/api/polyline.d.ts +2 -1
  29. package/api/polyline.js +3 -0
  30. package/api/quad.d.ts +3 -2
  31. package/api/quad.js +3 -0
  32. package/api/quad3.d.ts +3 -2
  33. package/api/quad3.js +3 -0
  34. package/api/quadratic.d.ts +3 -2
  35. package/api/quadratic.js +3 -0
  36. package/api/ray.d.ts +1 -0
  37. package/api/ray.js +3 -0
  38. package/api/rect.d.ts +2 -1
  39. package/api/rect.js +6 -1
  40. package/api/sphere.d.ts +1 -0
  41. package/api/sphere.js +3 -0
  42. package/api/text.d.ts +1 -0
  43. package/api/text.js +3 -0
  44. package/api/triangle.d.ts +3 -2
  45. package/api/triangle.js +3 -0
  46. package/apply-transforms.d.ts +33 -0
  47. package/apply-transforms.js +59 -0
  48. package/arc-length.d.ts +10 -9
  49. package/arc-length.js +11 -10
  50. package/area.d.ts +24 -23
  51. package/area.js +26 -23
  52. package/as-cubic.d.ts +36 -0
  53. package/as-cubic.js +45 -4
  54. package/as-path.d.ts +7 -0
  55. package/as-path.js +7 -0
  56. package/as-polygon.d.ts +20 -0
  57. package/as-polygon.js +20 -0
  58. package/as-polyline.d.ts +23 -0
  59. package/as-polyline.js +23 -0
  60. package/bounds.d.ts +28 -0
  61. package/bounds.js +29 -1
  62. package/center.d.ts +11 -0
  63. package/center.js +11 -0
  64. package/centroid.d.ts +27 -0
  65. package/centroid.js +32 -4
  66. package/classify-point.d.ts +23 -0
  67. package/classify-point.js +23 -0
  68. package/clip-convex.d.ts +13 -0
  69. package/clip-convex.js +16 -1
  70. package/closest-point.d.ts +26 -0
  71. package/closest-point.js +27 -0
  72. package/convex-hull.d.ts +21 -0
  73. package/convex-hull.js +27 -2
  74. package/edges.d.ts +26 -0
  75. package/edges.js +35 -0
  76. package/fit-into-bounds.d.ts +22 -3
  77. package/fit-into-bounds.js +25 -5
  78. package/flip.d.ts +23 -0
  79. package/flip.js +23 -0
  80. package/index.d.ts +3 -0
  81. package/index.js +3 -0
  82. package/internal/rotate.d.ts +5 -0
  83. package/internal/rotate.js +4 -0
  84. package/internal/scale.d.ts +5 -0
  85. package/internal/scale.js +6 -0
  86. package/intersects.d.ts +27 -2
  87. package/intersects.js +31 -1
  88. package/map-point.d.ts +15 -0
  89. package/map-point.js +15 -0
  90. package/offset.d.ts +17 -0
  91. package/offset.js +21 -5
  92. package/package.json +40 -31
  93. package/point-at.d.ts +25 -0
  94. package/point-at.js +25 -0
  95. package/point-inside.d.ts +19 -0
  96. package/point-inside.js +19 -0
  97. package/resample.d.ts +19 -0
  98. package/resample.js +19 -0
  99. package/rotate.d.ts +30 -0
  100. package/rotate.js +79 -0
  101. package/scale.d.ts +37 -0
  102. package/scale.js +112 -0
  103. package/scatter.d.ts +13 -0
  104. package/scatter.js +13 -0
  105. package/simplify.d.ts +18 -0
  106. package/simplify.js +21 -3
  107. package/split-at.d.ts +15 -0
  108. package/split-at.js +15 -0
  109. package/split-near.d.ts +6 -6
  110. package/split-near.js +6 -6
  111. package/subdiv-curve.d.ts +17 -0
  112. package/subdiv-curve.js +17 -0
  113. package/tangent-at.d.ts +19 -0
  114. package/tangent-at.js +19 -0
  115. package/tessellate.d.ts +12 -1
  116. package/tessellate.js +11 -0
  117. package/transform-vertices.d.ts +35 -10
  118. package/transform-vertices.js +35 -10
  119. package/transform.d.ts +34 -8
  120. package/transform.js +36 -10
  121. package/translate.d.ts +29 -0
  122. package/translate.js +29 -0
  123. package/union.d.ts +10 -0
  124. package/union.js +10 -0
  125. package/unmap-point.d.ts +10 -7
  126. package/unmap-point.js +10 -7
  127. package/vertices.d.ts +29 -2
  128. package/vertices.js +33 -5
  129. package/volume.d.ts +5 -2
  130. package/volume.js +5 -2
  131. package/warp-points.d.ts +15 -1
  132. package/warp-points.js +17 -4
  133. package/with-attribs.d.ts +10 -1
  134. package/with-attribs.js +10 -4
package/translate.d.ts CHANGED
@@ -1,5 +1,34 @@
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
+ * Translates given shape by given `offset` vector.
6
+ *
7
+ * @remarks
8
+ * Currently implemented for:
9
+ *
10
+ * - {@link AABB}
11
+ * - {@link Arc}
12
+ * - {@link Circle}
13
+ * - {@link Cubic}
14
+ * - {@link Ellipse}
15
+ * - {@link Group}
16
+ * - {@link Line}
17
+ * - {@link Path}
18
+ * - {@link Points}
19
+ * - {@link Points3}
20
+ * - {@link Polygon}
21
+ * - {@link Polyline}
22
+ * - {@link Quad}
23
+ * - {@link Quadratic}
24
+ * - {@link Ray}
25
+ * - {@link Rect}
26
+ * - {@link Sphere}
27
+ * - {@link Text}
28
+ * - {@link Triangle}
29
+ *
30
+ * @param shape
31
+ * @param offset
32
+ */
4
33
  export declare const translate: MultiFn2<IShape, ReadonlyVec, IShape>;
5
34
  //# sourceMappingURL=translate.d.ts.map
package/translate.js CHANGED
@@ -20,6 +20,35 @@ import { Triangle } from "./api/triangle.js";
20
20
  import { __copyAttribs } from "./internal/copy.js";
21
21
  import { __dispatch } from "./internal/dispatch.js";
22
22
  import { __translatedShape as tx } from "./internal/translate.js";
23
+ /**
24
+ * Translates given shape by given `offset` vector.
25
+ *
26
+ * @remarks
27
+ * Currently implemented for:
28
+ *
29
+ * - {@link AABB}
30
+ * - {@link Arc}
31
+ * - {@link Circle}
32
+ * - {@link Cubic}
33
+ * - {@link Ellipse}
34
+ * - {@link Group}
35
+ * - {@link Line}
36
+ * - {@link Path}
37
+ * - {@link Points}
38
+ * - {@link Points3}
39
+ * - {@link Polygon}
40
+ * - {@link Polyline}
41
+ * - {@link Quad}
42
+ * - {@link Quadratic}
43
+ * - {@link Ray}
44
+ * - {@link Rect}
45
+ * - {@link Sphere}
46
+ * - {@link Text}
47
+ * - {@link Triangle}
48
+ *
49
+ * @param shape
50
+ * @param offset
51
+ */
23
52
  export const translate = defmulti(__dispatch, {}, {
24
53
  aabb: ($, delta) => new AABB(add3([], $.pos, delta), set3([], $.size), __copyAttribs($)),
25
54
  arc: ($, delta) => {
package/union.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
+ /**
4
+ * Computes shape "union" of given 2 shapes.
5
+ *
6
+ * @remarks
7
+ * Currently only implemented for {@link AABB} and {@link Rect} to compute union
8
+ * bounding boxes.
9
+ *
10
+ * @param a
11
+ * @param b
12
+ */
3
13
  export declare const union: MultiFn2<IShape, IShape, IShape[]>;
4
14
  //# sourceMappingURL=union.d.ts.map
package/union.js CHANGED
@@ -3,6 +3,16 @@ import { AABB } from "./api/aabb.js";
3
3
  import { Rect } from "./api/rect.js";
4
4
  import { __unionBounds } from "./internal/bounds.js";
5
5
  import { __dispatch } from "./internal/dispatch.js";
6
+ /**
7
+ * Computes shape "union" of given 2 shapes.
8
+ *
9
+ * @remarks
10
+ * Currently only implemented for {@link AABB} and {@link Rect} to compute union
11
+ * bounding boxes.
12
+ *
13
+ * @param a
14
+ * @param b
15
+ */
6
16
  export const union = defmulti(__dispatch, {}, {
7
17
  aabb: (a, b) => [
8
18
  new AABB(...__unionBounds(a.pos, a.size, b.pos, b.size)),
package/unmap-point.d.ts CHANGED
@@ -2,16 +2,19 @@ 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
4
  /**
5
- * Projects given point `uv` (normalized coords) into the target space
6
- * defined by `shape` and writes result to `out` (or returns new
7
- * vector). See {@link mapPoint} for reverse operation. Both functions
8
- * together can be used to warp points from one shape into another.
5
+ * Projects given point `uv` (normalized coords) into the target space defined
6
+ * by `shape` and writes result to `out` (or returns new vector).
7
+ *
8
+ * @remarks
9
+ * See {@link mapPoint} for reverse operation. Both functions together can be
10
+ * used to warp points from one shape into another.
9
11
  *
10
12
  * Currently only implemented for these shape types:
11
13
  *
12
- * - AABB
13
- * - Quad
14
- * - Rect
14
+ * - {@link AABB}
15
+ * - {@link Quad}
16
+ * - {@link Quad3}
17
+ * - {@link Rect}
15
18
  *
16
19
  * @param shape - shape to operate on
17
20
  * @param uv - point to map in UV space
package/unmap-point.js CHANGED
@@ -3,16 +3,19 @@ import { madd } from "@thi.ng/vectors/madd";
3
3
  import { mixBilinear } from "@thi.ng/vectors/mix-bilinear";
4
4
  import { __dispatch } from "./internal/dispatch.js";
5
5
  /**
6
- * Projects given point `uv` (normalized coords) into the target space
7
- * defined by `shape` and writes result to `out` (or returns new
8
- * vector). See {@link mapPoint} for reverse operation. Both functions
9
- * together can be used to warp points from one shape into another.
6
+ * Projects given point `uv` (normalized coords) into the target space defined
7
+ * by `shape` and writes result to `out` (or returns new vector).
8
+ *
9
+ * @remarks
10
+ * See {@link mapPoint} for reverse operation. Both functions together can be
11
+ * used to warp points from one shape into another.
10
12
  *
11
13
  * Currently only implemented for these shape types:
12
14
  *
13
- * - AABB
14
- * - Quad
15
- * - Rect
15
+ * - {@link AABB}
16
+ * - {@link Quad}
17
+ * - {@link Quad3}
18
+ * - {@link Rect}
16
19
  *
17
20
  * @param shape - shape to operate on
18
21
  * @param uv - point to map in UV space
package/vertices.d.ts CHANGED
@@ -2,10 +2,37 @@ import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  import { SamplingOpts } from "@thi.ng/geom-api/sample";
4
4
  import type { Vec } from "@thi.ng/vectors";
5
+ /**
6
+ * Extracts/samples vertices from given shape's boundary and returns them as
7
+ * array. Some shapes also support {@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 Group}
19
+ * - {@link Line}
20
+ * - {@link Path}
21
+ * - {@link Points}
22
+ * - {@link Points3}
23
+ * - {@link Quad}
24
+ * - {@link Quadratic}
25
+ * - {@link Rect}
26
+ * - {@link Triangle}
27
+ *
28
+ * @param shape
29
+ * @param opts
30
+ */
5
31
  export declare const vertices: MultiFn1O<IShape, number | Partial<SamplingOpts>, Vec[]>;
6
32
  /**
7
- * Takes array of vectors or an `IShape`. If the latter, calls {@link vertices}
8
- * and return result, else returns original array.
33
+ * Takes an array of vertices or an `IShape`. If the latter, calls
34
+ * {@link vertices} with default options and returns result, else returns
35
+ * original array.
9
36
  *
10
37
  * @param shape -
11
38
  */
package/vertices.js CHANGED
@@ -14,6 +14,32 @@ import { madd2 } from "@thi.ng/vectors/madd";
14
14
  import { set2 } from "@thi.ng/vectors/set";
15
15
  import { Polygon } from "./api/polygon.js";
16
16
  import { __dispatch } from "./internal/dispatch.js";
17
+ /**
18
+ * Extracts/samples vertices from given shape's boundary and returns them as
19
+ * array. Some shapes also support {@link @thi.ng/geom-api#SamplingOpts}.
20
+ *
21
+ * @remarks
22
+ * Currently implemented for:
23
+ *
24
+ * - {@link AABB}
25
+ * - {@link Arc}
26
+ * - {@link BPatch}
27
+ * - {@link Circle}
28
+ * - {@link Cubic}
29
+ * - {@link Ellipse}
30
+ * - {@link Group}
31
+ * - {@link Line}
32
+ * - {@link Path}
33
+ * - {@link Points}
34
+ * - {@link Points3}
35
+ * - {@link Quad}
36
+ * - {@link Quadratic}
37
+ * - {@link Rect}
38
+ * - {@link Triangle}
39
+ *
40
+ * @param shape
41
+ * @param opts
42
+ */
17
43
  export const vertices = defmulti(__dispatch, {
18
44
  line: "polyline",
19
45
  bpatch: "points",
@@ -47,7 +73,7 @@ export const vertices = defmulti(__dispatch, {
47
73
  circle: ($, opts = DEFAULT_SAMPLES) => {
48
74
  const pos = $.pos;
49
75
  const r = $.r;
50
- let [num, last] = circleOpts(opts, r);
76
+ let [num, last] = __circleOpts(opts, r);
51
77
  const delta = TAU / num;
52
78
  last && num++;
53
79
  const buf = new Array(num);
@@ -61,7 +87,7 @@ export const vertices = defmulti(__dispatch, {
61
87
  const buf = [];
62
88
  const pos = $.pos;
63
89
  const r = $.r;
64
- let [num, last] = circleOpts(opts, Math.max($.r[0], $.r[1]));
90
+ let [num, last] = __circleOpts(opts, Math.max($.r[0], $.r[1]));
65
91
  const delta = TAU / num;
66
92
  last && num++;
67
93
  for (let i = 0; i < num; i++) {
@@ -96,13 +122,15 @@ export const vertices = defmulti(__dispatch, {
96
122
  },
97
123
  });
98
124
  /**
99
- * Takes array of vectors or an `IShape`. If the latter, calls {@link vertices}
100
- * and return result, else returns original array.
125
+ * Takes an array of vertices or an `IShape`. If the latter, calls
126
+ * {@link vertices} with default options and returns result, else returns
127
+ * original array.
101
128
  *
102
129
  * @param shape -
103
130
  */
104
131
  export const ensureVertices = (shape) => isArray(shape) ? shape : vertices(shape);
105
- const circleOpts = (opts, r) => isNumber(opts)
132
+ /** @internal */
133
+ const __circleOpts = (opts, r) => isNumber(opts)
106
134
  ? [opts, false]
107
135
  : [
108
136
  opts.theta
package/volume.d.ts CHANGED
@@ -3,10 +3,13 @@ import type { IShape } from "@thi.ng/geom-api";
3
3
  /**
4
4
  * Returns the volume of given 3D shape. Returns 0 for all others.
5
5
  *
6
+ * @remarks
6
7
  * Currently only implemented for:
7
8
  *
8
- * - AABB
9
- * - Sphere
9
+ * - {@link AABB}
10
+ * - {@link Sphere}
11
+ *
12
+ * @param shape
10
13
  */
11
14
  export declare const volume: MultiFn1<IShape, number>;
12
15
  //# sourceMappingURL=volume.d.ts.map
package/volume.js CHANGED
@@ -4,10 +4,13 @@ import { __dispatch } from "./internal/dispatch.js";
4
4
  /**
5
5
  * Returns the volume of given 3D shape. Returns 0 for all others.
6
6
  *
7
+ * @remarks
7
8
  * Currently only implemented for:
8
9
  *
9
- * - AABB
10
- * - Sphere
10
+ * - {@link AABB}
11
+ * - {@link Sphere}
12
+ *
13
+ * @param shape
11
14
  */
12
15
  export const volume = defmulti(__dispatch, {}, {
13
16
  [DEFAULT]: () => 0,
package/warp-points.d.ts CHANGED
@@ -2,6 +2,20 @@ import type { IShape } from "@thi.ng/geom-api";
2
2
  import type { ReadonlyVec, Vec } from "@thi.ng/vectors/api";
3
3
  import type { BPatch } from "./api/bpatch.js";
4
4
  import type { Rect } from "./api/rect.js";
5
- export declare const warpPoints: (pts: ReadonlyVec[], dest: IShape, src: IShape) => Vec[];
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).
9
+ *
10
+ * @remarks
11
+ * The type of `src` must be supported by {@link mapPoint}. The type of `dest`
12
+ * must be supported by {@link unmapPoint}.
13
+ *
14
+ * @param pts
15
+ * @param dest
16
+ * @param src
17
+ * @param out
18
+ */
19
+ export declare const warpPoints: (pts: ReadonlyVec[], dest: IShape, src: IShape, out?: Vec[]) => Vec[];
6
20
  export declare const warpPointsBPatch: (pts: ReadonlyVec[], dest: BPatch, src?: Rect, out?: Vec[]) => Vec[];
7
21
  //# sourceMappingURL=warp-points.d.ts.map
package/warp-points.js CHANGED
@@ -2,12 +2,25 @@ 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
- export const warpPoints = (pts, dest, src) => {
6
- const res = [];
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).
9
+ *
10
+ * @remarks
11
+ * The type of `src` must be supported by {@link mapPoint}. The type of `dest`
12
+ * must be supported by {@link unmapPoint}.
13
+ *
14
+ * @param pts
15
+ * @param dest
16
+ * @param src
17
+ * @param out
18
+ */
19
+ export const warpPoints = (pts, dest, src, out = []) => {
7
20
  for (let n = pts.length, i = 0; i < n; i++) {
8
- res.push(unmapPoint(dest, mapPoint(src, pts[i])));
21
+ out.push(unmapPoint(dest, mapPoint(src, pts[i])));
9
22
  }
10
- return res;
23
+ return out;
11
24
  };
12
25
  export const warpPointsBPatch = (pts, dest, src, out = []) => {
13
26
  src = src || rectFromMinMax(...bounds2(pts));
package/with-attribs.d.ts CHANGED
@@ -1,3 +1,12 @@
1
1
  import type { Attribs, IShape } from "@thi.ng/geom-api";
2
- export declare const withAttribs: <T extends IShape>(shape: T, attribs: Attribs, replace?: boolean) => T;
2
+ /**
3
+ * Returns a shallow copy of given shape with new `attribs` assigned (using
4
+ * {@link @thi.ng/geom-api#IAttributed.withAttribs}). If `replace` is false, the
5
+ * new attribs will be merged with the existing ones (if any).
6
+ *
7
+ * @param shape
8
+ * @param attribs
9
+ * @param replace
10
+ */
11
+ export declare const withAttribs: <T extends IShape<IShape<any>>>(shape: T, attribs: Attribs, replace?: boolean) => IShape<any>;
3
12
  //# sourceMappingURL=with-attribs.d.ts.map
package/with-attribs.js CHANGED
@@ -1,4 +1,10 @@
1
- export const withAttribs = (shape, attribs, replace = true) => {
2
- shape.attribs = replace ? attribs : { ...shape.attribs, ...attribs };
3
- return shape;
4
- };
1
+ /**
2
+ * Returns a shallow copy of given shape with new `attribs` assigned (using
3
+ * {@link @thi.ng/geom-api#IAttributed.withAttribs}). If `replace` is false, the
4
+ * new attribs will be merged with the existing ones (if any).
5
+ *
6
+ * @param shape
7
+ * @param attribs
8
+ * @param replace
9
+ */
10
+ export const withAttribs = (shape, attribs, replace = true) => shape.withAttribs(replace ? attribs : { ...shape.attribs, ...attribs });