@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/classify-point.js CHANGED
@@ -1,34 +1,27 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
- import { classifyPointInCircle, classifyPointInTriangle2, } from "@thi.ng/geom-isec/point";
2
+ import {
3
+ classifyPointInCircle,
4
+ classifyPointInTriangle2
5
+ } from "@thi.ng/geom-isec/point";
3
6
  import { sign } from "@thi.ng/math/abs";
4
7
  import { EPS } from "@thi.ng/math/api";
5
8
  import { dot } from "@thi.ng/vectors/dot";
6
9
  import { __dispatch } from "./internal/dispatch.js";
7
- /**
8
- * Classifies point `p` with respect to given shape. Returns -1 if `p` is
9
- * inside, 1 if outside or 0 if `p` is on the shape boundary (using optional
10
- * tolerance `eps`, default: 1e-6).
11
- *
12
- * @remarks
13
- * Currently only implemented for:
14
- *
15
- * - {@link Circle}
16
- * - {@link Plane}
17
- * - {@link Sphere}
18
- * - {@link Triangle}
19
- *
20
- * The [thi.ng/geom-sdf](https://thi.ng/thi.ng/geom-sdf) package provides a much
21
- * more comprehensive feature set (incl. support for more shapes) to perform
22
- * similar checks as this function.
23
- *
24
- * Also see {@link pointInside}.
25
- *
26
- * @param shape
27
- * @param p
28
- * @param eps
29
- */
30
- export const classifyPoint = defmulti(__dispatch, { sphere: "circle" }, {
10
+ const classifyPoint = defmulti(
11
+ __dispatch,
12
+ { sphere: "circle" },
13
+ {
31
14
  circle: ($, p, eps = EPS) => classifyPointInCircle(p, $.pos, $.r, eps),
32
15
  plane: ($, p, eps) => sign(dot($.normal, p) - $.w, eps),
33
- tri: ({ points }, p, eps = EPS) => classifyPointInTriangle2(p, points[0], points[1], points[2], eps),
34
- });
16
+ tri: ({ points }, p, eps = EPS) => classifyPointInTriangle2(
17
+ p,
18
+ points[0],
19
+ points[1],
20
+ points[2],
21
+ eps
22
+ )
23
+ }
24
+ );
25
+ export {
26
+ classifyPoint
27
+ };
package/clip-convex.js CHANGED
@@ -8,53 +8,54 @@ import { Polygon } from "./api/polygon.js";
8
8
  import { __copyAttribs } from "./internal/copy.js";
9
9
  import { __dispatch } from "./internal/dispatch.js";
10
10
  import { ensureVertices, vertices } from "./vertices.js";
