@thi.ng/geom 6.0.6 → 6.0.8

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 (104) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/aabb.js +31 -32
  4. package/api/aabb.js +34 -29
  5. package/api/apc.js +15 -13
  6. package/api/arc.js +82 -66
  7. package/api/bpatch.js +79 -96
  8. package/api/circle.js +21 -21
  9. package/api/cubic.js +28 -25
  10. package/api/ellipse.js +26 -21
  11. package/api/group.js +45 -47
  12. package/api/line.js +26 -27
  13. package/api/path.js +62 -58
  14. package/api/plane.js +21 -21
  15. package/api/points.js +30 -26
  16. package/api/polygon.js +19 -16
  17. package/api/polyline.js +25 -22
  18. package/api/quad.js +20 -17
  19. package/api/quad3.js +20 -17
  20. package/api/quadratic.js +28 -25
  21. package/api/ray.js +30 -26
  22. package/api/rect.js +34 -29
  23. package/api/sphere.js +21 -21
  24. package/api/text.js +21 -28
  25. package/api/triangle.js +20 -17
  26. package/apply-transforms.js +28 -48
  27. package/arc-length.js +17 -30
  28. package/arc.js +17 -6
  29. package/area.js +19 -45
  30. package/as-cubic.js +38 -57
  31. package/as-path.js +4 -8
  32. package/as-polygon.js +12 -29
  33. package/as-polyline.js +18 -38
  34. package/as-svg.js +32 -63
  35. package/bounds.js +46 -48
  36. package/bpatch.js +22 -14
  37. package/center.js +22 -17
  38. package/centroid.js +14 -34
  39. package/circle.js +11 -6
  40. package/classify-point.js +20 -27
  41. package/clip-convex.js +40 -39
  42. package/closest-point.js +28 -34
  43. package/convex-hull.js +12 -27
  44. package/cubic.js +13 -5
  45. package/edges.js +31 -60
  46. package/ellipse.js +5 -2
  47. package/fit-into-bounds.js +78 -61
  48. package/flip.js +24 -41
  49. package/group.js +4 -1
  50. package/internal/args.js +18 -51
  51. package/internal/bounds.js +23 -38
  52. package/internal/collate.js +33 -17
  53. package/internal/copy.js +12 -23
  54. package/internal/dispatch.js +6 -4
  55. package/internal/edges.js +4 -1
  56. package/internal/pclike.js +8 -4
  57. package/internal/points-as-shape.js +4 -3
  58. package/internal/rotate.js +6 -2
  59. package/internal/scale.js +8 -2
  60. package/internal/split.js +9 -6
  61. package/internal/transform.js +24 -12
  62. package/internal/translate.js +6 -2
  63. package/internal/vertices.js +15 -31
  64. package/intersects.js +15 -39
  65. package/line.js +11 -9
  66. package/map-point.js +10 -18
  67. package/offset.js +31 -29
  68. package/package.json +33 -31
  69. package/path-builder.js +152 -143
  70. package/path-from-svg.js +129 -131
  71. package/path.js +28 -25
  72. package/plane.js +10 -5
  73. package/point-at.js +12 -30
  74. package/point-inside.js +20 -25
  75. package/points.js +6 -2
  76. package/polygon.js +15 -47
  77. package/polyline.js +18 -22
  78. package/quad.js +23 -15
  79. package/quadratic.js +7 -3
  80. package/ray.js +4 -1
  81. package/rect.js +47 -46
  82. package/resample.js +12 -27
  83. package/rotate.js +30 -42
  84. package/scale.js +66 -64
  85. package/scatter.js +18 -30
  86. package/simplify.js +38 -55
  87. package/sphere.js +7 -3
  88. package/split-arclength.js +53 -108
  89. package/split-at.js +46 -26
  90. package/split-near.js +28 -22
  91. package/subdiv-curve.js +33 -72
  92. package/tangent-at.js +12 -24
  93. package/tessellate.js +22 -47
  94. package/text.js +4 -1
  95. package/transform-vertices.js +31 -55
  96. package/transform.js +31 -54
  97. package/translate.js +39 -46
  98. package/triangle.js +7 -3
  99. package/union.js +12 -15
  100. package/unmap-point.js +21 -25
  101. package/vertices.js +91 -113
  102. package/volume.js +10 -14
  103. package/warp-points.js +15 -25
  104. package/with-attribs.js +4 -11
