@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/api/triangle.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import type { IHiccupShape } from "@thi.ng/geom-api";
1
+ import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
2
2
  import { APC } from "./apc.js";
3
3
  export declare class Triangle extends APC implements IHiccupShape {
4
4
  get type(): string;
5
5
  copy(): Triangle;
6
- toHiccup(): (string | import("@thi.ng/geom-api").Attribs | undefined)[];
6
+ withAttribs(attribs: Attribs): Triangle;
7
+ toHiccup(): (string | Attribs | undefined)[];
7
8
  }
8
9
  //# sourceMappingURL=triangle.d.ts.map
package/api/triangle.js CHANGED
@@ -7,6 +7,9 @@ export class Triangle extends APC {
7
7
  copy() {
8
8
  return __copyShape(Triangle, this);
9
9
  }
10
+ withAttribs(attribs) {
11
+ return new Triangle(this.points, attribs);
12
+ }
10
13
  toHiccup() {
11
14
  return ["polygon", this.attribs, this.points];
12
15
  }
@@ -0,0 +1,33 @@
1
+ import type { MultiFn1 } from "@thi.ng/defmulti";
2
+ import type { IShape } from "@thi.ng/geom-api";
3
+ /**
4
+ * Applies any spatial transformation attributes defined (if any) for the given
5
+ * shape. If no such attributes exist, the original shape is returned as is.
6
+ *
7
+ * @remarks
8
+ * The following attributes are considered:
9
+ *
10
+ * - transform: A 2x3 (for 2D) or 4x4 (for 3D) transformation matrix
11
+ * - translate: Translation/offset vector
12
+ * - scale: A scale factor (scalar or vector)
13
+ * - rotate: Rotation angle (in radians)
14
+ *
15
+ * If the `transform` attrib is given, the others will be ignored. If any of the
16
+ * other 3 attribs is provided, the order of application is: rotate, scale,
17
+ * translate. Any of these relevant attributes will be removed from the
18
+ * transformed shapes to ensure idempotent behavior.
19
+ *
20
+ * For (@link group} shapes, the children are processed in depth-first order
21
+ * with any transformations to the group itself applied last.
22
+ *
23
+ * Note: Where possible, this function delegates to {@link rotate},
24
+ * {@link scale}, {@link translate} to realize individual/partial transformation
25
+ * aspects to increase the likelihodd of retaining original shape types. E.g.
26
+ * uniformly scaling a circle with a scalar factor retains a circle, but scaling
27
+ * non-uniformly will convert it to an ellipse... Similarly, rotating a rect
28
+ * will convert it to a quad etc.
29
+ *
30
+ * @param shape
31
+ */
32
+ export declare const applyTransforms: MultiFn1<IShape, IShape>;
33
+ //# sourceMappingURL=apply-transforms.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { withoutKeysObj } from "@thi.ng/associative/without-keys";
2
+ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
3
+ import { __dispatch } from "./internal/dispatch.js";
4
+ import { rotate } from "./rotate.js";
5
+ import { scale } from "./scale.js";
6
+ import { transform } from "./transform.js";
7
+ import { translate } from "./translate.js";
8
+ /** @internal */
9
+ const __apply = ($) => {
10
+ let attribs = $.attribs;
11
+ if (!attribs)
12
+ return $;
13
+ const { transform: tx, translate: t, rotate: r, scale: s } = attribs;
14
+ if (tx)
15
+ return transform($.withAttribs(withoutKeysObj(attribs, ["transform"])), tx);
16
+ if (!(t || r || s))
17
+ return $;
18
+ $ = $.withAttribs(withoutKeysObj(attribs, ["translate", "rotate", "scale"]));
19
+ if (r)
20
+ $ = rotate($, r);
21
+ if (s)
22
+ $ = scale($, s);
23
+ if (t)
24
+ $ = translate($, t);
25
+ return $;
26
+ };
27
+ /**
28
+ * Applies any spatial transformation attributes defined (if any) for the given
29
+ * shape. If no such attributes exist, the original shape is returned as is.
30
+ *
31
+ * @remarks
32
+ * The following attributes are considered:
33
+ *
34
+ * - transform: A 2x3 (for 2D) or 4x4 (for 3D) transformation matrix
35
+ * - translate: Translation/offset vector
36
+ * - scale: A scale factor (scalar or vector)
37
+ * - rotate: Rotation angle (in radians)
38
+ *
39
+ * If the `transform` attrib is given, the others will be ignored. If any of the
40
+ * other 3 attribs is provided, the order of application is: rotate, scale,
41
+ * translate. Any of these relevant attributes will be removed from the
42
+ * transformed shapes to ensure idempotent behavior.
43
+ *
44
+ * For (@link group} shapes, the children are processed in depth-first order
45
+ * with any transformations to the group itself applied last.
46
+ *
47
+ * Note: Where possible, this function delegates to {@link rotate},
48
+ * {@link scale}, {@link translate} to realize individual/partial transformation
49
+ * aspects to increase the likelihodd of retaining original shape types. E.g.
50
+ * uniformly scaling a circle with a scalar factor retains a circle, but scaling
51
+ * non-uniformly will convert it to an ellipse... Similarly, rotating a rect
52
+ * will convert it to a quad etc.
53
+ *
54
+ * @param shape
55
+ */
56
+ export const applyTransforms = defmulti(__dispatch, {}, {
57
+ [DEFAULT]: __apply,
58
+ group: ($) => __apply($.copyTransformed((x) => applyTransforms(x))),
59
+ });
package/arc-length.d.ts CHANGED
@@ -7,16 +7,17 @@ import type { IShape } from "@thi.ng/geom-api";
7
7
  *
8
8
  * Implemented for:
9
9
  *
10
- * - Circle
11
- * - Ellipse
12
- * - Group
13
- * - Line
14
- * - Polygon
15
- * - Polyline
16
- * - Quad
17
- * - Rect
18
- * - Triangle
10
+ * - {@link Circle}
11
+ * - {@link Ellipse}
12
+ * - {@link Group} (total sum of child circumferences)
13
+ * - {@link Line}
14
+ * - {@link Polygon}
15
+ * - {@link Polyline}
16
+ * - {@link Quad}
17
+ * - {@link Rect}
18
+ * - {@link Triangle}
19
19
  *
20
+ * @param shape
20
21
  */
21
22
  export declare const arcLength: MultiFn1<IShape, number>;
22
23
  //# sourceMappingURL=arc-length.d.ts.map
package/arc-length.js CHANGED
@@ -10,16 +10,17 @@ import { __dispatch } from "./internal/dispatch.js";
10
10
  *
11
11
  * Implemented for:
12
12
  *
13
- * - Circle
14
- * - Ellipse
15
- * - Group
16
- * - Line
17
- * - Polygon
18
- * - Polyline
19
- * - Quad
20
- * - Rect
21
- * - Triangle
13
+ * - {@link Circle}
14
+ * - {@link Ellipse}
15
+ * - {@link Group} (total sum of child circumferences)
16
+ * - {@link Line}
17
+ * - {@link Polygon}
18
+ * - {@link Polyline}
19
+ * - {@link Quad}
20
+ * - {@link Rect}
21
+ * - {@link Triangle}
22
22
  *
23
+ * @param shape
23
24
  */
24
25
  export const arcLength = defmulti(__dispatch, {
25
26
  quad: "poly",
@@ -34,7 +35,7 @@ export const arcLength = defmulti(__dispatch, {
34
35
  line: ({ points }) => dist(points[0], points[1]),
35
36
  poly: ({ points }) => perimeter(points, points.length, true),
36
37
  polyline: ({ points }) => perimeter(points, points.length),
37
- rect: ({ size }) => 2 * (size[0] + size[1]),
38
+ rect: ({ size: [w, h] }) => 2 * (w + h),
38
39
  tri: ({ points }) => dist(points[0], points[1]) +
39
40
  dist(points[1], points[2]) +
40
41
  dist(points[2], points[0]),
package/area.d.ts CHANGED
@@ -1,34 +1,35 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { IShape } from "@thi.ng/geom-api";
3
3
  /**
4
- * Returns the possibly signed (unsigned by default) surface area of given
5
- * `shape`. For groups calls {@link area} for each child and returns sum of
6
- * unsigned areas.
4
+ * Computes the possibly signed (unsigned by default) surface area of given
5
+ * `shape`. For groups calls itself for each child and returns sum of unsigned
6
+ * areas.
7
7
  *
8
- * In general, for polygons and triangles, the sign of the result can be
9
- * used as indication of the shapes orientation (clockwise /
10
- * counterclockwise).
8
+ * @remarks
9
+ * In general, for polygons and triangles, the sign of the result can be used as
10
+ * indication of the shapes orientation (clockwise / counterclockwise).
11
11
  *
12
12
  * For curves, lines, point clouds and rays the function returns 0.
13
13
  *
14
- * Implemented for:
14
+ * Currently implemented for:
15
15
  *
16
- * - AABB
17
- * - Circle
18
- * - Cubic
19
- * - Ellipse
20
- * - Group
21
- * - Line
22
- * - Plane
23
- * - Points
24
- * - Polygon
25
- * - Polyline
26
- * - Quad
27
- * - Quadratic
28
- * - Ray
29
- * - Rect
30
- * - Sphere
31
- * - Triangle
16
+ * - {@link AABB}
17
+ * - {@link Circle}
18
+ * - {@link Cubic}
19
+ * - {@link Ellipse}
20
+ * - {@link Group}
21
+ * - {@link Line}
22
+ * - {@link Path} (closed only & via poly conversion)
23
+ * - {@link Plane}
24
+ * - {@link Points}
25
+ * - {@link Polygon}
26
+ * - {@link Polyline}
27
+ * - {@link Quad}
28
+ * - {@link Quadratic}
29
+ * - {@link Ray}
30
+ * - {@link Rect}
31
+ * - {@link Sphere}
32
+ * - {@link Triangle}
32
33
  *
33
34
  * @param shape - shape to operate on
34
35
  * @param signed - true, if signed area
package/area.js CHANGED
@@ -2,36 +2,38 @@ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
2
2
  import { polyArea2 } from "@thi.ng/geom-poly-utils/area";
3
3
  import { PI } from "@thi.ng/math/api";
4
4
  import { signedArea2 } from "@thi.ng/vectors/signed-area";
5
+ import { asPolygon } from "./as-polygon.js";
5
6
  import { __dispatch } from "./internal/dispatch.js";
6
7
  /**
7
- * Returns the possibly signed (unsigned by default) surface area of given
8
- * `shape`. For groups calls {@link area} for each child and returns sum of
9
- * unsigned areas.
8
+ * Computes the possibly signed (unsigned by default) surface area of given
9
+ * `shape`. For groups calls itself for each child and returns sum of unsigned
10
+ * areas.
10
11
  *
11
- * In general, for polygons and triangles, the sign of the result can be
12
- * used as indication of the shapes orientation (clockwise /
13
- * counterclockwise).
12
+ * @remarks
13
+ * In general, for polygons and triangles, the sign of the result can be used as
14
+ * indication of the shapes orientation (clockwise / counterclockwise).
14
15
  *
15
16
  * For curves, lines, point clouds and rays the function returns 0.
16
17
  *
17
- * Implemented for:
18
+ * Currently implemented for:
18
19
  *
19
- * - AABB
20
- * - Circle
21
- * - Cubic
22
- * - Ellipse
23
- * - Group
24
- * - Line
25
- * - Plane
26
- * - Points
27
- * - Polygon
28
- * - Polyline
29
- * - Quad
30
- * - Quadratic
31
- * - Ray
32
- * - Rect
33
- * - Sphere
34
- * - Triangle
20
+ * - {@link AABB}
21
+ * - {@link Circle}
22
+ * - {@link Cubic}
23
+ * - {@link Ellipse}
24
+ * - {@link Group}
25
+ * - {@link Line}
26
+ * - {@link Path} (closed only & via poly conversion)
27
+ * - {@link Plane}
28
+ * - {@link Points}
29
+ * - {@link Polygon}
30
+ * - {@link Polyline}
31
+ * - {@link Quad}
32
+ * - {@link Quadratic}
33
+ * - {@link Ray}
34
+ * - {@link Rect}
35
+ * - {@link Sphere}
36
+ * - {@link Triangle}
35
37
  *
36
38
  * @param shape - shape to operate on
37
39
  * @param signed - true, if signed area
@@ -44,6 +46,7 @@ export const area = defmulti(__dispatch, { quad: "poly" }, {
44
46
  circle: ($) => PI * $.r ** 2,
45
47
  ellipse: ($) => PI * $.r[0] * $.r[1],
46
48
  group: ({ children }) => children.reduce((sum, $) => sum + area($, false), 0),
49
+ path: ($) => ($.closed ? area(asPolygon($)) : 0),
47
50
  plane: () => Infinity,
48
51
  poly: ($, signed) => {
49
52
  const area = polyArea2($.points);
package/as-cubic.d.ts CHANGED
@@ -1,5 +1,41 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { CubicOpts, IShape } from "@thi.ng/geom-api";
3
3
  import { Cubic } from "./api/cubic.js";
4
+ /**
5
+ * Converts given shape into an array of {@link Cubic} curves. For some shapes
6
+ * (see below) the conversion supports optionally provided {@link CubicOpts}.
7
+ *
8
+ * @remarks
9
+ * Currently implemented for:
10
+ *
11
+ * - {@link Arc}
12
+ * - {@link Circle}
13
+ * - {@link Cubic}
14
+ * - {@link Ellipse}
15
+ * - {@link Group}
16
+ * - {@link Line}
17
+ * - {@link Path}
18
+ * - {@link Polygon}
19
+ * - {@link Polyline}
20
+ * - {@link Quad}
21
+ * - {@link Quadratic}
22
+ * - {@link Rect}
23
+ * - {@link Triangle}
24
+ *
25
+ * Shape types supporting custom conversion options (see
26
+ * [@thi.ng/geom-splines](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-splines#cubic-curve-conversion-from-polygons--polylines)
27
+ * for more details):
28
+ *
29
+ * - {@link Group} (only used for eligible children)
30
+ * - {@link Polygon}
31
+ * - {@link Polyline}
32
+ * - {@link Quad}
33
+ * - {@link Quadratic}
34
+ * - {@link Rect}
35
+ * - {@link Triangle}
36
+ *
37
+ * @param shape
38
+ * @param opts
39
+ */
4
40
  export declare const asCubic: MultiFn1O<IShape, Partial<CubicOpts>, Cubic[]>;
5
41
  //# sourceMappingURL=as-cubic.d.ts.map
package/as-cubic.js CHANGED
@@ -9,6 +9,42 @@ import { asPolygon } from "./as-polygon.js";
9
9
  import { cubicFromArc, cubicFromLine, cubicFromQuadratic } from "./cubic.js";
10
10
  import { __copyAttribs } from "./internal/copy.js";
11
11
  import { __dispatch } from "./internal/dispatch.js";
12
+ /**
13
+ * Converts given shape into an array of {@link Cubic} curves. For some shapes
14
+ * (see below) the conversion supports optionally provided {@link CubicOpts}.
15
+ *
16
+ * @remarks
17
+ * Currently implemented for:
18
+ *
19
+ * - {@link Arc}
20
+ * - {@link Circle}
21
+ * - {@link Cubic}
22
+ * - {@link Ellipse}
23
+ * - {@link Group}
24
+ * - {@link Line}
25
+ * - {@link Path}
26
+ * - {@link Polygon}
27
+ * - {@link Polyline}
28
+ * - {@link Quad}
29
+ * - {@link Quadratic}
30
+ * - {@link Rect}
31
+ * - {@link Triangle}
32
+ *
33
+ * Shape types supporting custom conversion options (see
34
+ * [@thi.ng/geom-splines](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-splines#cubic-curve-conversion-from-polygons--polylines)
35
+ * for more details):
36
+ *
37
+ * - {@link Group} (only used for eligible children)
38
+ * - {@link Polygon}
39
+ * - {@link Polyline}
40
+ * - {@link Quad}
41
+ * - {@link Quadratic}
42
+ * - {@link Rect}
43
+ * - {@link Triangle}
44
+ *
45
+ * @param shape
46
+ * @param opts
47
+ */
12
48
  export const asCubic = defmulti(__dispatch, {
13
49
  ellipse: "circle",
14
50
  quad: "poly",
@@ -17,22 +53,27 @@ export const asCubic = defmulti(__dispatch, {
17
53
  arc: cubicFromArc,
18
54
  circle: ($) => asCubic(arc($.pos, $.r, 0, 0, TAU, true, true)),
19
55
  cubic: ($) => [$],
20
- group: ($) => [...mapcat(asCubic, $.children)],
56
+ group: ($, opts) => [
57
+ ...mapcat((x) => asCubic(x, opts), $.children),
58
+ ],
21
59
  line: ({ attribs, points }) => [
22
60
  cubicFromLine(points[0], points[1], { ...attribs }),
23
61
  ],
24
62
  path: ($) => [
25
63
  ...mapcat((s) => (s.geo ? asCubic(s.geo) : null), $.segments),
26
64
  ],
27
- poly: ($, opts = {}) => polyCubic($, opts, closedCubicFromBreakPoints, closedCubicFromControlPoints),
28
- polyline: ($, opts = {}) => polyCubic($, opts, openCubicFromBreakPoints, openCubicFromControlPoints),
65
+ poly: ($, opts = {}) => __polyCubic($, opts, closedCubicFromBreakPoints, closedCubicFromControlPoints),
66
+ polyline: ($, opts = {}) => __polyCubic($, opts, openCubicFromBreakPoints, openCubicFromControlPoints),
29
67
  quadratic: ({ attribs, points }) => [
30
68
  cubicFromQuadratic(points[0], points[1], points[2], { ...attribs }),
31
69
  ],
32
70
  rect: ($, opts) => asCubic(asPolygon($), opts),
33
71
  });
72
+ /**
73
+ * @internal
74
+ */
34
75
  // prettier-ignore
35
- const polyCubic = ($, opts, breakPoints, controlPoints) => {
76
+ const __polyCubic = ($, opts, breakPoints, controlPoints) => {
36
77
  opts = { breakPoints: false, scale: 1 / 3, uniform: false, ...opts };
37
78
  return (opts.breakPoints
38
79
  ? breakPoints($.points, opts.scale, opts.uniform)
package/as-path.d.ts CHANGED
@@ -1,3 +1,10 @@
1
1
  import type { Attribs, IShape } from "@thi.ng/geom-api";
2
+ /**
3
+ * Converts given shape into a {@link Path} (via {@link asCubic} and
4
+ * {@link pathFromCubics}).
5
+ *
6
+ * @param src
7
+ * @param attribs
8
+ */
2
9
  export declare const asPath: (src: IShape, attribs?: Attribs) => import("./index.js").Path;
3
10
  //# sourceMappingURL=as-path.d.ts.map
package/as-path.js CHANGED
@@ -1,4 +1,11 @@
1
1
  import { asCubic } from "./as-cubic.js";
2
2
  import { __copyAttribs } from "./internal/copy.js";
3
3
  import { pathFromCubics } from "./path.js";
4
+ /**
5
+ * Converts given shape into a {@link Path} (via {@link asCubic} and
6
+ * {@link pathFromCubics}).
7
+ *
8
+ * @param src
9
+ * @param attribs
10
+ */
4
11
  export const asPath = (src, attribs) => pathFromCubics(asCubic(src), attribs || __copyAttribs(src));
package/as-polygon.d.ts CHANGED
@@ -1,5 +1,25 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
3
3
  import { Polygon } from "./api/polygon.js";
4
+ /**
5
+ * Converts given shape into a {@link Polygon}, optionally using provided
6
+ * {@link @thi.ng/geom-api#SamplingOpts} or number of target vertices.
7
+ *
8
+ * @remarks
9
+ * Currently implemented for:
10
+ *
11
+ * - {@link Circle}
12
+ * - {@link Ellipse}
13
+ * - {@link Line}
14
+ * - {@link Path}
15
+ * - {@link Poly}
16
+ * - {@link Polyline} (will be closed)
17
+ * - {@link Quad}
18
+ * - {@link Rect}
19
+ * - {@link Triangle}
20
+ *
21
+ * @param shape
22
+ * @param opts
23
+ */
4
24
  export declare const asPolygon: MultiFn1O<IShape, number | Partial<SamplingOpts>, Polygon>;
5
25
  //# sourceMappingURL=as-polygon.d.ts.map
package/as-polygon.js CHANGED
@@ -3,6 +3,26 @@ import { Polygon } from "./api/polygon.js";
3
3
  import { __copyAttribs } from "./internal/copy.js";
4
4
  import { __dispatch } from "./internal/dispatch.js";
5
5
  import { vertices } from "./vertices.js";
6
+ /**
7
+ * Converts given shape into a {@link Polygon}, optionally using provided
8
+ * {@link @thi.ng/geom-api#SamplingOpts} or number of target vertices.
9
+ *
10
+ * @remarks
11
+ * Currently implemented for:
12
+ *
13
+ * - {@link Circle}
14
+ * - {@link Ellipse}
15
+ * - {@link Line}
16
+ * - {@link Path}
17
+ * - {@link Poly}
18
+ * - {@link Polyline} (will be closed)
19
+ * - {@link Quad}
20
+ * - {@link Rect}
21
+ * - {@link Triangle}
22
+ *
23
+ * @param shape
24
+ * @param opts
25
+ */
6
26
  export const asPolygon = defmulti(__dispatch, {
7
27
  circle: "points",
8
28
  ellipse: "points",
package/as-polyline.d.ts CHANGED
@@ -1,5 +1,28 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
3
3
  import { Polyline } from "./api/polyline.js";
4
+ /**
5
+ * Converts given shape into a {@link Polyline}, optionally using provided
6
+ * {@link @thi.ng/geom-api#SamplingOpts} or number of target vertices.
7
+ *
8
+ * @remarks
9
+ * Currently implemented for:
10
+ *
11
+ * - {@link Arc}
12
+ * - {@link Circle}
13
+ * - {@link Cubic}
14
+ * - {@link Ellipse}
15
+ * - {@link Line}
16
+ * - {@link Path}
17
+ * - {@link Poly}
18
+ * - {@link Polyline}
19
+ * - {@link Quad}
20
+ * - {@link Quadratic}
21
+ * - {@link Rect}
22
+ * - {@link Triangle}
23
+ *
24
+ * @param shape
25
+ * @param opts
26
+ */
4
27
  export declare const asPolyline: MultiFn1O<IShape, number | Partial<SamplingOpts>, Polyline>;
5
28
  //# sourceMappingURL=as-polyline.d.ts.map
package/as-polyline.js CHANGED
@@ -4,6 +4,29 @@ import { Polyline } from "./api/polyline.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
+ * Converts given shape into a {@link Polyline}, optionally using provided
9
+ * {@link @thi.ng/geom-api#SamplingOpts} or number of target vertices.
10
+ *
11
+ * @remarks
12
+ * Currently implemented for:
13
+ *
14
+ * - {@link Arc}
15
+ * - {@link Circle}
16
+ * - {@link Cubic}
17
+ * - {@link Ellipse}
18
+ * - {@link Line}
19
+ * - {@link Path}
20
+ * - {@link Poly}
21
+ * - {@link Polyline}
22
+ * - {@link Quad}
23
+ * - {@link Quadratic}
24
+ * - {@link Rect}
25
+ * - {@link Triangle}
26
+ *
27
+ * @param shape
28
+ * @param opts
29
+ */
7
30
  export const asPolyline = defmulti(__dispatch, {
8
31
  arc: "points",
9
32
  circle: "poly",
package/bounds.d.ts CHANGED
@@ -1,4 +1,32 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
2
  import type { AABBLike, IShape } from "@thi.ng/geom-api";
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
+ */
3
31
  export declare const bounds: MultiFn1O<IShape, number, AABBLike | undefined>;
4
32
  //# sourceMappingURL=bounds.d.ts.map
package/bounds.js CHANGED
@@ -19,6 +19,34 @@ import { Rect } from "./api/rect.js";
19
19
  import { __collBounds } from "./internal/bounds.js";
20
20
  import { __dispatch } from "./internal/dispatch.js";
21
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",
@@ -51,5 +79,5 @@ export const bounds = defmulti(__dispatch, {
51
79
  rect: ($, margin = 0) => margin === 0
52
80
  ? $.copy()
53
81
  : $.copy().offset(margin),
54
- text: ($, margin = 0) => new Rect(subN2([], $.pos, margin), [0, 0]), // TODO
82
+ text: ($, margin = 0) => new Rect(subN2([], $.pos, margin), margin * 2),
55
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