import type { MultiFn2O } from "@thi.ng/defmulti" ; import { defmulti } from "@thi.ng/defmulti/defmulti" ; import type { IntersectionResult , IShape , PCLike } from "@thi.ng/geom-api" ; import { IntersectionType } from "@thi.ng/geom-api/isec" ; import { intersectCircleCircle } from "@thi.ng/geom-isec/circle-circle" ; import { intersectLineLine } from "@thi.ng/geom-isec/line-line" ; import { intersectPlanePlane } from "@thi.ng/geom-isec/plane-plane" ; import { intersectRayCircle } from "@thi.ng/geom-isec/ray-circle" ; import { intersectRayPlane } from "@thi.ng/geom-isec/ray-plane" ; import { intersectRayPolyline } from "@thi.ng/geom-isec/ray-poly" ; import { intersectRayAABB , intersectRayRect } from "@thi.ng/geom-isec/ray-rect" ; import { testRectCircle } from "@thi.ng/geom-isec/rect-circle" ; import { testRectRect } from "@thi.ng/geom-isec/rect-rect" ; import type { AABB } from "./api/aabb.js" ; import type { Circle } from "./api/circle.js" ; import type { Line } from "./api/line.js" ; import type { Plane } from "./api/plane.js" ; import type { Ray } from "./api/ray.js" ; import type { Rect } from "./api/rect.js" ; import type { Sphere } from "./api/sphere.js" ; import { __dispatch2 } from "./internal/dispatch.js" ; export const intersects = defmulti ( __dispatch2 , { "ray-sphere" : "ray-circle" , "ray-quad" : "ray-poly" , "ray-tri" : "ray-poly" , "sphere-sphere" : "circle-circle" , } , { "circle-circle" : ( a , b ) => intersectCircleCircle ( a . pos , b . pos , a . r , b . r ) , "line-line" : ( { points : a } , { points : b } ) => intersectLineLine ( a [ 0 ] , a [ 1 ] , b [ 0 ] , b [ 1 ] ) , "plane-plane" : ( a , b ) => intersectPlanePlane ( a . normal , a . w , b . normal , b . w ) , "ray-aabb" : ( ray , box ) => intersectRayAABB ( ray . pos , ray . dir , box . pos , box . max ( ) ) , "ray-circle" : ( ray , sphere ) => intersectRayCircle ( ray . pos , ray . dir , sphere . pos , sphere . r ) , "ray-plane" : ( ray , plane ) => intersectRayPlane ( ray . pos , ray . dir , plane . normal , plane . w ) , "ray-poly" : ( ray , poly ) => intersectRayPolyline ( ray . pos , ray . dir , poly . points , true ) , "ray-polyline" : ( ray , poly ) => intersectRayPolyline ( ray . pos , ray . dir , poly . points , false ) , "ray-rect" : ( ray , rect ) => intersectRayRect ( ray . pos , ray . dir , rect . pos , rect . max ( ) ) , "rect-circle" : ( rect , circle ) => ( { type : testRectCircle ( rect . pos , rect . size , circle . pos , circle . r ) ? IntersectionType . INTERSECT : IntersectionType . NONE , } ) , "rect-rect" : ( a , b ) => ( { type : testRectRect ( a . pos , a . size , b . pos , b . size ) ? IntersectionType . INTERSECT : IntersectionType . NONE , } ) , } ) ;