import type { MultiFn1O } from "@thi.ng/defmulti" ; import { DEFAULT , defmulti } from "@thi.ng/defmulti/defmulti" ; import type { IShape } from "@thi.ng/geom-api" ; import { polyArea2 } from "@thi.ng/geom-poly-utils/area" ; import { PI } from "@thi.ng/math/api" ; import type { Vec } from "@thi.ng/vectors" ; import { signedArea2 } from "@thi.ng/vectors/signed-area" ; import type { AABB } from "./api/aabb.js" ; import type { Arc } from "./api/arc.js" ; import type { Circle } from "./api/circle.js" ; import type { Ellipse } from "./api/ellipse.js" ; import type { Group } from "./api/group.js" ; import type { Polygon } from "./api/polygon.js" ; import type { Rect } from "./api/rect.js" ; import type { Sphere } from "./api/sphere.js" ; import type { Triangle } from "./api/triangle.js" ; import { __dispatch } from "./internal/dispatch.js" ; /**
 * Returns the possibly signed (unsigned by default) surface area of given
 * `shape`. For groups calls  area for each child and returns sum of
 * unsigned areas.
 *
 * In general, for polygons and triangles, the sign of the result can be
 * used as indication of the shapes orientation (clockwise /
 * counterclockwise).
 *
 * For curves, lines, point clouds and rays the function returns 0.
 *
 * Implemented for:
 *
 * - AABB
 * - Circle
 * - Cubic
 * - Ellipse
 * - Group
 * - Line
 * - Plane
 * - Points
 * - Polygon
 * - Polyline
 * - Quad
 * - Quadratic
 * - Ray
 * - Rect
 * - Sphere
 * - Triangle
 *
 *  param shape param signed export const area = defmulti ( __dispatch , { quad : "poly" } , { aabb : ( { size : [ w , h , d ] } ) => 2 * ( w * h + w * d + h * d ) , arc : ( $ ) => 0.5 * Math . abs ( $ . start - $ . end ) * $ . r [ 0 ] * $ . r [ 1 ] , circle : ( $ ) => PI * $ . r ** 2 , ellipse : ( $ ) => PI * $ . r [ 0 ] * $ . r [ 1 ] , group : ( { children } ) => children . reduce ( ( sum , $ ) => sum + area ( $ , false ) , 0 ) , plane : ( ) => Infinity , poly : ( $ , signed ? ) => { const area = polyArea2 ( $ . points ) ; return signed ? area : Math . abs ( area ) ; } , rect : ( $ ) => $ . size [ 0 ] * $ . size [ 1 ] , sphere : ( $ ) => 4 * PI * $ . r ** 2 , tri : ( $ , signed ? ) => { const area = 0.5 * signedArea2 ( ... ( < [ Vec , Vec , Vec ] > $ . points ) ) ; return signed ? area : Math . abs ( area ) ; } , [ DEFAULT ] : ( ) => 0 , } ) ;