import { isNumber } from "@thi.ng/checks/is-number" ; import type { Attribs } from "@thi.ng/geom-api" ; import { closestPointPlane } from "@thi.ng/geom-closest-point/plane" ; import { alignmentQuat } from "@thi.ng/matrices/alignment-quat" ; import { mulVQ } from "@thi.ng/matrices/mulv" ; import { add3 } from "@thi.ng/vectors/add" ; import { ReadonlyVec , Vec , Z3 } from "@thi.ng/vectors/api" ; import type { Plane } from "./api/plane.js" ; import { Quad } from "./api/quad.js" ; import { Quad3 } from "./api/quad3.js" ; import { __argAttribs } from "./internal/args.js" ; import { __pclike } from "./internal/pclike.js" ; export function quad ( a , b , c , d , attribs ? ) ; export function quad ( pts , attribs ? ) ; export function quad ( ... args ) { return __pclike ( Quad , args ) ; } export function quad3 ( a , b , c , d , attribs ? ) ; export function quad3 ( pts , attribs ? ) ; export function quad3 ( ... args ) { const attr = __argAttribs ( args ) ; return new Quad3 ( args . length === 1 ? args [ 0 ] : args , attr ) ; } export const quadOnPlane = ( plane , pos , size , attribs ? ) => { pos = closestPointPlane ( pos , plane . normal , plane . w ) ; const [ w , h ] = isNumber ( size ) ? [ size , size ] : size ; const q = alignmentQuat ( Z3 , plane . normal ) ; return new Quad3 ( [ [ - w , - h , 0 ] , [ w , - h , 0 ] , [ w , h , 0 ] , [ - w , h , 0 ] , ] . map ( ( p ) => add3 ( null , mulVQ ( null , q , p ) , pos ) ) , attribs ) ; } ;