import type { MultiFn1 } from "@thi.ng/defmulti" ; import { 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" ; import { dist } from "@thi.ng/vectors/dist" ; import type { Circle } from "./api/circle.js" ; import type { Ellipse } from "./api/ellipse.js" ; import type { Group } from "./api/group.js" ; import type { Line } from "./api/line.js" ; import type { Polygon } from "./api/polygon.js" ; import type { Rect } from "./api/rect.js" ; import type { Triangle } from "./api/triangle.js" ; import { __dispatch } from "./internal/dispatch.js" ; /**
 * Returns the arc length / perimeter / circumference of the given
 * shape. For groups calls  arcLength for each child and returns the
 * sum of results.
 *
 * Implemented for:
 *
 * - Circle
 * - Ellipse
 * - Group
 * - Line
 * - Polygon
 * - Polyline
 * - Quad
 * - Rect
 * - Triangle
 *
  export const arcLength = defmulti ( __dispatch , { quad : "poly" , tri : "poly" , } , { circle : ( $ ) => TAU * $ . r , ellipse : ( { r : [ a , b ] } ) => PI * ( 3 * ( a + b ) - Math . sqrt ( ( 3 * a + b ) * ( 3 * b + a ) ) ) , group : ( { children } ) => children . reduce ( ( sum , $ ) => sum + arcLength ( $ ) , 0 ) , line : ( { points } ) => dist ( points [ 0 ] , points [ 1 ] ) , poly : ( { points } ) => perimeter ( points , points . length , true ) , polyline : ( { points } ) => perimeter ( points , points . length ) , rect : ( { size } ) => 2 * ( size [ 0 ] + size [ 1 ] ) , tri : ( { points } ) => dist ( points [ 0 ] , points [ 1 ] ) + dist ( points [ 1 ] , points [ 2 ] ) + dist ( points [ 2 ] , points [ 0 ] ) , } ) ;