import type { Attribs } from "@thi.ng/geom-api" ; import { centroid } from "@thi.ng/geom-poly-utils/centroid" ; import { SQRT2_2 , SQRT3 } from "@thi.ng/math/api" ; import { add2 } from "@thi.ng/vectors/add" ; import { ReadonlyVec , Vec , ZERO2 } from "@thi.ng/vectors/api" ; import { dist } from "@thi.ng/vectors/dist" ; import { maddN2 } from "@thi.ng/vectors/maddn" ; import { max2 } from "@thi.ng/vectors/max" ; import { min2 } from "@thi.ng/vectors/min" ; import { sub2 } from "@thi.ng/vectors/sub" ; import { subN2 } from "@thi.ng/vectors/subn" ; import type { Circle } from "./api/circle.js" ; import type { Polygon } from "./api/polygon.js" ; import { Rect } from "./api/rect.js" ; import { __argsVV } from "./internal/args.js" ; export function rect ( pos , size , attribs ? ) ; export function rect ( size , attribs ? ) ; export function rect ( attribs ? ) ; export function rect ( ... args ) { return new Rect ( ... __argsVV ( args ) ) ; } export const rectFromMinMax = ( min , max , attribs ? ) => new Rect ( min , sub2 ( [ ] , max , min ) , attribs ) ; export const rectFromCentroid = ( centroid , size , attribs ? ) => new Rect ( maddN2 ( [ ] , size , - 0.5 , centroid ) , size , attribs ) ; param a param b export const intersectionRect = ( a , b ) => { const p = max2 ( [ ] , a . pos , b . pos ) ; const q = min2 ( null , add2 ( [ ] , a . pos , a . size ) , add2 ( [ ] , b . pos , b . size ) ) ; const size = max2 ( null , sub2 ( null , q , p ) , ZERO2 ) ; return size [ 0 ] > 0 && size [ 1 ] > 0 ? new Rect ( p , size ) : undefined ; } ; param circle export function inscribedSquare ( circle ) ; export function inscribedSquare ( pos , r ) ; export function inscribedSquare ( ... args ) { let pos , r ; if ( args . length === 1 ) { const c = args [ 0 ] ; pos = c . pos ; r = c . r ; } else { [ pos , r ] = args ; } r *= SQRT2_2 ; return rect ( subN2 ( [ ] , pos , r ) , r * 2 ) ; } /**
 * Returns square inscribed in given (unrotated) hexagon. The hexagon
 * can be given as  Polygon or centroid and edge length.
 *
 *  param hex export function inscribedSquareHex ( hex ) ; export function inscribedSquareHex ( pos , len ) ; export function inscribedSquareHex ( ... args ) { let pos , l ; if ( args . length === 1 ) { const pts = ( < Polygon > args [ 0 ] ) . points ; pos = centroid ( pts ) ; l = dist ( pts [ 0 ] , pts [ 1 ] ) ; } else { [ pos , l ] = args ; } l *= 3 - SQRT3 ; return rect ( subN2 ( [ ] , pos , l / 2 ) , l ) ; }