@thi.ng/geom 6.0.7 → 6.0.9

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 -30
  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
@@ -6,117 +6,62 @@ import { asPolyline } from "./as-polyline.js";
6
6
  import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
7
7
  import { __dispatch } from "./internal/dispatch.js";
8
8
  import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
9
- /**
10
- * Splits given shape into {@link Polyline} segments of given (max) arc length.
11
- * Returns a {@link Group} of shapes/polylines.
12
- *
13
- * @remarks
14
- * If the shape has a `__samples` attribute, it will be removed in the result to
15
- * avoid recursive application.
16
- *
17
- * Currently only implemented for:
18
- *
19
- * - {@link Group}
20
- * - {@link Polyline}
21
- *
22
- * Other shape types will be attempted to be auto-converted via
23
- * {@link asPolyline} first.
24
- *
25
- * Nested groups are NOT supported. Groups are processing their child shapes and
26
- * forming new child groups of given max. arc lengths and potentially splitting
27
- * shapes if they don't fit within the current subgroup...
28
- *
29
- * @example
30
- * ```ts
31
- * // circle (to be sampled as octagon)
32
- * const a = circle(100, { stroke: "red", __samples: 8 });
33
- *
34
- * // inner square of circle
35
- * const b = inscribedSquare(a, { stroke: "blue" });
36
- *
37
- * // process as group, split/partition into subgroups of arclength max. 200
38
- * splitArcLength(group({}, [a, b]), 200);
39
- * ```
40
- *
41
- * Result serialized to SVG:
42
- *
43
- * ```svg
44
- * <g>
45
- * <g>
46
- * <polyline fill="none" points="100,0 70.7,70.7 0.0,100 -43.4,82.0" stroke="red"/>
47
- * </g>
48
- * <g>
49
- * <polyline fill="none" points="-43.4,82.0 -70.7,70.7 -100,0.0 -70.7,-70.7 -54.7,-77.3" stroke="red"/>
50
- * </g>
51
- * <g>
52
- * <polyline fill="none" points="-54.7,-77.3 -0.0,-100 70.7,-70.7 95.3,-11.4" stroke="red"/>
53
- * </g>
54
- * <g>
55
- * <!-- last segment of circle -->
56
- * <polyline fill="none" points="95.3,-11.4 100,0" stroke="red"/>
57
- * <!-- first segment of rect -->
58
- * <polyline fill="none" points="-70.7,-70.7 70.7,-70.7 70.7,-24.4" stroke="blue"/>
59
- * </g>
60
- * <g>
61
- * <polyline fill="none" points="70.7,-24.4 70.7,70.7 -34.2,70.7" stroke="blue"/>
62
- * </g>
63
- * <g>
64
- * <polyline fill="none" points="-34.2,70.7 -70.7,70.7 -70.7,-70.7" stroke="blue"/>
65
- * </g>
66
- * </g>
67
- * ```
68
- *
69
- * @param shape
70
- * @param dist
71
- */
72
- export const splitArcLength = defmulti(__dispatch, {}, {
9
+ const splitArcLength = defmulti(
10
+ __dispatch,
11
+ {},
12
+ {
73
13
  [DEFAULT]: ($, d) => splitArcLength(asPolyline($), d),
74
14
  group: ($, d) => {
75
- const groups = [];
76
- let curr = [];
77
- let currLen = 0;
78
- const queue = $.children.slice().reverse();
79
- while (queue.length) {
80
- const child = queue.pop();
81
- const polyline = asPolyline(child);
82
- const sampler = new Sampler(polyline.points);
83
- const len = sampler.totalLength();
84
- if (currLen + len <= d) {
85
- curr.push(polyline);
86
- currLen += len;
87
- }
88
- else {
89
- const remainingLen = d - currLen;
90
- const [fill, next] = sampler.splitAt(remainingLen / len);
91
- curr.push(new Polyline(fill, __attribs(child)));
92
- groups.push(new Group({}, curr));
93
- curr = [];
94
- currLen = 0;
95
- queue.push(new Polyline(next, __attribs(child)));
96
- }
15
+ const groups = [];
16
+ let curr = [];
17
+ let currLen = 0;
18
+ const queue = $.children.slice().reverse();
19
+ while (queue.length) {
20
+ const child = queue.pop();
21
+ const polyline = asPolyline(child);
22
+ const sampler = new Sampler(polyline.points);
23
+ const len = sampler.totalLength();
24
+ if (currLen + len <= d) {
25
+ curr.push(polyline);
26
+ currLen += len;
27
+ } else {
28
+ const remainingLen = d - currLen;
29
+ const [fill, next] = sampler.splitAt(remainingLen / len);
30
+ curr.push(new Polyline(fill, __attribs(child)));
31
+ groups.push(new Group({}, curr));
32
+ curr = [];
33
+ currLen = 0;
34
+ queue.push(new Polyline(next, __attribs(child)));
97
35
  }
98
- if (curr.length)
99
- groups.push(new Group({}, curr));
100
- return new Group(__attribs($), groups);
36
+ }
37
+ if (curr.length)
38
+ groups.push(new Group({}, curr));
39
+ return new Group(__attribs($), groups);
101
40
  },
102
41
  polyline: ($, d) => {
103
- const chunks = [];
104
- let pts = $.points;
105
- while (true) {
106
- const sampler = new Sampler(pts);
107
- const total = sampler.totalLength();
108
- if (total > d) {
109
- const parts = sampler.splitAt(d / total);
110
- if (!parts)
111
- break;
112
- chunks.push(parts[0]);
113
- pts = parts[1];
114
- }
115
- else {
116
- chunks.push(pts);
117
- break;
118
- }
42
+ const chunks = [];
43
+ let pts = $.points;
44
+ while (true) {
45
+ const sampler = new Sampler(pts);
46
+ const total = sampler.totalLength();
47
+ if (total > d) {
48
+ const parts = sampler.splitAt(d / total);
49
+ if (!parts)
50
+ break;
51
+ chunks.push(parts[0]);
52
+ pts = parts[1];
53
+ } else {
54
+ chunks.push(pts);
55
+ break;
119
56
  }
120
- return new Group(__attribs($), __pointArraysAsShapes(Polyline, chunks));
121
- },
122
- });
57
+ }
58
+ return new Group(
59
+ __attribs($),
60
+ __pointArraysAsShapes(Polyline, chunks)
61
+ );
62
+ }
63
+ }
64
+ );
65
+ export {
66
+ splitArcLength
67
+ };
package/split-at.js CHANGED
@@ -13,31 +13,51 @@ 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
- */
31
- export const splitAt = defmulti(__dispatch, {}, {
16
+ const splitAt = defmulti(
17
+ __dispatch,
18
+ {},
19
+ {
32
20
  arc: ($, t) => {
33
- const theta = fit01(t, $.start, $.end);
34
- return [
35
- new Arc(set([], $.pos), set([], $.r), $.axis, $.start, theta, $.xl, $.cw, __copyAttribs($)),
36
- new Arc(set([], $.pos), set([], $.r), $.axis, theta, $.end, $.xl, $.cw, __copyAttribs($)),
37
- ];
21
+ const theta = fit01(t, $.start, $.end);
22
+ return [
23
+ new Arc(
24
+ set([], $.pos),
25
+ set([], $.r),
26
+ $.axis,
27
+ $.start,
28
+ theta,
29
+ $.xl,
30
+ $.cw,
31
+ __copyAttribs($)
32
+ ),
33
+ new Arc(
34
+ set([], $.pos),
35
+ set([], $.r),
36
+ $.axis,
37
+ theta,
38
+ $.end,
39
+ $.xl,
40
+ $.cw,
41
+ __copyAttribs($)
42
+ )
43
+ ];
38
44
  },
39
- cubic: ({ attribs, points }, t) => cubicSplitAt(points[0], points[1], points[2], points[3], t).map((pts) => new Cubic(pts, { ...attribs })),
40
- line: ({ attribs, points }, t) => __splitLine(points[0], points[1], t).map((pts) => new Line(pts, { ...attribs })),
41
- polyline: ($, t) => __pointArraysAsShapes(Polyline, new Sampler($.points).splitAt(t), $.attribs),
42
- quadratic: ({ attribs, points }, t) => quadraticSplitAt(points[0], points[1], points[2], t).map((pts) => new Quadratic(pts, { ...attribs })),
43
- });
45
+ cubic: ({ attribs, points }, t) => cubicSplitAt(points[0], points[1], points[2], points[3], t).map(
46
+ (pts) => new Cubic(pts, { ...attribs })
47
+ ),
48
+ line: ({ attribs, points }, t) => __splitLine(points[0], points[1], t).map(
49
+ (pts) => new Line(pts, { ...attribs })
50
+ ),
51
+ polyline: ($, t) => __pointArraysAsShapes(
52
+ Polyline,
53
+ new Sampler($.points).splitAt(t),
54
+ $.attribs
55
+ ),
56
+ quadratic: ({ attribs, points }, t) => quadraticSplitAt(points[0], points[1], points[2], t).map(
57
+ (pts) => new Quadratic(pts, { ...attribs })
58
+ )
59
+ }
60
+ );
61
+ export {
62
+ splitAt
63
+ };
package/split-near.js CHANGED
@@ -12,27 +12,33 @@ import { __copyAttribs } from "./internal/copy.js";
12
12
  import { __dispatch } from "./internal/dispatch.js";
13
13
  import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
14
14
  import { __splitLine } from "./internal/split.js";
15
- /**
16
- * Similar to {@link splitAt}, but instead of taking a normalized parametric
17
- * split position, splits the given curve at the closest point to `p`.
18
- *
19
- * @remarks
20
- * Currently only implemented for:
21
- *
22
- * - {@link Cubic}
23
- * - {@link Line}
24
- * - {@link Polyline}
25
- * - {@link Quadratic}
26
- *
27
- * @param shape - shape to operate on
28
- * @param p - split point
29
- */
30
- export const splitNearPoint = defmulti(__dispatch, {}, {
31
- cubic: ({ points, attribs }, p) => splitCubicNearPoint(p, points[0], points[1], points[2], points[3]).map((pts) => new Cubic(pts, { ...attribs })),
15
+ const splitNearPoint = defmulti(
16
+ __dispatch,
17
+ {},
18
+ {
19
+ cubic: ({ points, attribs }, p) => splitCubicNearPoint(
20
+ p,
21
+ points[0],
22
+ points[1],
23
+ points[2],
24
+ points[3]
25
+ ).map((pts) => new Cubic(pts, { ...attribs })),
32
26
  line: ($, p) => {
33
- const t = closestT(p, $.points[0], $.points[1]) || 0;
34
- return __splitLine($.points[0], $.points[1], clamp01(t)).map((pts) => new Line(pts, __copyAttribs($)));
27
+ const t = closestT(p, $.points[0], $.points[1]) || 0;
28
+ return __splitLine($.points[0], $.points[1], clamp01(t)).map(
29
+ (pts) => new Line(pts, __copyAttribs($))
30
+ );
35
31
  },
36
- polyline: ($, p) => __pointArraysAsShapes(Polyline, new Sampler($.points).splitNear(p), $.attribs),
37
- quadratic: ({ points, attribs }, p) => quadraticSplitNearPoint(p, points[0], points[1], points[2]).map((pts) => new Quadratic(pts, { ...attribs })),
38
- });
32
+ polyline: ($, p) => __pointArraysAsShapes(
33
+ Polyline,
34
+ new Sampler($.points).splitNear(p),
35
+ $.attribs
36
+ ),
37
+ quadratic: ({ points, attribs }, p) => quadraticSplitNearPoint(p, points[0], points[1], points[2]).map(
38
+ (pts) => new Quadratic(pts, { ...attribs })
39
+ )
40
+ }
41
+ );
42
+ export {
43
+ splitNearPoint
44
+ };
package/subdiv-curve.js CHANGED
@@ -7,81 +7,42 @@ import { asPolygon } from "./as-polygon.js";
7
7
  import { asPolyline } from "./as-polyline.js";
8
8
  import { __copyAttribs } from "./internal/copy.js";
9
9
  import { __dispatch } from "./internal/dispatch.js";
10
- /**
11
- * Recursively applies
12
- * [`SubdivKernel`](https://docs.thi.ng/umbrella/geom-api/interfaces/SubdivKernel.html)
13
- * to given shape/boundary. See
14
- * [thi.ng/geom-subdiv-curve](https://thi.ng/thi.ng/geom-subdiv-curve) package
15
- * for further details.
16
- *
17
- * @remarks
18
- * By default only applies a single iteration.
19
- *
20
- * Currently only implemented for:
21
- *
22
- * - {@link Arc}
23
- * - {@link Circle}
24
- * - {@link Ellipse}
25
- * - {@link Line}
26
- * - {@link Polygon}
27
- * - {@link Polyline}
28
- * - {@link Quad}
29
- * - {@link Rect}
30
- * - {@link Triangle}
31
- *
32
- * @example
33
- * ```ts
34
- *
35
- * ```
36
- *
37
- * @param shape
38
- * @param kernel
39
- * @param iter
40
- */
41
- export const subdivCurve = defmulti(__dispatch, {
10
+ const subdivCurve = defmulti(
11
+ __dispatch,
12
+ {
42
13
  ellipse: "circle",
43
14
  line: "polyline",
44
15
  quad: "poly",
45
16
  rect: "circle",
46
- tri: "poly",
47
- }, {
17
+ tri: "poly"
18
+ },
19
+ {
48
20
  arc: ($, kernel, iter = 1) => subdivCurve(asPolyline($), kernel, iter),
49
21
  circle: ($, kernel, iter = 1) => subdivCurve(asPolygon($), kernel, iter),
50
- poly: ($, kernel, iter = 1) => new Polygon(subdivide($.points, kernel, iter), __copyAttribs($)),
51
- polyline: ($, kernel, iter = 1) => new Polyline(subdivide($.points, kernel, iter), __copyAttribs($)),
52
- });
53
- /**
54
- * Re-export of thi.ng/geom-subdiv-curve
55
- * [`SUBDIV_MID_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_MID_OPEN.html)
56
- */
57
- export const SUBDIV_MID_OPEN = sdc.SUBDIV_MID_OPEN;
58
- /**
59
- * Re-export of thi.ng/geom-subdiv-curve
60
- * [`SUBDIV_MID_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_MID_CLOSED.html)
61
- */
62
- export const SUBDIV_MID_CLOSED = sdc.SUBDIV_MID_CLOSED;
63
- /**
64
- * Re-export of thi.ng/geom-subdiv-curve
65
- * [`SUBDIV_THIRDS_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_THIRDS_OPEN.html)
66
- */
67
- export const SUBDIV_THIRDS_OPEN = sdc.SUBDIV_THIRDS_OPEN;
68
- /**
69
- * Re-export of thi.ng/geom-subdiv-curve
70
- * [`SUBDIV_THIRDS_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_THIRDS_CLOSED.html)
71
- */
72
- export const SUBDIV_THIRDS_CLOSED = sdc.SUBDIV_THIRDS_CLOSED;
73
- /**
74
- * Re-export of thi.ng/geom-subdiv-curve
75
- * [`SUBDIV_CHAIKIN_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CHAIKIN_OPEN.html)
76
- */
77
- export const SUBDIV_CHAIKIN_OPEN = sdc.SUBDIV_CHAIKIN_OPEN;
78
- /**
79
- * Re-export of thi.ng/geom-subdiv-curve
80
- * [`SUBDIV_CHAIKIN_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CHAIKIN_CLOSED.html)
81
- */
82
- export const SUBDIV_CHAIKIN_CLOSED = sdc.SUBDIV_CHAIKIN_CLOSED;
83
- /**
84
- * Re-export of thi.ng/geom-subdiv-curve
85
- * [`SUBDIV_CUBIC_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CUBIC_CLOSED.html)
86
- */
87
- export const SUBDIV_CUBIC_CLOSED = sdc.SUBDIV_CUBIC_CLOSED;
22
+ poly: ($, kernel, iter = 1) => new Polygon(
23
+ subdivide($.points, kernel, iter),
24
+ __copyAttribs($)
25
+ ),
26
+ polyline: ($, kernel, iter = 1) => new Polyline(
27
+ subdivide($.points, kernel, iter),
28
+ __copyAttribs($)
29
+ )
30
+ }
31
+ );
32
+ const SUBDIV_MID_OPEN = sdc.SUBDIV_MID_OPEN;
33
+ const SUBDIV_MID_CLOSED = sdc.SUBDIV_MID_CLOSED;
34
+ const SUBDIV_THIRDS_OPEN = sdc.SUBDIV_THIRDS_OPEN;
35
+ const SUBDIV_THIRDS_CLOSED = sdc.SUBDIV_THIRDS_CLOSED;
36
+ const SUBDIV_CHAIKIN_OPEN = sdc.SUBDIV_CHAIKIN_OPEN;
37
+ const SUBDIV_CHAIKIN_CLOSED = sdc.SUBDIV_CHAIKIN_CLOSED;
38
+ const SUBDIV_CUBIC_CLOSED = sdc.SUBDIV_CUBIC_CLOSED;
39
+ export {
40
+ SUBDIV_CHAIKIN_CLOSED,
41
+ SUBDIV_CHAIKIN_OPEN,
42
+ SUBDIV_CUBIC_CLOSED,
43
+ SUBDIV_MID_CLOSED,
44
+ SUBDIV_MID_OPEN,
45
+ SUBDIV_THIRDS_CLOSED,
46
+ SUBDIV_THIRDS_OPEN,
47
+ subdivCurve
48
+ };
package/tangent-at.js CHANGED
@@ -7,34 +7,22 @@ import { HALF_PI, TAU } from "@thi.ng/math/api";
7
7
  import { direction2 } 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
- */
29
- export const tangentAt = defmulti(__dispatch, {
10
+ const tangentAt = defmulti(
11
+ __dispatch,
12
+ {
30
13
  quad: "poly",
31
- tri: "poly",
32
- }, {
14
+ tri: "poly"
15
+ },
16
+ {
33
17
  circle: (_, t) => cossin(TAU * t + HALF_PI),
34
18
  cubic: ({ points }, t) => cubicTangentAt([], points[0], points[1], points[2], points[3], t),
35
19
  line: ({ points }) => direction2([], points[0], points[1]),
36
20
  poly: ($, t) => new Sampler($.points, true).tangentAt(t),
37
21
  polyline: ($, t) => new Sampler($.points).tangentAt(t),
38
22
  quadratic: ({ points }, t) => quadraticTangentAt([], points[0], points[1], points[2], t),
39
- rect: ($, t) => new Sampler(vertices($), true).tangentAt(t),
40
- });
23
+ rect: ($, t) => new Sampler(vertices($), true).tangentAt(t)
24
+ }
25
+ );
26
+ export {
27
+ tangentAt
28
+ };
package/tessellate.js CHANGED
@@ -10,51 +10,26 @@ import { mapcat } from "@thi.ng/transducers/mapcat";
10
10
  import { Group } from "./api/group.js";
11
11
  import { __dispatch } from "./internal/dispatch.js";
12
12
  import { vertices } from "./vertices.js";
13
- /**
14
- * Recursively tessellates shape using provided
15
- * [`Tessellator`](https://docs.thi.ng/umbrella/geom-api/types/Tessellator.html)
16
- * functions. See
17
- * [thi.ng/geom-tessellate](https://thi.ng/thi.ng/geom-tessellate) package for
18
- * more details.
19
- *
20
- * @remarks
21
- * Implemented for all shapes supported by {@link vertices}. For groups, every
22
- * child shape will be tessellated individually.
23
- *
24
- * @param shape
25
- * @param tessellators
26
- */
27
- export const tessellate = defmulti(__dispatch, {}, {
13
+ const tessellate = defmulti(
14
+ __dispatch,
15
+ {},
16
+ {
28
17
  [DEFAULT]: ($, fns) => _tessellate(vertices($), fns),
29
- group: ($, fns) => mapcat((x) => _tessellate(vertices(x), fns), $.children),
30
- });
31
- /**
32
- * Alias for thi.ng/geom-tessellate
33
- * [`earCut2`](https://docs.thi.ng/umbrella/geom-tessellate/functions/earCut2.html)
34
- */
35
- export const TESSELLATE_EARCUT = earCut2;
36
- /**
37
- * Alias for thi.ng/geom-tessellate
38
- * [`edgeSplit`](https://docs.thi.ng/umbrella/geom-tessellate/functions/edgeSplit.html)
39
- */
40
- export const TESSELLATE_EDGE_SPLIT = edgeSplit;
41
- /**
42
- * Alias for thi.ng/geom-tessellate
43
- * [`tesselInset`](https://docs.thi.ng/umbrella/geom-tessellate/functions/tesselInset.html)
44
- */
45
- export const TESSELLATE_INSET = tesselInset;
46
- /**
47
- * Alias for thi.ng/geom-tessellate
48
- * [`quadFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/quadFan.html)
49
- */
50
- export const TESSELLATE_QUAD_FAN = quadFan;
51
- /**
52
- * Alias for thi.ng/geom-tessellate
53
- * [`rimTris`](https://docs.thi.ng/umbrella/geom-tessellate/functions/rimTris.html)
54
- */
55
- export const TESSELLATE_RIM_TRIS = rimTris;
56
- /**
57
- * Alias for thi.ng/geom-tessellate
58
- * [`triFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/triFan.html)
59
- */
60
- export const TESSELLATE_TRI_FAN = triFan;
18
+ group: ($, fns) => mapcat((x) => _tessellate(vertices(x), fns), $.children)
19
+ }
20
+ );
21
+ const TESSELLATE_EARCUT = earCut2;
22
+ const TESSELLATE_EDGE_SPLIT = edgeSplit;
23
+ const TESSELLATE_INSET = tesselInset;
24
+ const TESSELLATE_QUAD_FAN = quadFan;
25
+ const TESSELLATE_RIM_TRIS = rimTris;
26
+ const TESSELLATE_TRI_FAN = triFan;
27
+ export {
28
+ TESSELLATE_EARCUT,
29
+ TESSELLATE_EDGE_SPLIT,
30
+ TESSELLATE_INSET,
31
+ TESSELLATE_QUAD_FAN,
32
+ TESSELLATE_RIM_TRIS,
33
+ TESSELLATE_TRI_FAN,
34
+ tessellate
35
+ };
package/text.js CHANGED
@@ -1,2 +1,5 @@
1
1
  import { Text } from "./api/text.js";
2
- export const text = (pos, body, attribs) => new Text(pos, body, attribs);
2
+ const text = (pos, body, attribs) => new Text(pos, body, attribs);
3
+ export {
4
+ text
5
+ };
@@ -14,64 +14,36 @@ import { asPolygon } from "./as-polygon.js";
14
14
  import { asPolyline } from "./as-polyline.js";
15
15
  import { __copyAttribs } from "./internal/copy.js";
16
16
  import { __dispatch } from "./internal/dispatch.js";
17
- import { __transformedShapePoints as tx, __transformedShapePoints3 as tx3, } from "./internal/transform.js";
18
- /**
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.
22
- *
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
55
- */
56
- export const transformVertices = defmulti(__dispatch, {
17
+ import {
18
+ __transformedShapePoints as tx,
19
+ __transformedShapePoints3 as tx3
20
+ } from "./internal/transform.js";
21
+ const transformVertices = defmulti(
22
+ __dispatch,
23
+ {
57
24
  circle: "rect",
58
- ellipse: "circle",
59
- }, {
25
+ ellipse: "circle"
26
+ },
27
+ {
60
28
  arc: ($, fn) => transformVertices(asPolyline($), fn),
61
29
  cubic: tx(Cubic),
62
30
  group: ($, fn) => $.copyTransformed((x) => transformVertices(x, fn)),
63
31
  line: tx(Line),
64
- path: ($, fn) => new Path([
65
- ...map((s) => s.type === "m"
66
- ? {
67
- type: s.type,
68
- point: mulV([], fn(s.point), s.point),
69
- }
70
- : {
71
- type: s.type,
72
- geo: transformVertices(s.geo, fn),
73
- }, $.segments),
74
- ], __copyAttribs($)),
32
+ path: ($, fn) => new Path(
33
+ [
34
+ ...map(
35
+ (s) => s.type === "m" ? {
36
+ type: s.type,
37
+ point: mulV([], fn(s.point), s.point)
38
+ } : {
39
+ type: s.type,
40
+ geo: transformVertices(s.geo, fn)
41
+ },
42
+ $.segments
43
+ )
44
+ ],
45
+ __copyAttribs($)
46
+ ),
75
47
  points: tx(Points),
76
48
  points3: tx3(Points3),
77
49
  poly: tx(Polygon),
@@ -79,5 +51,9 @@ export const transformVertices = defmulti(__dispatch, {
79
51
  quad: tx(Quad),
80
52
  quadratic: tx(Quadratic),
81
53
  rect: ($, fn) => transformVertices(asPolygon($), fn),
82
- tri: tx(Triangle),
83
- });
54
+ tri: tx(Triangle)
55
+ }
56
+ );
57
+ export {
58
+ transformVertices
59
+ };