package/as-cubic.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
- import { closedCubicFromBreakPoints, openCubicFromBreakPoints, } from "@thi.ng/geom-splines/cubic-from-breakpoints";
3
- import { closedCubicFromControlPoints, openCubicFromControlPoints, } from "@thi.ng/geom-splines/cubic-from-controlpoints";
2
+ import {
3
+ closedCubicFromBreakPoints,
4
+ openCubicFromBreakPoints
5
+ } from "@thi.ng/geom-splines/cubic-from-breakpoints";
6
+ import {
7
+ closedCubicFromControlPoints,
8
+ openCubicFromControlPoints
9
+ } from "@thi.ng/geom-splines/cubic-from-controlpoints";
4
10
  import { TAU } from "@thi.ng/math/api";
5
11
  import { mapcat } from "@thi.ng/transducers/mapcat";
6
12
  import { Cubic } from "./api/cubic.js";
@@ -9,73 +15,48 @@ import { asPolygon } from "./as-polygon.js";
9
15
  import { cubicFromArc, cubicFromLine, cubicFromQuadratic } from "./cubic.js";
10
16
  import { __copyAttribs } from "./internal/copy.js";
11
17
  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
- */
48
- export const asCubic = defmulti(__dispatch, {
18
+ const asCubic = defmulti(
19
+ __dispatch,
20
+ {
49
21
  ellipse: "circle",
50
22
  quad: "poly",
51
- tri: "poly",
52
- }, {
23
+ tri: "poly"
24
+ },
25
+ {
53
26
  arc: cubicFromArc,
54
27
  circle: ($) => asCubic(arc($.pos, $.r, 0, 0, TAU, true, true)),
55
28
  cubic: ($) => [$],
56
29
  group: ($, opts) => [
57
- ...mapcat((x) => asCubic(x, opts), $.children),
30
+ ...mapcat((x) => asCubic(x, opts), $.children)
58
31
  ],
59
32
  line: ({ attribs, points }) => [
60
- cubicFromLine(points[0], points[1], { ...attribs }),
33
+ cubicFromLine(points[0], points[1], { ...attribs })
61
34
  ],
62
35
  path: ($) => [
63
- ...mapcat((s) => (s.geo ? asCubic(s.geo) : null), $.segments),
36
+ ...mapcat((s) => s.geo ? asCubic(s.geo) : null, $.segments)
64
37
  ],
65
- poly: ($, opts = {}) => __polyCubic($, opts, closedCubicFromBreakPoints, closedCubicFromControlPoints),
66
- polyline: ($, opts = {}) => __polyCubic($, opts, openCubicFromBreakPoints, openCubicFromControlPoints),
38
+ poly: ($, opts = {}) => __polyCubic(
39
+ $,
40
+ opts,
41
+ closedCubicFromBreakPoints,
42
+ closedCubicFromControlPoints
43
+ ),
44
+ polyline: ($, opts = {}) => __polyCubic(
45
+ $,
46
+ opts,
47
+ openCubicFromBreakPoints,
48
+ openCubicFromControlPoints
49
+ ),
67
50
  quadratic: ({ attribs, points }) => [
68
- cubicFromQuadratic(points[0], points[1], points[2], { ...attribs }),
51
+ cubicFromQuadratic(points[0], points[1], points[2], { ...attribs })
69
52
  ],
70
- rect: ($, opts) => asCubic(asPolygon($), opts),
71
- });
72
- /**
73
- * @internal
74
- */
75
- // prettier-ignore
53
+ rect: ($, opts) => asCubic(asPolygon($), opts)
54
+ }
55
+ );
76
56
  const __polyCubic = ($, opts, breakPoints, controlPoints) => {
77
- opts = { breakPoints: false, scale: 1 / 3, uniform: false, ...opts };
78
- return (opts.breakPoints
79
- ? breakPoints($.points, opts.scale, opts.uniform)
80
- : controlPoints($.points, opts.scale, opts.uniform)).map((pts) => new Cubic(pts, __copyAttribs($)));
57
+ opts = { breakPoints: false, scale: 1 / 3, uniform: false, ...opts };
58
+ return (opts.breakPoints ? breakPoints($.points, opts.scale, opts.uniform) : controlPoints($.points, opts.scale, opts.uniform)).map((pts) => new Cubic(pts, __copyAttribs($)));
59
+ };
60
+ export {
61
+ asCubic
81
62
  };
