@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/api/quadratic.js CHANGED
@@ -1,29 +1,32 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
- export class Quadratic extends APC {
5
- constructor(points, attribs) {
6
- super(points, attribs);
7
- __ensureNumVerts(this.points.length, 3);
8
- }
9
- get type() {
10
- return "quadratic";
11
- }
12
- copy() {
13
- return __copyShape(Quadratic, this);
14
- }
15
- withAttribs(attribs) {
16
- return new Quadratic(this.points, attribs);
17
- }
18
- toHiccup() {
19
- return [
20
- "path",
21
- this.attribs,
22
- [["M", this.points[0]], ...this.toHiccupPathSegments()],
23
- ];
24
- }
25
- toHiccupPathSegments() {
26
- const pts = this.points;
27
- return [["Q", pts[1], pts[2]]];
28
- }
4
+ class Quadratic extends APC {
5
+ constructor(points, attribs) {
6
+ super(points, attribs);
7
+ __ensureNumVerts(this.points.length, 3);
8
+ }
9
+ get type() {
10
+ return "quadratic";
11
+ }
12
+ copy() {
13
+ return __copyShape(Quadratic, this);
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Quadratic(this.points, attribs);
17
+ }
18
+ toHiccup() {
19
+ return [
20
+ "path",
21
+ this.attribs,
22
+ [["M", this.points[0]], ...this.toHiccupPathSegments()]
23
+ ];
24
+ }
25
+ toHiccupPathSegments() {
26
+ const pts = this.points;
27
+ return [["Q", pts[1], pts[2]]];
28
+ }
29
29
  }
30
+ export {
31
+ Quadratic
32
+ };
package/api/ray.js CHANGED
@@ -1,30 +1,34 @@
1
1
  import { maddN2 } from "@thi.ng/vectors/maddn";
2
2
  import { set } from "@thi.ng/vectors/set";
3
3
  import { __copyAttribs } from "../internal/copy.js";
4
- export class Ray {
5
- pos;
6
- dir;
7
- attribs;
8
- constructor(pos, dir, attribs) {
9
- this.pos = pos;
10
- this.dir = dir;
11
- this.attribs = attribs;
12
- }
13
- get type() {
14
- return "ray";
15
- }
16
- copy() {
17
- return new Ray(set([], this.pos), set([], this.dir), __copyAttribs(this));
18
- }
19
- withAttribs(attribs) {
20
- return new Ray(this.pos, this.dir, attribs);
21
- }
22
- toHiccup() {
23
- return [
24
- "line",
25
- this.attribs,
26
- this.pos,
27
- maddN2([], this.dir, 1e6, this.pos),
28
- ];
29
- }
4
+ class Ray {
5
+ constructor(pos, dir, attribs) {
6
+ this.pos = pos;
7
+ this.dir = dir;
8
+ this.attribs = attribs;
9
+ }
10
+ get type() {
11
+ return "ray";
12
+ }
13
+ copy() {
14
+ return new Ray(
15
+ set([], this.pos),
16
+ set([], this.dir),
17
+ __copyAttribs(this)
18
+ );
19
+ }
20
+ withAttribs(attribs) {
21
+ return new Ray(this.pos, this.dir, attribs);
22
+ }
23
+ toHiccup() {
24
+ return [
25
+ "line",
26
+ this.attribs,
27
+ this.pos,
28
+ maddN2([], this.dir, 1e6, this.pos)
29
+ ];
30
+ }
30
31
  }
32
+ export {
33
+ Ray
34
+ };
package/api/rect.js CHANGED
@@ -6,33 +6,38 @@ import { set2 } from "@thi.ng/vectors/set";
6
6
  import { subN2 } from "@thi.ng/vectors/subn";
7
7
  import { __asVec } from "../internal/args.js";
8
8
  import { __copyAttribs } from "../internal/copy.js";
9
- export class Rect {
10
- pos;
11
- attribs;
12
- size;
13
- constructor(pos = [0, 0], size = 1, attribs) {
14
- this.pos = pos;
15
- this.attribs = attribs;
16
- this.size = __asVec(size);
17
- }
18
- get type() {
19
- return "rect";
20
- }
21
- copy() {
22
- return new Rect(set2([], this.pos), set2([], this.size), __copyAttribs(this));
23
- }
24
- withAttribs(attribs) {
25
- return new Rect(this.pos, this.size, attribs);
26
- }
27
- max() {
28
- return add2([], this.pos, this.size);
29
- }
30
- offset(offset) {
31
- subN2(null, this.pos, offset);
32
- max2(null, addN2(null, this.size, offset * 2), ZERO2);
33
- return this;
34
- }
35
- toHiccup() {
36
- return ["rect", this.attribs, this.pos, this.size[0], this.size[1]];
37
- }
9
+ class Rect {
10
+ constructor(pos = [0, 0], size = 1, attribs) {
11
+ this.pos = pos;
12
+ this.attribs = attribs;
13
+ this.size = __asVec(size);
14
+ }
15
+ size;
16
+ get type() {
17
+ return "rect";
18
+ }
19
+ copy() {
20
+ return new Rect(
21
+ set2([], this.pos),
22
+ set2([], this.size),
23
+ __copyAttribs(this)
24
+ );
25
+ }
26
+ withAttribs(attribs) {
27
+ return new Rect(this.pos, this.size, attribs);
28
+ }
29
+ max() {
30
+ return add2([], this.pos, this.size);
31
+ }
32
+ offset(offset) {
33
+ subN2(null, this.pos, offset);
34
+ max2(null, addN2(null, this.size, offset * 2), ZERO2);
35
+ return this;
36
+ }
37
+ toHiccup() {
38
+ return ["rect", this.attribs, this.pos, this.size[0], this.size[1]];
39
+ }
38
40
  }
41
+ export {
42
+ Rect
43
+ };
package/api/sphere.js CHANGED
@@ -1,24 +1,24 @@
1
1
  import { set3 } from "@thi.ng/vectors/set";
2
2
  import { __copyAttribs } from "../internal/copy.js";
3
- export class Sphere {
4
- pos;
5
- r;
6
- attribs;
7
- constructor(pos = [0, 0, 0], r = 1, attribs) {
8
- this.pos = pos;
9
- this.r = r;
10
- this.attribs = attribs;
11
- }
12
- get type() {
13
- return "sphere";
14
- }
15
- copy() {
16
- return new Sphere(set3([], this.pos), this.r, __copyAttribs(this));
17
- }
18
- withAttribs(attribs) {
19
- return new Sphere(this.pos, this.r, attribs);
20
- }
21
- toHiccup() {
22
- return ["sphere", this.attribs, this.pos, this.r];
23
- }
3
+ class Sphere {
4
+ constructor(pos = [0, 0, 0], r = 1, attribs) {
5
+ this.pos = pos;
6
+ this.r = r;
7
+ this.attribs = attribs;
8
+ }
9
+ get type() {
10
+ return "sphere";
11
+ }
12
+ copy() {
13
+ return new Sphere(set3([], this.pos), this.r, __copyAttribs(this));
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Sphere(this.pos, this.r, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["sphere", this.attribs, this.pos, this.r];
20
+ }
24
21
  }
22
+ export {
23
+ Sphere
24
+ };
package/api/text.js CHANGED
@@ -1,31 +1,24 @@
1
1
  import { set } from "@thi.ng/vectors/set";
2
2
  import { __copyAttribs } from "../internal/copy.js";
3
- /**
4
- * Basic stub for text elements. Currently, only a minimal set of geometry
5
- * operations are implemented for this type, however this type implements
6
- * [`IToHiccup`](https://docs.thi.ng/umbrella/api/interfaces/IToHiccup.html) and
7
- * so is useful as wrapper for inclusion of text elements in {@link Group}s with
8
- * other shape types.
9
- */
10
- export class Text {
11
- pos;
12
- body;
13
- attribs;
14
- constructor(pos, body, attribs) {
15
- this.pos = pos;
16
- this.body = body;
17
- this.attribs = attribs;
18
- }
19
- get type() {
20
- return "text";
21
- }
22
- copy() {
23
- return new Text(set([], this.pos), this.body, __copyAttribs(this));
24
- }
25
- withAttribs(attribs) {
26
- return new Text(this.pos, this.body, attribs);
27
- }
28
- toHiccup() {
29
- return ["text", this.attribs, this.pos, this.body];
30
- }
3
+ class Text {
4
+ constructor(pos, body, attribs) {
5
+ this.pos = pos;
6
+ this.body = body;
7
+ this.attribs = attribs;
8
+ }
9
+ get type() {
10
+ return "text";
11
+ }
12
+ copy() {
13
+ return new Text(set([], this.pos), this.body, __copyAttribs(this));
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Text(this.pos, this.body, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["text", this.attribs, this.pos, this.body];
20
+ }
31
21
  }
22
+ export {
23
+ Text
24
+ };
package/api/triangle.js CHANGED
@@ -1,21 +1,24 @@
1
1
  import { __copyShape } from "../internal/copy.js";
2
2
  import { __ensureNumVerts } from "../internal/pclike.js";
3
3
  import { APC } from "./apc.js";
4
- export class Triangle extends APC {
5
- constructor(points, attribs) {
6
- super(points, attribs);
7
- __ensureNumVerts(this.points.length, 3);
8
- }
9
- get type() {
10
- return "tri";
11
- }
12
- copy() {
13
- return __copyShape(Triangle, this);
14
- }
15
- withAttribs(attribs) {
16
- return new Triangle(this.points, attribs);
17
- }
18
- toHiccup() {
19
- return ["polygon", this.attribs, this.points];
20
- }
4
+ class Triangle extends APC {
5
+ constructor(points, attribs) {
6
+ super(points, attribs);
7
+ __ensureNumVerts(this.points.length, 3);
8
+ }
9
+ get type() {
10
+ return "tri";
11
+ }
12
+ copy() {
13
+ return __copyShape(Triangle, this);
14
+ }
15
+ withAttribs(attribs) {
16
+ return new Triangle(this.points, attribs);
17
+ }
18
+ toHiccup() {
19
+ return ["polygon", this.attribs, this.points];
20
+ }
21
21
  }
22
+ export {
23
+ Triangle
24
+ };
@@ -6,55 +6,35 @@ import { scale } from "./scale.js";
6
6
  import { transform } from "./transform.js";
7
7
  import { translate } from "./translate.js";
8
8
  const TX_ATTRIBS = ["transform", "translate", "rotate", "scale"];
9
- /** @internal */
10
9
  const __apply = ($) => {
11
- let attribs = $.attribs;
12
- if (!attribs)
13
- return $;
14
- const { transform: tx, translate: t, rotate: r, scale: s } = attribs;
15
- if (tx)
16
- return transform($.withAttribs(withoutKeysObj(attribs, TX_ATTRIBS)), tx);
17
- if (!(t || r || s))
18
- return $;
19
- $ = $.withAttribs(withoutKeysObj(attribs, TX_ATTRIBS));
20
- if (r)
21
- $ = rotate($, r);
22
- if (s)
23
- $ = scale($, s);
24
- if (t)
25
- $ = translate($, t);
10
+ let attribs = $.attribs;
11
+ if (!attribs)
26
12
  return $;
13
+ const { transform: tx, translate: t, rotate: r, scale: s } = attribs;
14
+ if (tx)
15
+ return transform(
16
+ $.withAttribs(withoutKeysObj(attribs, TX_ATTRIBS)),
17
+ tx
18
+ );
19
+ if (!(t || r || s))
20
+ return $;
21
+ $ = $.withAttribs(withoutKeysObj(attribs, TX_ATTRIBS));
22
+ if (r)
23
+ $ = rotate($, r);
24
+ if (s)
25
+ $ = scale($, s);
26
+ if (t)
27
+ $ = translate($, t);
28
+ return $;
27
29
  };
28
- /**
29
- * Applies any spatial transformation attributes defined (if any) for the given
30
- * shape. If no such attributes exist, the original shape is returned as is.
31
- *
32
- * @remarks
33
- * The following attributes are considered:
34
- *
35
- * - transform: A 2x3 (for 2D) or 4x4 (for 3D) transformation matrix
36
- * - translate: Translation/offset vector
37
- * - scale: A scale factor (scalar or vector)
38
- * - rotate: Rotation angle (in radians)
39
- *
40
- * If the `transform` attrib is given, the others will be ignored. If any of the
41
- * other 3 attribs is provided, the order of application is: rotate, scale,
42
- * translate. Any of these relevant attributes will be removed from the
43
- * transformed shapes to ensure idempotent behavior.
44
- *
45
- * For (@link group} shapes, the children are processed in depth-first order
46
- * with any transformations to the group itself applied last.
47
- *
48
- * Note: Where possible, this function delegates to {@link rotate},
49
- * {@link scale}, {@link translate} to realize individual/partial transformation
50
- * aspects to increase the likelihodd of retaining original shape types. E.g.
51
- * uniformly scaling a circle with a scalar factor retains a circle, but scaling
52
- * non-uniformly will convert it to an ellipse... Similarly, rotating a rect
53
- * will convert it to a quad etc.
54
- *
55
- * @param shape
56
- */
57
- export const applyTransforms = defmulti(__dispatch, {}, {
30
+ const applyTransforms = defmulti(
31
+ __dispatch,
32
+ {},
33
+ {
58
34
  [DEFAULT]: __apply,
59
- group: ($) => __apply($.copyTransformed((x) => applyTransforms(x))),
60
- });
35
+ group: ($) => __apply($.copyTransformed((x) => applyTransforms(x)))
36
+ }
37
+ );
38
+ export {
39
+ applyTransforms
40
+ };
package/arc-length.js CHANGED
@@ -3,40 +3,27 @@ import { perimeter } from "@thi.ng/geom-poly-utils/perimeter";
3
3
  import { PI, TAU } from "@thi.ng/math/api";
4
4
  import { dist } from "@thi.ng/vectors/dist";
5
5
  import { __dispatch } from "./internal/dispatch.js";
6
- /**
7
- * Returns the arc length / perimeter / circumference of the given
8
- * shape. For groups calls {@link arcLength} for each child and returns the
9
- * sum of results.
10
- *
11
- * Implemented for:
12
- *
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
- *
23
- * @param shape
24
- */
25
- export const arcLength = defmulti(__dispatch, {
6
+ const arcLength = defmulti(
7
+ __dispatch,
8
+ {
26
9
  quad: "poly",
27
- tri: "poly",
28
- }, {
10
+ tri: "poly"
11
+ },
12
+ {
29
13
  circle: ($) => TAU * $.r,
30
- ellipse: ({ r: [a, b] }) =>
31
- // Ramanujan approximation
32
- // https://www.mathsisfun.com/geometry/ellipse-perimeter.html
33
- PI * (3 * (a + b) - Math.sqrt((3 * a + b) * (3 * b + a))),
14
+ ellipse: ({ r: [a, b] }) => (
15
+ // Ramanujan approximation
16
+ // https://www.mathsisfun.com/geometry/ellipse-perimeter.html
17
+ PI * (3 * (a + b) - Math.sqrt((3 * a + b) * (3 * b + a)))
18
+ ),
34
19
  group: ({ children }) => children.reduce((sum, $) => sum + arcLength($), 0),
35
20
  line: ({ points }) => dist(points[0], points[1]),
36
21
  poly: ({ points }) => perimeter(points, points.length, true),
37
22
  polyline: ({ points }) => perimeter(points, points.length),
38
23
  rect: ({ size: [w, h] }) => 2 * (w + h),
39
- tri: ({ points }) => dist(points[0], points[1]) +
40
- dist(points[1], points[2]) +
41
- dist(points[2], points[0]),
42
- });
24
+ tri: ({ points }) => dist(points[0], points[1]) + dist(points[1], points[2]) + dist(points[2], points[0])
25
+ }
26
+ );
27
+ export {
28
+ arcLength
29
+ };
package/arc.js CHANGED
@@ -1,10 +1,21 @@
1
1
  import { isNumber } from "@thi.ng/checks/is-number";
2
2
  import { fromEndPoints } from "@thi.ng/geom-arc/from-endpoints";
3
3
  import { Arc } from "./api/arc.js";
4
- export const arc = (pos, r, axis, start, end, xl = false, clockwise = false) => new Arc(pos, isNumber(r) ? [r, r] : r, axis, start, end, xl, clockwise);
5
- export const arcFrom2Points = (a, b, radii, axis = 0, xl = false, cw = false, attribs) => {
6
- const res = fromEndPoints(a, b, radii, axis, xl, cw);
7
- return res
8
- ? new Arc(res.center, res.r, res.axis, res.start, res.end, res.xl, res.cw, attribs)
9
- : undefined;
4
+ const arc = (pos, r, axis, start, end, xl = false, clockwise = false) => new Arc(pos, isNumber(r) ? [r, r] : r, axis, start, end, xl, clockwise);
5
+ const arcFrom2Points = (a, b, radii, axis = 0, xl = false, cw = false, attribs) => {
6
+ const res = fromEndPoints(a, b, radii, axis, xl, cw);
7
+ return res ? new Arc(
8
+ res.center,
9
+ res.r,
10
+ res.axis,
11
+ res.start,
12
+ res.end,
13
+ res.xl,
14
+ res.cw,
15
+ attribs
16
+ ) : void 0;
17
+ };
18
+ export {
19
+ arc,
20
+ arcFrom2Points
10
21
  };
package/area.js CHANGED
@@ -4,59 +4,33 @@ import { PI } from "@thi.ng/math/api";
4
4
  import { signedArea2 } from "@thi.ng/vectors/signed-area";
5
5
  import { asPolygon } from "./as-polygon.js";
6
6
  import { __dispatch } from "./internal/dispatch.js";
7
- /**
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.
11
- *
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).
15
- *
16
- * For curves, lines, point clouds and rays the function returns 0.
17
- *
18
- * Currently implemented for:
19
- *
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}
37
- *
38
- * @param shape - shape to operate on
39
- * @param signed - true, if signed area
40
- */
41
- export const area = defmulti(__dispatch, { quad: "poly" }, {
7
+ const area = defmulti(
8
+ __dispatch,
9
+ { quad: "poly" },
10
+ {
42
11
  aabb: ({ size: [w, h, d] }) => 2 * (w * h + w * d + h * d),
43
- arc:
44
- // http://cut-the-knot.org/Generalization/Cavalieri2.shtml
45
- ($) => 0.5 * Math.abs($.start - $.end) * $.r[0] * $.r[1],
12
+ arc: (
13
+ // http://cut-the-knot.org/Generalization/Cavalieri2.shtml
14
+ ($) => 0.5 * Math.abs($.start - $.end) * $.r[0] * $.r[1]
15
+ ),
46
16
  circle: ($) => PI * $.r ** 2,
47
17
  ellipse: ($) => PI * $.r[0] * $.r[1],
48
18
  group: ({ children }) => children.reduce((sum, $) => sum + area($, false), 0),
49
- path: ($) => ($.closed ? area(asPolygon($)) : 0),
19
+ path: ($) => $.closed ? area(asPolygon($)) : 0,
50
20
  plane: () => Infinity,
51
21
  poly: ($, signed) => {
52
- const area = polyArea2($.points);
53
- return signed ? area : Math.abs(area);
22
+ const area2 = polyArea2($.points);
23
+ return signed ? area2 : Math.abs(area2);
54
24
  },
55
25
  rect: ($) => $.size[0] * $.size[1],
56
26
  sphere: ($) => 4 * PI * $.r ** 2,
57
27
  tri: ($, signed) => {
58
- const area = 0.5 * signedArea2(...$.points);
59
- return signed ? area : Math.abs(area);
28
+ const area2 = 0.5 * signedArea2(...$.points);
29
+ return signed ? area2 : Math.abs(area2);
60
30
  },
61
- [DEFAULT]: () => 0,
62
- });
31
+ [DEFAULT]: () => 0
32
+ }
33
+ );
34
+ export {
35
+ area
36
+ };