11
- /**
12
- * Takes a shape and a boundary (both convex). Uses the Sutherland-Hodgman
13
- * algorithm to compute a clipped version of the first shape (against the
14
- * boundary). Returns `undefined` if there're no remaining result vertices.
15
- *
16
- * @remarks
17
- * Internally uses
18
- * [`sutherlandHodgeman()`](https://docs.thi.ng/umbrella/geom-clip-poly/functions/sutherlandHodgeman.html).
19
- * For groups, calls itself for each child shape individually and returns a new
20
- * group of results (if any).
21
- *
22
- * @param shape
23
- * @param boundary
24
- */
25
- export const clipConvex = defmulti(__dispatch, {
11
+ const clipConvex = defmulti(
12
+ __dispatch,
13
+ {
26
14
  circle: "rect",
27
15
  ellipse: "rect",
28
16
  path: "rect",
29
17
  quad: "poly",
30
- tri: "poly",
31
- }, {
18
+ tri: "poly"
19
+ },
20
+ {
32
21
  group: ({ children, attribs }, boundary) => {
33
- boundary = ensureVertices(boundary);
34
- const clipped = [];
35
- for (let c of children) {
36
- const res = clipConvex(c, boundary);
37
- if (res)
38
- clipped.push(res);
39
- }
40
- return clipped.length
41
- ? new Group({ ...attribs }, clipped)
42
- : undefined;
22
+ boundary = ensureVertices(boundary);
23
+ const clipped = [];
24
+ for (let c of children) {
25
+ const res = clipConvex(c, boundary);
26
+ if (res)
27
+ clipped.push(res);
28
+ }
29
+ return clipped.length ? new Group({ ...attribs }, clipped) : void 0;
43
30
  },
44
31
  line: ($, boundary) => {
45
- const segments = clipLineSegmentPoly($.points[0], $.points[1], ensureVertices(boundary));
46
- return segments && segments.length
47
- ? new Line(segments[0], __copyAttribs($))
48
- : undefined;
32
+ const segments = clipLineSegmentPoly(
33
+ $.points[0],
34
+ $.points[1],
35
+ ensureVertices(boundary)
36
+ );
37
+ return segments && segments.length ? new Line(segments[0], __copyAttribs($)) : void 0;
49
38
  },
50
39
  poly: ($, boundary) => {
51
- boundary = ensureVertices(boundary);
52
- const pts = sutherlandHodgeman($.points, boundary, centroid(boundary));
53
- return pts.length ? new Polygon(pts, __copyAttribs($)) : undefined;
40
+ boundary = ensureVertices(boundary);
41
+ const pts = sutherlandHodgeman(
42
+ $.points,
43
+ boundary,
44
+ centroid(boundary)
45
+ );
46
+ return pts.length ? new Polygon(pts, __copyAttribs($)) : void 0;
54
47
  },
55
48
  rect: ($, boundary) => {
56
- boundary = ensureVertices(boundary);
57
- const pts = sutherlandHodgeman(vertices($), boundary, centroid(boundary));
58
- return pts.length ? new Polygon(pts, __copyAttribs($)) : undefined;
59
- },
60
- });
49
+ boundary = ensureVertices(boundary);
50
+ const pts = sutherlandHodgeman(
51
+ vertices($),
52
+ boundary,
53
+ centroid(boundary)
54
+ );
55
+ return pts.length ? new Polygon(pts, __copyAttribs($)) : void 0;
56
+ }
57
+ }
58
+ );
59
+ export {
60
+ clipConvex
61
+ };
package/closest-point.js CHANGED
@@ -1,55 +1,49 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
2
  import { closestPoint as closestPointArc } from "@thi.ng/geom-arc/closest-point";
3
- import { closestPointAABB, closestPointRect, } from "@thi.ng/geom-closest-point/box";
3
+ import {
4
+ closestPointAABB,
5
+ closestPointRect
6
+ } from "@thi.ng/geom-closest-point/box";
4
7
  import { closestPointCircle } from "@thi.ng/geom-closest-point/circle";
5
- import { closestPointPolyline, closestPointSegment, } from "@thi.ng/geom-closest-point/line";
8
+ import {
9
+ closestPointPolyline,
10
+ closestPointSegment
11
+ } from "@thi.ng/geom-closest-point/line";
6
12
  import { closestPointPlane } from "@thi.ng/geom-closest-point/plane";
7
13
  import { closestPointArray } from "@thi.ng/geom-closest-point/points";
8
14
  import { closestPointCubic } from "@thi.ng/geom-splines/cubic-closest-point";
9
15
  import { closestPointQuadratic } from "@thi.ng/geom-splines/quadratic-closest-point";
10
16
  import { add2, add3 } from "@thi.ng/vectors/add";
11
17
  import { __dispatch } from "./internal/dispatch.js";
