Skip to content

Commit

Permalink
feat(geom): add arcLength(), area() default impls (return 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 3, 2024
1 parent beb4bf0 commit f2a30bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/geom/src/arc-length.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MultiFn1 } from "@thi.ng/defmulti";
import { defmulti } from "@thi.ng/defmulti/defmulti";
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
import type { IShape } from "@thi.ng/geom-api";
import { perimeter } from "@thi.ng/geom-poly-utils/perimeter";
import { PI, TAU } from "@thi.ng/math/api";
Expand Down Expand Up @@ -47,6 +47,8 @@ import { __dispatch } from "./internal/dispatch.js";
* - {@link Triangle}
* - {@link Triangle3}
*
* For all other types the function returns 0.
*
* @param shape
*/
export const arcLength: MultiFn1<IShape, number> = defmulti(
Expand All @@ -68,6 +70,8 @@ export const arcLength: MultiFn1<IShape, number> = defmulti(
tri3: "tri",
},
{
[DEFAULT]: () => 0,

$aspoly: ($) => asPolygon($).reduce((acc, p) => acc + arcLength(p), 0),

$aspolyline: ($) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/geom/src/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const area: MultiFn1O<IShape, boolean, number> = defmulti(
__dispatch,
{ group3: "group", quad: "poly" },
{
[DEFAULT]: () => 0,

aabb: ({ size: [w, h, d] }: AABB) => 2 * (w * h + w * d + h * d),

arc:
Expand Down Expand Up @@ -92,7 +94,5 @@ export const area: MultiFn1O<IShape, boolean, number> = defmulti(
const area = 0.5 * signedArea2(...(<[Vec, Vec, Vec]>$.points));
return signed ? area : Math.abs(area);
},

[DEFAULT]: () => 0,
}
);

0 comments on commit f2a30bf

Please sign in to comment.