@thi.ng/geom 3.3.1 → 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 (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 +21 -12
  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/scatter.d.ts CHANGED
@@ -1,4 +1,17 @@
1
1
  import type { IShape } from "@thi.ng/geom-api";
2
2
  import type { Vec } from "@thi.ng/vectors";
3
+ /**
4
+ * Produces `num` random points for which {@link pointInside} succeeeds for the
5
+ * given `shape`. Writes results into `out` array (or creates a new one).
6
+ *
7
+ * @remarks
8
+ * Samples are only created with the shapes bounding box and are chosen using
9
+ * optionall yprovided `rnd` {@link @thi.ng/random#IRandom} instance.
10
+ *
11
+ * @param shape
12
+ * @param num
13
+ * @param rnd
14
+ * @param out
15
+ */
3
16
  export declare const scatter: (shape: IShape, num: number, rnd?: import("@thi.ng/random/system").SystemRandom, out?: Vec[]) => Vec[] | undefined;
4
17
  //# sourceMappingURL=scatter.d.ts.map
package/scatter.js CHANGED
@@ -2,6 +2,19 @@ import { SYSTEM } from "@thi.ng/random/system";
2
2
  import { randMinMax } from "@thi.ng/vectors/random";
3
3
  import { bounds } from "./bounds.js";
4
4
  import { pointInside } from "./point-inside.js";
5
+ /**
6
+ * Produces `num` random points for which {@link pointInside} succeeeds for the
7
+ * given `shape`. Writes results into `out` array (or creates a new one).
8
+ *
9
+ * @remarks
10
+ * Samples are only created with the shapes bounding box and are chosen using
11
+ * optionall yprovided `rnd` {@link @thi.ng/random#IRandom} instance.
12
+ *
13
+ * @param shape
14
+ * @param num
15
+ * @param rnd
16
+ * @param out
17
+ */
5
18
  export const scatter = (shape, num, rnd = SYSTEM, out = []) => {
6
19
  const b = bounds(shape);
7
20
  if (!b)
package/simplify.d.ts CHANGED
@@ -1,4 +1,22 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
+ /**
4
+ * Simplifies given 2D shape boundary using Douglas-Peucker algorithm
5
+ * (implemented by {@link @thi.ng/geom-resample#simplify}) and given `threshold`
6
+ * distance (default: 0, which removes only co-linear vertices).
7
+ *
8
+ * @remarks
9
+ * Currently only implemented for:
10
+ *
11
+ * - {@link Path}
12
+ * - {@link Polygon}
13
+ * - {@link Polyline}
14
+ *
15
+ * Use {@link asPath}, {@link asPolygon} or {@link asPolyline} to convert other
16
+ * shape types first.
17
+ *
18
+ * @param shape
19
+ * @param threshold
20
+ */
3
21
  export declare const simplify: MultiFn2<IShape, number, IShape>;
4
22
  //# sourceMappingURL=simplify.d.ts.map
package/simplify.js CHANGED
@@ -7,8 +7,26 @@ import { Polyline } from "./api/polyline.js";
7
7
  import { __copyAttribs } from "./internal/copy.js";
8
8
  import { __dispatch } from "./internal/dispatch.js";
9
9
  import { vertices } from "./vertices.js";
10
+ /**
11
+ * Simplifies given 2D shape boundary using Douglas-Peucker algorithm
12
+ * (implemented by {@link @thi.ng/geom-resample#simplify}) and given `threshold`
13
+ * distance (default: 0, which removes only co-linear vertices).
14
+ *
15
+ * @remarks
16
+ * Currently only implemented for:
17
+ *
18
+ * - {@link Path}
19
+ * - {@link Polygon}
20
+ * - {@link Polyline}
21
+ *
22
+ * Use {@link asPath}, {@link asPolygon} or {@link asPolyline} to convert other
23
+ * shape types first.
24
+ *
25
+ * @param shape
26
+ * @param threshold
27
+ */
10
28
  export const simplify = defmulti(__dispatch, {}, {
11
- path: ($, eps = 0.1) => {
29
+ path: ($, eps = 0) => {
12
30
  const res = [];
13
31
  const orig = $.segments;
14
32
  const n = orig.length;
@@ -43,6 +61,6 @@ export const simplify = defmulti(__dispatch, {}, {
43
61
  }
44
62
  return new Path(res, __copyAttribs($));
45
63
  },
46
- poly: ($, eps = 0.1) => new Polygon(_simplify($.points, eps, true), __copyAttribs($)),
47
- polyline: ($, eps = 0.1) => new Polyline(_simplify($.points, eps), __copyAttribs($)),
64
+ poly: ($, eps = 0) => new Polygon(_simplify($.points, eps, true), __copyAttribs($)),
65
+ polyline: ($, eps = 0) => new Polyline(_simplify($.points, eps), __copyAttribs($)),
48
66
  });
package/split-at.d.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  import type { MultiFn2 } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
+ /**
4
+ * Splits given shape in 2 parts at normalized parametric position `t`.
5
+ *
6
+ * @remarks
7
+ * Currently only implemented for:
8
+ *
9
+ * - {@link Arc}
10
+ * - {@link Cubic}
11
+ * - {@link Line}
12
+ * - {@link Polyline}
13
+ * - {@link Quadratic}
14
+ *
15
+ * @param shape
16
+ * @param t
17
+ */
3
18
  export declare const splitAt: MultiFn2<IShape, number, IShape[] | undefined>;
4
19
  //# sourceMappingURL=split-at.d.ts.map
package/split-at.js CHANGED
@@ -13,6 +13,21 @@ import { __copyAttribs } from "./internal/copy.js";
13
13
  import { __dispatch } from "./internal/dispatch.js";
14
14
  import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
15
15
  import { __splitLine } from "./internal/split.js";
16
+ /**
17
+ * Splits given shape in 2 parts at normalized parametric position `t`.
18
+ *
19
+ * @remarks
20
+ * Currently only implemented for:
21
+ *
22
+ * - {@link Arc}
23
+ * - {@link Cubic}
24
+ * - {@link Line}
25
+ * - {@link Polyline}
26
+ * - {@link Quadratic}
27
+ *
28
+ * @param shape
29
+ * @param t
30
+ */
16
31
  export const splitAt = defmulti(__dispatch, {}, {
17
32
  arc: ($, t) => {
18
33
  const theta = fit01(t, $.start, $.end);
package/split-near.d.ts CHANGED
@@ -4,14 +4,14 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
4
4
  /**
5
5
  * Similar to {@link splitAt}, but instead of taking a normalized parametric
6
6
  * split position, splits the given curve at the closest point to `p`.
7
- * Returns tuple of split shapes of same type as `shape`.
8
7
  *
9
- * Implemented for:
8
+ * @remarks
9
+ * Currently only implemented for:
10
10
  *
11
- * - Cubic
12
- * - Line
13
- * - Polyline
14
- * - Quadratic
11
+ * - {@link Cubic}
12
+ * - {@link Line}
13
+ * - {@link Polyline}
14
+ * - {@link Quadratic}
15
15
  *
16
16
  * @param shape - shape to operate on
17
17
  * @param p - split point
package/split-near.js CHANGED
@@ -15,14 +15,14 @@ import { __splitLine } from "./internal/split.js";
15
15
  /**
16
16
  * Similar to {@link splitAt}, but instead of taking a normalized parametric
17
17
  * split position, splits the given curve at the closest point to `p`.
18
- * Returns tuple of split shapes of same type as `shape`.
19
18
  *
20
- * Implemented for:
19
+ * @remarks
20
+ * Currently only implemented for:
21
21
  *
22
- * - Cubic
23
- * - Line
24
- * - Polyline
25
- * - Quadratic
22
+ * - {@link Cubic}
23
+ * - {@link Line}
24
+ * - {@link Polyline}
25
+ * - {@link Quadratic}
26
26
  *
27
27
  * @param shape - shape to operate on
28
28
  * @param p - split point
package/subdiv-curve.d.ts CHANGED
@@ -1,4 +1,21 @@
1
1
  import type { MultiFn2O } from "@thi.ng/defmulti";
2
2
  import type { IShape, SubdivKernel } from "@thi.ng/geom-api";
3
+ /**
4
+ * Recursively applies {@link @thi.ng/geom-api#SubdivKernel} to given
5
+ * shape/boundary. See {@link @thi.ng/geom-subdiv-curve#} package for further
6
+ * details.
7
+ *
8
+ * @remarks
9
+ * By default only applies a single iteration.
10
+ *
11
+ * Currently only implemented for:
12
+ *
13
+ * - {@link Polygon}
14
+ * - {@link Polyline}
15
+ *
16
+ * @param shape
17
+ * @param kernel
18
+ * @param iter
19
+ */
3
20
  export declare const subdivCurve: MultiFn2O<IShape, SubdivKernel, number, IShape>;
4
21
  //# sourceMappingURL=subdiv-curve.d.ts.map
package/subdiv-curve.js CHANGED
@@ -4,6 +4,23 @@ import { Polygon } from "./api/polygon.js";
4
4
  import { Polyline } from "./api/polyline.js";
5
5
  import { __copyAttribs } from "./internal/copy.js";
6
6
  import { __dispatch } from "./internal/dispatch.js";
7
+ /**
8
+ * Recursively applies {@link @thi.ng/geom-api#SubdivKernel} to given
9
+ * shape/boundary. See {@link @thi.ng/geom-subdiv-curve#} package for further
10
+ * details.
11
+ *
12
+ * @remarks
13
+ * By default only applies a single iteration.
14
+ *
15
+ * Currently only implemented for:
16
+ *
17
+ * - {@link Polygon}
18
+ * - {@link Polyline}
19
+ *
20
+ * @param shape
21
+ * @param kernel
22
+ * @param iter
23
+ */
7
24
  export const subdivCurve = defmulti(__dispatch, {}, {
8
25
  poly: ($, kernel, iter = 1) => new Polygon(subdivide($.points, kernel, iter), __copyAttribs($)),
9
26
  polyline: ($, kernel, iter = 1) => new Polyline(subdivide($.points, kernel, iter), __copyAttribs($)),
package/tangent-at.d.ts CHANGED
@@ -1,5 +1,24 @@
1
1
  import type { MultiFn2 } 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 tangent on shape/boundary at normalized parametric position `t`.
6
+ *
7
+ * @remarks
8
+ * Currently implemented for:
9
+ *
10
+ * - {@link Circle}
11
+ * - {@link Cubic}
12
+ * - {@link Line}
13
+ * - {@link Polygon}
14
+ * - {@link Polyline}
15
+ * - {@link Quad}
16
+ * - {@link Quadratic}
17
+ * - {@link Rect}
18
+ * - {@link Triangle}
19
+ *
20
+ * @param shape
21
+ * @param t
22
+ */
4
23
  export declare const tangentAt: MultiFn2<IShape, number, Vec | undefined>;
5
24
  //# sourceMappingURL=tangent-at.d.ts.map
package/tangent-at.js CHANGED
@@ -7,6 +7,25 @@ import { HALF_PI, TAU } from "@thi.ng/math/api";
7
7
  import { direction } from "@thi.ng/vectors/direction";
8
8
  import { __dispatch } from "./internal/dispatch.js";
9
9
  import { vertices } from "./vertices.js";
10
+ /**
11
+ * Computes tangent on shape/boundary at normalized parametric position `t`.
12
+ *
13
+ * @remarks
14
+ * Currently implemented for:
15
+ *
16
+ * - {@link Circle}
17
+ * - {@link Cubic}
18
+ * - {@link Line}
19
+ * - {@link Polygon}
20
+ * - {@link Polyline}
21
+ * - {@link Quad}
22
+ * - {@link Quadratic}
23
+ * - {@link Rect}
24
+ * - {@link Triangle}
25
+ *
26
+ * @param shape
27
+ * @param t
28
+ */
10
29
  export const tangentAt = defmulti(__dispatch, {
11
30
  quad: "poly",
12
31
  tri: "poly",
package/tessellate.d.ts CHANGED
@@ -1,4 +1,15 @@
1
1
  import type { IShape, Tessellator } from "@thi.ng/geom-api";
2
2
  import type { Vec } from "@thi.ng/vectors";
3
- export declare const tessellate: import("@thi.ng/defmulti").MultiFn2<IShape, Tessellator[], Vec[][]>;
3
+ /**
4
+ * Recursively tessellates shape using provided
5
+ * {@link @thi.ng/geom-api#Tessellator} functions. See
6
+ * {@link @thi.ng/geom-tessellate#} package for more details.
7
+ *
8
+ * @remarks
9
+ * Implemented for all shapes supported by {@link vertices}.
10
+ *
11
+ * @param shape
12
+ * @param tessellators
13
+ */
14
+ export declare const tessellate: import("@thi.ng/defmulti").MultiFn2<IShape<IShape<any>>, Tessellator[], Vec[][]>;
4
15
  //# sourceMappingURL=tessellate.d.ts.map
package/tessellate.js CHANGED
@@ -2,6 +2,17 @@ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
2
2
  import { tessellate as _tessellate } from "@thi.ng/geom-tessellate/tessellate";
3
3
  import { __dispatch } from "./internal/dispatch.js";
4
4
  import { vertices } from "./vertices.js";
5
+ /**
6
+ * Recursively tessellates shape using provided
7
+ * {@link @thi.ng/geom-api#Tessellator} functions. See
8
+ * {@link @thi.ng/geom-tessellate#} package for more details.
9
+ *
10
+ * @remarks
11
+ * Implemented for all shapes supported by {@link vertices}.
12
+ *
13
+ * @param shape
14
+ * @param tessellators
15
+ */
5
16
  export const tessellate = defmulti(__dispatch, {}, {
6
17
  [DEFAULT]: ($, fns) => _tessellate(vertices($), fns),
7
18
  });
@@ -4,17 +4,42 @@ import type { IShape } from "@thi.ng/geom-api";
4
4
  import type { ReadonlyMat } from "@thi.ng/matrices";
5
5
  import type { ReadonlyVec } from "@thi.ng/vectors";
6
6
  /**
7
- * Transforms vertices of given shape with provided function, which is
8
- * being called for each vertex individually and should produce a
9
- * transformation matrix. Some shape types will be automatically
10
- * converted to other types prior to transformation because they cannot
11
- * be reliably represented in their original type anymore, this
12
- * includes:
7
+ * Similar to {@link transform}. Transforms vertices of given shape with
8
+ * provided function, which is being called for each vertex individually and
9
+ * should produce a transformation matrix.
13
10
  *
14
- * - Arc => Path (cubics)
15
- * - Circle => Path (cubics)
16
- * - Ellipse => Path (cubics)
17
- * - Rect => Polygon
11
+ * @remark
12
+ * Some shape types will be automatically converted to other types prior to
13
+ * transformation because they cannot be reliably represented in their original
14
+ * type anymore, this includes:
15
+ *
16
+ * - {@link Arc} => {@link Path} (cubics)
17
+ * - {@link Circle} => {@link Path} (cubics)
18
+ * - {@link Ellipse} => {@link Path} (cubics)
19
+ * - {@link Rect} => {@link Polygon}
20
+ *
21
+ * Currently implemented for:
22
+ *
23
+ * - {@link Arc}
24
+ * - {@link Circle}
25
+ * - {@link Cubic}
26
+ * - {@link Ellipse}
27
+ * - {@link Group}
28
+ * - {@link Line}
29
+ * - {@link Path}
30
+ * - {@link Points}
31
+ * - {@link Points3}
32
+ * - {@link Polygon}
33
+ * - {@link Polyline}
34
+ * - {@link Quad}
35
+ * - {@link Quadratic}
36
+ * - {@link Ray}
37
+ * - {@link Rect}
38
+ * - {@link Text}
39
+ * - {@link Triangle}
40
+ *
41
+ * @param shape
42
+ * @param fn
18
43
  */
19
44
  export declare const transformVertices: MultiFn2<IShape, Fn<ReadonlyVec, ReadonlyMat>, IShape>;
20
45
  //# sourceMappingURL=transform-vertices.d.ts.map
@@ -16,17 +16,42 @@ import { __copyAttribs } from "./internal/copy.js";
16
16
  import { __dispatch } from "./internal/dispatch.js";
17
17
  import { __transformedShapePoints as tx, __transformedShapePoints3 as tx3, } from "./internal/transform.js";
18
18
  /**
19
- * Transforms vertices of given shape with provided function, which is
20
- * being called for each vertex individually and should produce a
21
- * transformation matrix. Some shape types will be automatically
22
- * converted to other types prior to transformation because they cannot
23
- * be reliably represented in their original type anymore, this
24
- * includes:
19
+ * Similar to {@link transform}. Transforms vertices of given shape with
20
+ * provided function, which is being called for each vertex individually and
21
+ * should produce a transformation matrix.
25
22
  *
26
- * - Arc => Path (cubics)
27
- * - Circle => Path (cubics)
28
- * - Ellipse => Path (cubics)
29
- * - Rect => Polygon
23
+ * @remark
24
+ * Some shape types will be automatically converted to other types prior to
25
+ * transformation because they cannot be reliably represented in their original
26
+ * type anymore, this includes:
27
+ *
28
+ * - {@link Arc} => {@link Path} (cubics)
29
+ * - {@link Circle} => {@link Path} (cubics)
30
+ * - {@link Ellipse} => {@link Path} (cubics)
31
+ * - {@link Rect} => {@link Polygon}
32
+ *
33
+ * Currently implemented for:
34
+ *
35
+ * - {@link Arc}
36
+ * - {@link Circle}
37
+ * - {@link Cubic}
38
+ * - {@link Ellipse}
39
+ * - {@link Group}
40
+ * - {@link Line}
41
+ * - {@link Path}
42
+ * - {@link Points}
43
+ * - {@link Points3}
44
+ * - {@link Polygon}
45
+ * - {@link Polyline}
46
+ * - {@link Quad}
47
+ * - {@link Quadratic}
48
+ * - {@link Ray}
49
+ * - {@link Rect}
50
+ * - {@link Text}
51
+ * - {@link Triangle}
52
+ *
53
+ * @param shape
54
+ * @param fn
30
55
  */
31
56
  export const transformVertices = defmulti(__dispatch, {
32
57
  circle: "rect",
package/transform.d.ts CHANGED
@@ -2,15 +2,41 @@ import type { MultiFn2 } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  import type { ReadonlyMat } from "@thi.ng/matrices";
4
4
  /**
5
- * Transforms given shape with provided matrix. Some shape types will be
6
- * automatically converted to other types prior to transformation because they
7
- * cannot be reliably represented in their original type anymore, this
8
- * includes:
5
+ * Transforms given shape with provided matrix.
9
6
  *
10
- * - Arc => Path (cubics)
11
- * - Circle => Path (cubics)
12
- * - Ellipse => Path (cubics)
13
- * - Rect => Polygon
7
+ * @remarks
8
+ * A 2x3 transform matrix is assumed for 2D shapes and 4x4 matrix for 3D shapes.
9
+ * Some shape types will be automatically converted to other types prior to
10
+ * transformation because they cannot be reliably represented in their original
11
+ * type anymore, this includes:
12
+ *
13
+ * - {@link Arc} => {@link Path} (cubics)
14
+ * - {@link Circle} => {@link Path} (cubics)
15
+ * - {@link Ellipse} => {@link Path} (cubics)
16
+ * - {@link Rect} => {@link Quad}
17
+ *
18
+ * Currently implemented for:
19
+ *
20
+ * - {@link Arc}
21
+ * - {@link Circle}
22
+ * - {@link Cubic}
23
+ * - {@link Ellipse}
24
+ * - {@link Group}
25
+ * - {@link Line}
26
+ * - {@link Path}
27
+ * - {@link Points}
28
+ * - {@link Points3}
29
+ * - {@link Polygon}
30
+ * - {@link Polyline}
31
+ * - {@link Quad}
32
+ * - {@link Quadratic}
33
+ * - {@link Ray}
34
+ * - {@link Rect}
35
+ * - {@link Text}
36
+ * - {@link Triangle}
37
+ *
38
+ * @param shape
39
+ * @param mat
14
40
  */
15
41
  export declare const transform: MultiFn2<IShape, ReadonlyMat, IShape>;
16
42
  //# sourceMappingURL=transform.d.ts.map
package/transform.js CHANGED
@@ -12,20 +12,46 @@ import { Quadratic } from "./api/quadratic.js";
12
12
  import { Text } from "./api/text.js";
13
13
  import { Triangle } from "./api/triangle.js";
14
14
  import { asPath } from "./as-path.js";
15
- import { asPolygon } from "./as-polygon.js";
16
15
  import { __copyAttribs } from "./internal/copy.js";
17
16
  import { __dispatch } from "./internal/dispatch.js";
18
17
  import { __transformedShape as tx, __transformedShape3 as tx3, } from "./internal/transform.js";
18
+ import { vertices } from "./vertices.js";
19
19
  /**
20
- * Transforms given shape with provided matrix. Some shape types will be
21
- * automatically converted to other types prior to transformation because they
22
- * cannot be reliably represented in their original type anymore, this
23
- * includes:
20
+ * Transforms given shape with provided matrix.
24
21
  *
25
- * - Arc => Path (cubics)
26
- * - Circle => Path (cubics)
27
- * - Ellipse => Path (cubics)
28
- * - Rect => Polygon
22
+ * @remarks
23
+ * A 2x3 transform matrix is assumed for 2D shapes and 4x4 matrix for 3D shapes.
24
+ * Some shape types will be automatically converted to other types prior to
25
+ * transformation because they cannot be reliably represented in their original
26
+ * type anymore, this includes:
27
+ *
28
+ * - {@link Arc} => {@link Path} (cubics)
29
+ * - {@link Circle} => {@link Path} (cubics)
30
+ * - {@link Ellipse} => {@link Path} (cubics)
31
+ * - {@link Rect} => {@link Quad}
32
+ *
33
+ * Currently implemented for:
34
+ *
35
+ * - {@link Arc}
36
+ * - {@link Circle}
37
+ * - {@link Cubic}
38
+ * - {@link Ellipse}
39
+ * - {@link Group}
40
+ * - {@link Line}
41
+ * - {@link Path}
42
+ * - {@link Points}
43
+ * - {@link Points3}
44
+ * - {@link Polygon}
45
+ * - {@link Polyline}
46
+ * - {@link Quad}
47
+ * - {@link Quadratic}
48
+ * - {@link Ray}
49
+ * - {@link Rect}
50
+ * - {@link Text}
51
+ * - {@link Triangle}
52
+ *
53
+ * @param shape
54
+ * @param mat
29
55
  */
30
56
  export const transform = defmulti(__dispatch, {
31
57
  circle: "arc",
@@ -52,7 +78,7 @@ export const transform = defmulti(__dispatch, {
52
78
  polyline: tx(Polyline),
53
79
  quad: tx(Quad),
54
80
  quadratic: tx(Quadratic),
55
- rect: ($, mat) => transform(asPolygon($), mat),
81
+ rect: ($, mat) => transform(new Quad(vertices($), __copyAttribs($)), mat),
56
82
  text: ($, mat) => new Text(mulV([], mat, $.pos), $.body, __copyAttribs($)),
57
83
  tri: tx(Triangle),
58
84
  });
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)),