12
- /**
13
- * Computes closest point to `p` on boundary of given shape. Writes result in
14
- * optionally provided output vector (or creates new one if omitted).
15
- *
16
- * @remarks
17
- * Currently implemented for:
18
- *
19
- * - {@link AABB}
20
- * - {@link Arc}
21
- * - {@link Circle}
22
- * - {@link Cubic}
23
- * - {@link Line}
24
- * - {@link Plane}
25
- * - {@link Points}
26
- * - {@link Points3}
27
- * - {@link Polygon}
28
- * - {@link Polyline}
29
- * - {@link Quad}
30
- * - {@link Quadratic}
31
- * - {@link Rect}
32
- * - {@link Sphere}
33
- *
34
- * @param shape
35
- * @param p
36
- * @param out
37
- */
38
- export const closestPoint = defmulti(__dispatch, {
18
+ const closestPoint = defmulti(
19
+ __dispatch,
20
+ {
39
21
  quad: "poly",
40
22
  points3: "points",
41
23
  sphere: "circle",
42
- tri: "poly",
43
- }, {
24
+ tri: "poly"
25
+ },
26
+ {
44
27
  aabb: ($, p, out) => closestPointAABB(p, $.pos, add3([], $.pos, $.size), out),
45
28
  arc: ($, p, out) => closestPointArc(p, $.pos, $.r, $.axis, $.start, $.end, out),
46
29
  circle: ($, p, out) => closestPointCircle(p, $.pos, $.r, out),
47
- cubic: ({ points }, p, out) => closestPointCubic(p, points[0], points[1], points[2], points[3], out),
30
+ cubic: ({ points }, p, out) => closestPointCubic(
31
+ p,
32
+ points[0],
33
+ points[1],
34
+ points[2],
35
+ points[3],
36
+ out
37
+ ),
48
38
  line: ({ points }, p, out) => closestPointSegment(p, points[0], points[1], out),
49
39
  plane: ($, p, out) => closestPointPlane(p, $.normal, $.w, out),
50
40
  points: ($, p, out) => closestPointArray(p, $.points, out),
51
41
  poly: ($, p, out) => closestPointPolyline(p, $.points, true, out),
52
42
  polyline: ($, p, out) => closestPointPolyline(p, $.points, false, out),
53
43
  quadratic: ({ points }, p, out) => closestPointQuadratic(p, points[0], points[1], points[2], out),
54
- rect: ($, p, out) => closestPointRect(p, $.pos, add2([], $.pos, $.size), out),
55
- });
44
+ rect: ($, p, out) => closestPointRect(p, $.pos, add2([], $.pos, $.size), out)
45
+ }
46
+ );
47
+ export {
48
+ closestPoint
49
+ };
package/convex-hull.js CHANGED
@@ -4,29 +4,9 @@ import { Polygon } from "./api/polygon.js";
4
4
  import { __copyAttribs } from "./internal/copy.js";
5
5
  import { __dispatch } from "./internal/dispatch.js";
6
6
  import { vertices } from "./vertices.js";
