import type { Fn } from "@thi.ng/api" ; import type { AABBLike , IShape } from "@thi.ng/geom-api" ; import type { ReadonlyVec , VecPair } from "@thi.ng/vectors" ; import { add } from "@thi.ng/vectors/add" ; import { max } from "@thi.ng/vectors/max" ; import { min } from "@thi.ng/vectors/min" ; import { sub } from "@thi.ng/vectors/sub" ; /**
 * Computes the total bounds for the given shape collection, which
 * should either contain only 2D or 3D types. No mixed dimensions are
 * allowed! Currently the  bounds function MUST be passed in as
 * arg to avoid circular module dependencies.
 *
 *  param shapes param bounds export const __collBounds = ( shapes , bounds ) => { let n = shapes . length - 1 ; if ( n < 0 ) return ; let b = bounds ( shapes [ n ] ) ; if ( ! b ) return ; let { pos , size } = b ; for ( ; n -- > 0 ; ) { b = bounds ( shapes [ n ] ) ; if ( ! b ) continue ; [ pos , size ] = __unionBounds ( pos , size , b . pos , b . size ) ; } return [ pos , size ] ; } ; /**
 * Takes the position and size vectors of 2
 *  {@link @thi.ng/geom-api#AABBLike} s and returns 2-tuple of
 * `[pos,size]` of their union bounds.
 *
 *  param apos param asize param bpos param bsize export const __unionBounds = ( apos , asize , bpos , bsize ) : VecPair => { const p = add ( [ ] , apos , asize ) ; const q = add ( [ ] , bpos , bsize ) ; const pos = min ( [ ] , apos , bpos ) ; return [ pos , sub ( null , max ( null , p , q ) , pos ) ] ; } ;