package/as-path.js CHANGED
@@ -1,11 +1,7 @@
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
- */
11
- export const asPath = (src, attribs) => pathFromCubics(asCubic(src), attribs || __copyAttribs(src));
4
+ const asPath = (src, attribs) => pathFromCubics(asCubic(src), attribs || __copyAttribs(src));
5
+ export {
6
+ asPath
7
+ };
package/as-polygon.js CHANGED
@@ -3,31 +3,9 @@ import { Polygon } from "./api/polygon.js";
3
3
  import { __copyAttribsNoSamples as __attribs } 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
- * [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html)
9
- * or number of target vertices.
10
- *
11
- * @remarks
12
- * If the shape has a `__samples` attribute, it will be removed in the result to
13
- * avoid recursive application.
14
- *
15
- * Currently implemented for:
16
- *
17
- * - {@link Circle}
18
- * - {@link Ellipse}
19
- * - {@link Line}
20
- * - {@link Path}
21
- * - {@link Poly}
22
- * - {@link Polyline} (will be closed)
23
- * - {@link Quad}
24
- * - {@link Rect}
25
- * - {@link Triangle}
26
- *
27
- * @param shape
28
- * @param opts
29
- */
30
- export const asPolygon = defmulti(__dispatch, {
6
+ const asPolygon = defmulti(
7
+ __dispatch,
8
+ {
31
9
  circle: "points",
32
10
  ellipse: "points",
33
11
  line: "points",
@@ -36,7 +14,12 @@ export const asPolygon = defmulti(__dispatch, {
36
14
  polyline: "points",
37
15
  quad: "points",
38
16
  rect: "points",
39
- tri: "points",
40
- }, {
41
- points: ($, opts) => new Polygon(vertices($, opts), __attribs($)),
42
- });
17
+ tri: "points"
18
+ },
19
+ {
20
+ points: ($, opts) => new Polygon(vertices($, opts), __attribs($))
21
+ }
22
+ );
23
+ export {
24
+ asPolygon
25
+ };
package/as-polyline.js CHANGED
@@ -4,34 +4,9 @@ import { Polyline } from "./api/polyline.js";
4
4
  import { __copyAttribsNoSamples as __attribs } 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
- * [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html)
10
- * or number of target vertices.
11
- *
12
- * @remarks
13
- * If the shape has a `__samples` attribute, it will be removed in the result to
14
- * avoid recursive application.
15
- *
16
- * Currently implemented for:
17
- *
18
- * - {@link Arc}
19
- * - {@link Circle}
20
- * - {@link Cubic}
21
- * - {@link Ellipse}
22
- * - {@link Line}
23
- * - {@link Path}
24
- * - {@link Poly}
25
- * - {@link Polyline}
26
- * - {@link Quad}
27
- * - {@link Quadratic}
28
- * - {@link Rect}
29
- * - {@link Triangle}
30
- *
31
- * @param shape
32
- * @param opts
33
- */
34
- export const asPolyline = defmulti(__dispatch, {
7
+ const asPolyline = defmulti(
8
+ __dispatch,
9
+ {
35
10
  arc: "points",
36
11
  circle: "poly",
37
12
  cubic: "points",
@@ -41,17 +16,22 @@ export const asPolyline = defmulti(__dispatch, {
41
16
  quad: "poly",
42
17
  quadratic: "points",
43
18
  rect: "poly",
44
- tri: "poly",
45
- }, {
19
+ tri: "poly"
20
+ },
21
+ {
46
22
  points: ($, opts) => new Polyline(vertices($, opts), __attribs($)),
47
23
  path: ($, opts) => {
48
- const pts = vertices($, opts);
49
- $.closed && pts.push(set([], pts[0]));
50
- return new Polyline(pts, __attribs($));
24
+ const pts = vertices($, opts);
25
+ $.closed && pts.push(set([], pts[0]));
26
+ return new Polyline(pts, __attribs($));
51
27
  },
52
28
  poly: ($, opts) => {
53
- const pts = vertices($, opts);
54
- pts.push(set([], pts[0]));
55
- return new Polyline(pts, __attribs($));
56
- },
57
- });
29
+ const pts = vertices($, opts);
30
+ pts.push(set([], pts[0]));
31
+ return new Polyline(pts, __attribs($));
32
+ }
33
+ }
34
+ );
35
+ export {
36
+ asPolyline
37
+ };
package/as-svg.js CHANGED
@@ -5,69 +5,38 @@ import { svg } from "@thi.ng/hiccup-svg/svg";
5
5
  import { serialize } from "@thi.ng/hiccup/serialize";
6
6
  import { bounds } from "./bounds.js";
7
7
  import { __collBounds } from "./internal/bounds.js";
8
- /**
9
- * Can be overridden via {@link setSvgDefaultAttribs}.
10
- */
11
- export let DEFAULT_ATTRIBS = { fill: "none", stroke: "#000" };
12
- /**
13
- * Sets the SVG root element attribs used by default by {@link svgDoc}.
14
- *
15
- * @param attribs
16
- */
17
- export const setSvgDefaultAttribs = (attribs) => {
18
- DEFAULT_ATTRIBS = attribs;
8
+ let DEFAULT_ATTRIBS = { fill: "none", stroke: "#000" };
9
+ const setSvgDefaultAttribs = (attribs) => {
10
+ DEFAULT_ATTRIBS = attribs;
19
11
  };
20
- /**
21
- * Serializes given hiccup tree to an actual SVG source string.
22
- *
23
- * @param args
24
- */
25
- export const asSvg = (...args) => args.map((x) => serialize(convertTree(x))).join("");
26
- /**
27
- * Creates a hiccup SVG doc element container for given {@link IShape}s and
28
- * attribs (merged with {@link DEFAULT_ATTRIBS}). If the attribs do not include
29
- * a `viewBox`, it will be computed automatically. Furthermore (and only for the
30
- * case a viewbox needs to be computed), a `__bleed` attrib can be provided to
31
- * include a bleed/margin for the viewbox (in world space units).
32
- *
33
- * @remarks
34
- * Use {@link asSvg} to serialize the resulting doc to an SVG string.
35
- *
36
- * The actual serialization is performed via the
37
- * [thi.ng/hiccup](https://thi.ng/hiccup) and
38
- * [thi.ng/hiccup-svg](https://thi.ng/hiccup-svg) packages. Floating point
39
- * precision for various point coordinates can be controlled via the `__prec`
40
- * attribute (number of fractional digits), either for the entire doc or on a
41
- * per-shape basis. If omitted, the currently configured precision will be used
42
- * (default: 3).
43
- *
44
- * Also see
45
- * [`convertTree()`](https://docs.thi.ng/umbrella/hiccup-svg/functions/convertTree.html)
46
- * and
47
- * [`setPrecision()`](https://docs.thi.ng/umbrella/hiccup-svg/functions/setPrecision.html).
48
- *
49
- * @param attribs
50
- * @param xs
51
- */
52
- export const svgDoc = (attribs, ...xs) => {
53
- attribs = { ...DEFAULT_ATTRIBS, ...attribs };
54
- if (xs.length > 0) {
55
- if (!attribs.viewBox) {
56
- const cbounds = __collBounds(xs, bounds);
57
- if (cbounds) {
58
- const [[x, y], [w, h]] = cbounds;
59
- const bleed = attribs.__bleed || 0;
60
- const bleed2 = 2 * bleed;
61
- const width = ff(w + bleed2);
62
- const height = ff(h + bleed2);
63
- attribs = {
64
- width,
65
- height,
66
- viewBox: `${ff(x - bleed)} ${ff(y - bleed)} ${width} ${height}`,
67
- ...withoutKeysObj(attribs, ["__bleed"]),
68
- };
69
- }
70
- }
12
+ const asSvg = (...args) => args.map((x) => serialize(convertTree(x))).join("");
13
+ const svgDoc = (attribs, ...xs) => {
14
+ attribs = { ...DEFAULT_ATTRIBS, ...attribs };
15
+ if (xs.length > 0) {
16
+ if (!attribs.viewBox) {
17
+ const cbounds = __collBounds(xs, bounds);
18
+ if (cbounds) {
19
+ const [[x, y], [w, h]] = cbounds;
20
+ const bleed = attribs.__bleed || 0;
21
+ const bleed2 = 2 * bleed;
22
+ const width = ff(w + bleed2);
23
+ const height = ff(h + bleed2);
24
+ attribs = {
25
+ width,
26
+ height,
27
+ viewBox: `${ff(x - bleed)} ${ff(
28
+ y - bleed
29
+ )} ${width} ${height}`,
30
+ ...withoutKeysObj(attribs, ["__bleed"])
31
+ };
32
+ }
71
33
  }
72
- return svg(attribs, ...xs);
34
+ }
35
+ return svg(attribs, ...xs);
36
+ };
37
+ export {
38
+ DEFAULT_ATTRIBS,
39
+ asSvg,
40
+ setSvgDefaultAttribs,
41
+ svgDoc
73
42
  };
package/bounds.js CHANGED
@@ -19,65 +19,63 @@ 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
- */
50
- export const bounds = defmulti(__dispatch, {
22
+ const bounds = defmulti(
23
+ __dispatch,
24
+ {
51
25
  aabb: "rect",
52
26
  bpatch: "points",
53
27
  poly: "points",
54
28
  polyline: "points",
55
29
  quad: "points",
56
- tri: "points",
57
- }, {
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),
30
+ tri: "points"
31
+ },
32
+ {
33
+ arc: ($, margin = 0) => rectFromMinMaxWithMargin(
34
+ ...arcBounds($.pos, $.r, $.axis, $.start, $.end),
35
+ margin
36
+ ),
37
+ circle: ($, margin = 0) => new Rect(
38
+ subN2([], $.pos, $.r + margin),
39
+ mulN2(null, [2, 2], $.r + margin)
40
+ ),
41
+ cubic: ({ points }, margin = 0) => rectFromMinMaxWithMargin(
42
+ ...cubicBounds(points[0], points[1], points[2], points[3]),
43
+ margin
44
+ ),
61
45
  ellipse: ($, margin = 0) => {
62
- const r = addN2([], $.r, margin);
63
- return new Rect(sub2([], $.pos, r), mul2(null, [2, 2], r));
46
+ const r = addN2([], $.r, margin);
47
+ return new Rect(sub2([], $.pos, r), mul2(null, [2, 2], r));
64
48
  },
65
49
  group: ($, margin = 0) => {
66
- const res = __collBounds($.children, bounds);
67
- return res ? new Rect(...res).offset(margin) : undefined;
50
+ const res = __collBounds($.children, bounds);
51
+ return res ? new Rect(...res).offset(margin) : void 0;
68
52
  },
69
53
  line: ({ points: [a, b] }, margin = 0) => rectFromMinMaxWithMargin(min([], a, b), max([], a, b), margin),
70
54
  path: (path, margin = 0) => {
71
- const b = __collBounds([
72
- ...iterator1(comp(map((s) => s.geo), filter((s) => !!s)), path.segments),
73
- ], bounds);
74
- return b ? new Rect(...b).offset(margin) : undefined;
55
+ const b = __collBounds(
56
+ [
57
+ ...iterator1(
58
+ comp(
59
+ map((s) => s.geo),
60
+ filter((s) => !!s)
61
+ ),
62
+ path.segments
63
+ )
64
+ ],
65
+ bounds
66
+ );
67
+ return b ? new Rect(...b).offset(margin) : void 0;
75
68
  },
76
69
  points: ($, margin = 0) => rectFromMinMaxWithMargin(...bounds2($.points), margin),
77
70
  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),
83
- });
71
+ quadratic: ({ points }, margin = 0) => rectFromMinMaxWithMargin(
72
+ ...quadraticBounds(points[0], points[1], points[2]),
73
+ margin
74
+ ),
75
+ rect: ($, margin = 0) => margin === 0 ? $.copy() : $.copy().offset(margin),
76
+ text: ($, margin = 0) => new Rect(subN2([], $.pos, margin), margin * 2)
77
+ }
78
+ );
79
+ export {
80
+ bounds
81
+ };
package/bpatch.js CHANGED
@@ -1,20 +1,28 @@
1
1
  import { assert } from "@thi.ng/errors/assert";
2
2
  import { mixBilinear } from "@thi.ng/vectors/mix-bilinear";
3
3
  import { BPatch } from "./api/bpatch.js";
4
- export const bpatch = (pts, attribs) => new BPatch(pts, attribs);
5
- export const bpatchFromQuad = (pts, attribs) => {
6
- assert(pts.length === 4, "require 4 points");
7
- const [a, b, c, d] = pts;
8
- const cps = [];
9
- for (let u = 0; u < 4; u++) {
10
- for (let v = 0; v < 4; v++) {
11
- cps.push(mixBilinear([], a, b, d, c, u / 3, v / 3));
12
- }
4
+ const bpatch = (pts, attribs) => new BPatch(pts, attribs);
5
+ const bpatchFromQuad = (pts, attribs) => {
6
+ assert(pts.length === 4, "require 4 points");
7
+ const [a, b, c, d] = pts;
8
+ const cps = [];
9
+ for (let u = 0; u < 4; u++) {
10
+ for (let v = 0; v < 4; v++) {
11
+ cps.push(mixBilinear([], a, b, d, c, u / 3, v / 3));
13
12
  }
14
- return new BPatch(cps, attribs);
13
+ }
14
+ return new BPatch(cps, attribs);
15
15
  };
16
- export const bpatchFromHex = (pts, attribs) => {
17
- assert(pts.length === 6, "require 6 points");
18
- const [a, b, c, d, e, f] = pts;
19
- return new BPatch([e, e, f, f, d, d, a, a, d, d, a, a, c, c, b, b], attribs);
16
+ const bpatchFromHex = (pts, attribs) => {
17
+ assert(pts.length === 6, "require 6 points");
18
+ const [a, b, c, d, e, f] = pts;
19
+ return new BPatch(
20
+ [e, e, f, f, d, d, a, a, d, d, a, a, c, c, b, b],
21
+ attribs
22
+ );
23
+ };
24
+ export {
25
+ bpatch,
26
+ bpatchFromHex,
27
+ bpatchFromQuad
20
28
  };
package/center.js CHANGED
@@ -10,24 +10,29 @@ 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
- */
24
- export const center = defmulti(__dispatch, {}, {
13
+ const center = defmulti(
14
+ __dispatch,
15
+ {},
16
+ {
25
17
  [DEFAULT]: ($, origin = ZERO3) => {
26
- const c = centroid($);
27
- return c ? translate($, submN(null, c, origin, -1)) : undefined;
18
+ const c = centroid($);
19
+ return c ? translate($, submN(null, c, origin, -1)) : void 0;
28
20
  },
29
- arc: ($, origin = ZERO2) => new Arc(set2([], origin), set2([], $.r), $.axis, $.start, $.end, $.xl, $.cw, __copyAttribs($)),
21
+ arc: ($, origin = ZERO2) => new Arc(
22
+ set2([], origin),
23
+ set2([], $.r),
24
+ $.axis,
25
+ $.start,
26
+ $.end,
27
+ $.xl,
28
+ $.cw,
29
+ __copyAttribs($)
30
+ ),
30
31
  circle: ($, origin = ZERO2) => new Circle(set2([], origin), $.r, __copyAttribs($)),
31
32
  ellipse: ($, origin = ZERO2) => new Ellipse(set2([], origin), set2([], $.r), __copyAttribs($)),
32
- sphere: ($, origin = ZERO3) => new Sphere(set3([], origin), $.r, __copyAttribs($)),
33
- });
33
+ sphere: ($, origin = ZERO3) => new Sphere(set3([], origin), $.r, __copyAttribs($))
34
+ }
35
+ );
36
+ export {
37
+ center
38
+ };
package/centroid.js CHANGED
@@ -9,34 +9,9 @@ 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
- */
39
- export const centroid = defmulti(__dispatch, {
12
+ const centroid = defmulti(
13
+ __dispatch,
14
+ {
40
15
  arc: "circle",
41
16
  aabb: "rect",
42
17
  bpatch: "points",
@@ -47,17 +22,22 @@ export const centroid = defmulti(__dispatch, {
47
22
  quad: "poly",
48
23
  sphere: "circle",
49
24
  text: "circle",
50
- tri3: "tri",
51
- }, {
25
+ tri3: "tri"
26
+ },
27
+ {
52
28
  circle: ($, out) => set(out || [], $.pos),
53
29
  group: ($, out) => {
54
- const b = bounds($);
55
- return b ? centroid(b, out) : undefined;
30
+ const b = bounds($);
31
+ return b ? centroid(b, out) : void 0;
56
32
  },
57
33
  line: ({ points }, out) => mixN(out || [], points[0], points[1], 0.5),
58
34
  points: ($, out) => _centroid($.points, out),
59
35
  plane: ($, out) => mulN(out || [], $.normal, $.w),
60
36
  poly: ($, out) => centerOfWeight2($.points, out),
61
37
  rect: ($, out) => maddN(out || [], $.size, 0.5, $.pos),
62
- tri: ({ points }, out) => addmN(null, add(out || [], points[0], points[1]), points[2], 1 / 3),
63
- });
38
+ tri: ({ points }, out) => addmN(null, add(out || [], points[0], points[1]), points[2], 1 / 3)
39
+ }
40
+ );
41
+ export {
42
+ centroid
43
+ };
package/circle.js CHANGED
@@ -3,11 +3,16 @@ import { dist } from "@thi.ng/vectors/dist";
3
3
  import { mixN2 } from "@thi.ng/vectors/mixn";
4
4
  import { Circle } from "./api/circle.js";
5
5
  import { __argsVN } from "./internal/args.js";
6
- export function circle(...args) {
7
- return new Circle(...__argsVN(args));
6
+ function circle(...args) {
7
+ return new Circle(...__argsVN(args));
8
8
  }
9
- export const circleFrom2Points = (a, b, attribs) => new Circle(mixN2([], a, b, 0.5), dist(a, b) / 2, attribs);
10
- export const circleFrom3Points = (a, b, c, attribs) => {
11
- const o = circumCenter2(a, b, c);
12
- return o ? new Circle(o, dist(a, o), attribs) : undefined;
9
+ const circleFrom2Points = (a, b, attribs) => new Circle(mixN2([], a, b, 0.5), dist(a, b) / 2, attribs);
10
+ const circleFrom3Points = (a, b, c, attribs) => {
11
+ const o = circumCenter2(a, b, c);
12
+ return o ? new Circle(o, dist(a, o), attribs) : void 0;
13
+ };
14
+ export {
15
+ circle,
16
+ circleFrom2Points,
17
+ circleFrom3Points
13
18
  };