7
- /**
8
- * Computes the convex hull for given shape and returns it as {@link Polygon}.
9
- *
10
- * @remarks
11
- * Internally uses
12
- * [`grahamScan2()`](https://docs.thi.ng/umbrella/geom-hull/functions/grahamScan2.html).
13
- *
14
- * Currently implemented for:
15
- *
16
- * - {@link Arc}
17
- * - {@link Circle}
18
- * - {@link Ellipse}
19
- * - {@link Group} (only the listed child shape types are considered)
20
- * - {@link Points}
21
- * - {@link Polygon}
22
- * - {@link Polyline}
23
- * - {@link Quad}
24
- * - {@link Rect}
25
- * - {@link Triangle}
26
- *
27
- * @param shape
28
- */
29
- export const convexHull = defmulti(__dispatch, {
7
+ const convexHull = defmulti(
8
+ __dispatch,
9
+ {
30
10
  arc: "group",
31
11
  circle: "tri",
32
12
  cubic: "group",
@@ -36,9 +16,14 @@ export const convexHull = defmulti(__dispatch, {
36
16
  polyline: "points",
37
17
  quad: "points",
38
18
  quadratic: "group",
39
- rect: "tri",
40
- }, {
19
+ rect: "tri"
20
+ },
21
+ {
41
22
  group: ($) => new Polygon(grahamScan2(vertices($)), __copyAttribs($)),
42
23
  points: ($) => new Polygon(grahamScan2($.points), __copyAttribs($)),
43
- tri: ($) => new Polygon(vertices($), __copyAttribs($)),
44
- });
24
+ tri: ($) => new Polygon(vertices($), __copyAttribs($))
25
+ }
26
+ );
27
+ export {
28
+ convexHull
29
+ };
package/cubic.js CHANGED
@@ -4,9 +4,17 @@ import { cubicFromQuadratic as _quad } from "@thi.ng/geom-splines/cubic-quadrati
4
4
  import { Cubic } from "./api/cubic.js";
5
5
  import { __copyAttribs } from "./internal/copy.js";
6
6
  import { __pclike } from "./internal/pclike.js";
7
- export function cubic(...args) {
8
- return __pclike(Cubic, args);
7
+ function cubic(...args) {
8
+ return __pclike(Cubic, args);
9
9
  }
10
- export const cubicFromArc = (arc) => _arc(arc.pos, arc.r, arc.axis, arc.start, arc.end).map((c) => new Cubic(c, __copyAttribs(arc)));
11
- export const cubicFromLine = (a, b, attribs) => new Cubic(_line(a, b), attribs);
12
- export const cubicFromQuadratic = (a, b, c, attribs) => new Cubic(_quad(a, b, c), attribs);
10
+ const cubicFromArc = (arc) => _arc(arc.pos, arc.r, arc.axis, arc.start, arc.end).map(
11
+ (c) => new Cubic(c, __copyAttribs(arc))
12
+ );
13
+ const cubicFromLine = (a, b, attribs) => new Cubic(_line(a, b), attribs);
14
+ const cubicFromQuadratic = (a, b, c, attribs) => new Cubic(_quad(a, b, c), attribs);
15
+ export {
16
+ cubic,
17
+ cubicFromArc,
18
+ cubicFromLine,
19
+ cubicFromQuadratic
20
+ };
package/edges.js CHANGED
@@ -5,70 +5,37 @@ import { asPolyline } from "./as-polyline.js";
5
5
  import { __dispatch } from "./internal/dispatch.js";
6
6
  import { __edges } from "./internal/edges.js";
7
7
  import { vertices } from "./vertices.js";
8
- /**
9
- * Extracts the edges of given shape's boundary and returns them as an iterable
10
- * of vector pairs.
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 AABB}
19
- * - {@link Arc}
20
- * - {@link BPatch}
21
- * - {@link Circle}
22
- * - {@link Cubic}
23
- * - {@link Ellipse}
24
- * - {@link Group}
25
- * - {@link Line}
26
- * - {@link Path}
27
- * - {@link Polygon}
28
- * - {@link Polyline}
29
- * - {@link Quad}
30
- * - {@link Quadratic}
31
- * - {@link Rect}
32
- * - {@link Triangle}
33
- *
34
- * The implementations for the following shapes **do not** support
35
- * [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html)
36
- * (all others do):
37
- *
38
- * - {@link Line}
39
- * - {@link Polygon}
40
- * - {@link Polyline}
41
- * - {@link Quad}
42
- * - {@link Rect}
43
- * - {@link Triangle}
44
- *
45
- * @param shape
46
- * @param opts
47
- */
48
- export const edges = defmulti(__dispatch, {
8
+ const edges = defmulti(
9
+ __dispatch,
10
+ {
49
11
  cubic: "arc",
50
12
  ellipse: "circle",
51
13
  line: "polyline",
52
14
  quad: "poly",
53
15
  quadratic: "arc",
54
- tri: "poly",
55
- }, {
16
+ tri: "poly"
17
+ },
18
+ {
56
19
  aabb: ($) => {
57
- const [a, b, c, d, e, f, g, h] = vertices($);
58
- return [
59
- [a, b],
60
- [b, c],
61
- [c, d],
62
- [d, a], // bottom
63
- [e, f],
64
- [f, g],
65
- [g, h],
66
- [h, e], // top
67
- [a, e],
68
- [b, f], // left
69
- [c, g],
70
- [d, h], // right
71
- ];
20
+ const [a, b, c, d, e, f, g, h] = vertices($);
21
+ return [
22
+ [a, b],
23
+ [b, c],
24
+ [c, d],
25
+ [d, a],
26
+ // bottom
27
+ [e, f],
28
+ [f, g],
29
+ [g, h],
30
+ [h, e],
31
+ // top
32
+ [a, e],
33
+ [b, f],
34
+ // left
35
+ [c, g],
36
+ [d, h]
37
+ // right
38
+ ];
72
39
  },
73
40
  arc: ($, opts) => __edges(asPolyline($, opts).points, false),
74
41
  bpatch: ($) => $.edges(),
@@ -77,5 +44,9 @@ export const edges = defmulti(__dispatch, {
77
44
  path: ($, opts) => __edges(asPolygon($, opts).points, $.closed),
78
45
  poly: ($) => __edges($.points, true),
79
46
  polyline: ($) => __edges($.points),
80
- rect: ($) => __edges(vertices($), true),
81
- });
47
+ rect: ($) => __edges(vertices($), true)
48
+ }
49
+ );
50
+ export {
51
+ edges
52
+ };
package/ellipse.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Ellipse } from "./api/ellipse.js";
2
2
  import { __argsVV } from "./internal/args.js";
3
- export function ellipse(...args) {
4
- return new Ellipse(...__argsVV(args));
3
+ function ellipse(...args) {
4
+ return new Ellipse(...__argsVV(args));
5
5
  }
6
+ export {
7
+ ellipse
8
+ };
@@ -12,68 +12,85 @@ import { __collBounds } from "./internal/bounds.js";
12
12
  import { mapPoint } from "./map-point.js";
13
13
  import { transform } from "./transform.js";
14
14
  import { unmapPoint } from "./unmap-point.js";
15
- /** @internal */
16
- const __translateScale = (tmat, smat, shape, preTrans, postTrans, scale) => transform(shape, concat([], tmat([], postTrans), smat([], scale), tmat([], preTrans)));
17
- /**
18
- * Uniformly rescales & repositions given 2D `shape` such that it fits into
19
- * destination bounds. Returns transformed copy of `shape`.
20
- *
21
- * @param shape
22
- * @param dest
23
- */
24
- export const fitIntoBounds2 = (shape, dest) => {
25
- const src = bounds(shape);
26
- if (!src)
27
- return;
28
- const c = centroid(src);
29
- if (!c)
30
- return;
31
- return __translateScale(translation23, scale23, shape, neg(null, c), centroid(dest), minNonZero2(safeDiv(dest.size[0], src.size[0]), safeDiv(dest.size[1], src.size[1])));
15
+ const __translateScale = (tmat, smat, shape, preTrans, postTrans, scale) => transform(
16
+ shape,
17
+ concat([], tmat([], postTrans), smat([], scale), tmat([], preTrans))
18
+ );
19
+ const fitIntoBounds2 = (shape, dest) => {
20
+ const src = bounds(shape);
21
+ if (!src)
22
+ return;
23
+ const c = centroid(src);
24
+ if (!c)
25
+ return;
26
+ return __translateScale(
27
+ translation23,
28
+ scale23,
29
+ shape,
30
+ neg(null, c),
31
+ centroid(dest),
32
+ minNonZero2(
33
+ safeDiv(dest.size[0], src.size[0]),
34
+ safeDiv(dest.size[1], src.size[1])
35
+ )
36
+ );
32
37
  };
33
- /**
34
- * 3D version of {@link fitIntoBounds2}.
35
- *
36
- * @param shape
37
- * @param dest
38
- */
39
- export const fitIntoBounds3 = (shape, dest) => {
40
- const src = bounds(shape);
41
- if (!src)
42
- return;
43
- const c = centroid(src);
44
- if (!c)
45
- return;
46
- return __translateScale(translation44, scale44, shape, neg(null, c), centroid(dest), minNonZero3(safeDiv(dest.size[0], src.size[0]), safeDiv(dest.size[1], src.size[1]), safeDiv(dest.size[2], src.size[2])));
38
+ const fitIntoBounds3 = (shape, dest) => {
39
+ const src = bounds(shape);
40
+ if (!src)
41
+ return;
42
+ const c = centroid(src);
43
+ if (!c)
44
+ return;
45
+ return __translateScale(
46
+ translation44,
47
+ scale44,
48
+ shape,
49
+ neg(null, c),
50
+ centroid(dest),
51
+ minNonZero3(
52
+ safeDiv(dest.size[0], src.size[0]),
53
+ safeDiv(dest.size[1], src.size[1]),
54
+ safeDiv(dest.size[2], src.size[2])
55
+ )
56
+ );
47
57
  };
48
- /**
49
- * Version of {@link fitIntoBounds2} for multiple source shapes.
50
- *
51
- * @param shapes
52
- * @param dest
53
- */
54
- export const fitAllIntoBounds2 = (shapes, dest) => {
55
- const sbraw = __collBounds(shapes, bounds);
56
- if (!sbraw)
57
- return;
58
- const src = new Rect(...sbraw);
59
- const sx = safeDiv(dest.size[0], src.size[0]);
60
- const sy = safeDiv(dest.size[1], src.size[1]);
61
- const scale = sx > 0 ? (sy > 0 ? Math.min(sx, sy) : sx) : sy;
62
- const smat = scale23([], scale);
63
- const b = center(transform(src, smat), centroid(dest));
64
- const c1 = [];
65
- const c2 = [];
66
- const res = [];
67
- for (let i = shapes.length; i-- > 0;) {
68
- const s = shapes[i];
69
- const sc = centroid(s, c1);
70
- if (sc) {
71
- unmapPoint(b, mapPoint(src, sc), c2);
72
- res.push(__translateScale(translation23, scale23, s, neg(null, c1), c2, smat));
73
- }
74
- else {
75
- res.push(s);
76
- }
58
+ const fitAllIntoBounds2 = (shapes, dest) => {
59
+ const sbraw = __collBounds(shapes, bounds);
60
+ if (!sbraw)
61
+ return;
62
+ const src = new Rect(...sbraw);
63
+ const sx = safeDiv(dest.size[0], src.size[0]);
64
+ const sy = safeDiv(dest.size[1], src.size[1]);
65
+ const scale = sx > 0 ? sy > 0 ? Math.min(sx, sy) : sx : sy;
66
+ const smat = scale23([], scale);
67
+ const b = center(transform(src, smat), centroid(dest));
68
+ const c1 = [];
69
+ const c2 = [];
70
+ const res = [];
71
+ for (let i = shapes.length; i-- > 0; ) {
72
+ const s = shapes[i];
73
+ const sc = centroid(s, c1);
74
+ if (sc) {
75
+ unmapPoint(b, mapPoint(src, sc), c2);
76
+ res.push(
77
+ __translateScale(
78
+ translation23,
79
+ scale23,
80
+ s,
81
+ neg(null, c1),
82
+ c2,
83
+ smat
84
+ )
85
+ );
86
+ } else {
87
+ res.push(s);
77
88
  }
78
- return res;
89
+ }
90
+ return res;
91
+ };
92
+ export {
93
+ fitAllIntoBounds2,
94
+ fitIntoBounds2,
95
+ fitIntoBounds3
79
96
  };
package/flip.js CHANGED
@@ -1,30 +1,9 @@
1
1
  import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
2
2
  import { neg } from "@thi.ng/vectors/neg";
3
3
  import { __dispatch } from "./internal/dispatch.js";
4
- /**
5
- * Reverses vertex ordering or general direction (e.g. for {@link Ray}) of given
6
- * shape.
7
- *
8
- * @remarks
9
- * Currently implemented for:
10
- *
11
- * - {@link Arc}
12
- * - {@link Cubic}
13
- * - {@link Group} (only eligible shapes)
14
- * - {@link Line}
15
- * - {@link Path}
16
- * - {@link Points}
17
- * - {@link Points3}
18
- * - {@link Polygon}
19
- * - {@link Polyline}
20
- * - {@link Quad}
21
- * - {@link Quadratic}
22
- * - {@link Ray}
23
- * - {@link Triangle}
24
- *
25
- * @param shape
26
- */
27
- export const flip = defmulti(__dispatch, {
4
+ const flip = defmulti(
5
+ __dispatch,
6
+ {
28
7
  cubic: "points",
29
8
  line: "points",
30
9
  points3: "points",
@@ -32,30 +11,34 @@ export const flip = defmulti(__dispatch, {
32
11
  polyline: "points",
33
12
  quad: "points",
34
13
  quadratic: "points",
35
- tri: "points",
36
- }, {
14
+ tri: "points"
15
+ },
16
+ {
37
17
  [DEFAULT]: (x) => x,
38
18
  arc: ($) => {
39
- const t = $.start;
40
- $.start = $.end;
41
- $.end = t;
42
- $.cw = !$.cw;
43
- return $;
19
+ const t = $.start;
20
+ $.start = $.end;
21
+ $.end = t;
22
+ $.cw = !$.cw;
23
+ return $;
44
24
  },
45
25
  group: ($) => {
46
- $.children.forEach(flip);
47
- return $;
26
+ $.children.forEach(flip);
27
+ return $;
48
28
  },
49
29
  path: ($) => {
50
- // TODO
51
- return $;
30
+ return $;
52
31
  },
53
32
  points: ($) => {
54
- $.points.reverse();
55
- return $;
33
+ $.points.reverse();
34
+ return $;
56
35
  },
57
36
  ray: ($) => {
58
- $.dir = neg(null, $.dir);
59
- return $;
60
- },
61
- });
37
+ $.dir = neg(null, $.dir);
38
+ return $;
39
+ }
40
+ }
41
+ );
42
+ export {
43
+ flip
44
+ };
package/group.js CHANGED
@@ -1,2 +1,5 @@
1
1
  import { Group } from "./api/group.js";
2
- export const group = (attribs = {}, children) => new Group(attribs, children);
2
+ const group = (attribs = {}, children) => new Group(attribs, children);
3
+ export {
4
+ group
5
+ };