@thi.ng/geom-isec
Advanced tools
Comparing version 0.4.26 to 0.5.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.5.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/geom-isec@0.4.26...@thi.ng/geom-isec@0.5.0) (2020-07-17) | ||
### Features | ||
* **geom-isec:** add intersectLinePolylineAll() ([1f38d92](https://github.com/thi-ng/umbrella/commit/1f38d92e0d88c855251fa14627975b0bb1c7cf39)) | ||
## [0.4.26](https://github.com/thi-ng/umbrella/compare/@thi.ng/geom-isec@0.4.25...@thi.ng/geom-isec@0.4.26) (2020-07-08) | ||
@@ -8,0 +19,0 @@ |
export * from "./point"; | ||
export * from "./circle-circle"; | ||
export * from "./line-line"; | ||
export * from "./line-poly"; | ||
export * from "./plane-plane"; | ||
@@ -5,0 +6,0 @@ export * from "./ray-circle"; |
export * from "./point"; | ||
export * from "./circle-circle"; | ||
export * from "./line-line"; | ||
export * from "./line-poly"; | ||
export * from "./plane-plane"; | ||
@@ -5,0 +6,0 @@ export * from "./ray-circle"; |
@@ -154,2 +154,51 @@ 'use strict'; | ||
const intersectRayLine = (rpos, dir, a, b) => { | ||
const bax = b[0] - a[0]; | ||
const bay = b[1] - a[1]; | ||
const d = dir[0] * bay - dir[1] * bax; | ||
if (math.eqDeltaFixed(d, 0)) { | ||
return NONE; | ||
} | ||
const arx = a[0] - rpos[0]; | ||
const ary = a[1] - rpos[1]; | ||
const t = (bay * arx - bax * ary) / d; | ||
const s = (dir[1] * arx - dir[0] * ary) / d; | ||
return t >= 0 && s >= 0 && s <= 1 | ||
? { | ||
type: geomApi.IntersectionType.INTERSECT, | ||
isec: vectors.maddN([], dir, t, rpos), | ||
alpha: t, | ||
} | ||
: NONE; | ||
}; | ||
const intersectLinePolylineAll = (a, b, pts, closed = false) => { | ||
const dir = vectors.sub([], b, a); | ||
const maxD = vectors.mag(dir); | ||
vectors.normalize(null, dir); | ||
const n = pts.length - 1; | ||
let i, j; | ||
if (closed) { | ||
i = pts[n]; | ||
j = pts[0]; | ||
} | ||
else { | ||
i = pts[0]; | ||
j = pts[1]; | ||
} | ||
const res = []; | ||
for (let k = 0; k <= n; i = j, j = pts[++k]) { | ||
const d = intersectRayLine(a, dir, i, j).alpha; | ||
if (d !== undefined && d >= 0 && d <= maxD) { | ||
res.push([d, vectors.maddN2([], dir, d, a)]); | ||
} | ||
} | ||
return res.length | ||
? { | ||
type: geomApi.IntersectionType.INTERSECT, | ||
isec: res.sort((a, b) => a[0] - b[0]).map((x) => x[1]), | ||
} | ||
: NONE; | ||
}; | ||
const intersectPlanePlane = (na, wa, nb, wb) => { | ||
@@ -194,22 +243,2 @@ const dn = vectors.dot3(na, nb); | ||
const intersectRayLine = (rpos, dir, a, b) => { | ||
const bax = b[0] - a[0]; | ||
const bay = b[1] - a[1]; | ||
const d = dir[0] * bay - dir[1] * bax; | ||
if (math.eqDeltaFixed(d, 0)) { | ||
return NONE; | ||
} | ||
const arx = a[0] - rpos[0]; | ||
const ary = a[1] - rpos[1]; | ||
const t = (bay * arx - bax * ary) / d; | ||
const s = (dir[1] * arx - dir[0] * ary) / d; | ||
return t >= 0 && s >= 0 && s <= 1 | ||
? { | ||
type: geomApi.IntersectionType.INTERSECT, | ||
isec: vectors.maddN([], dir, t, rpos), | ||
alpha: t, | ||
} | ||
: NONE; | ||
}; | ||
const intersectRayPlane = (rpos, dir, normal, w, eps = math.EPS) => { | ||
@@ -405,2 +434,3 @@ const d = vectors.dot(normal, dir); | ||
exports.intersectLineLine = intersectLineLine; | ||
exports.intersectLinePolylineAll = intersectLinePolylineAll; | ||
exports.intersectPlanePlane = intersectPlanePlane; | ||
@@ -407,0 +437,0 @@ exports.intersectRayAABB = intersectRayAABB; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/geom-closest-point"),require("@thi.ng/math"),require("@thi.ng/vectors"),require("@thi.ng/geom-api")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/geom-closest-point","@thi.ng/math","@thi.ng/vectors","@thi.ng/geom-api"],t):t(((e=e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.geomIsec={}),e.thi.ng.geomClosestPoint,e.thi.ng.math,e.thi.ng.vectors,e.thi.ng.geomApi)}(this,(function(e,t,n,i,r){"use strict";const s=(e,t,n)=>i.distSq(t,e)<=n*n,o=s,c=(e,t,n,i,r,s,o)=>(i<t&&s>=t||s<t&&i>=t)&&(n<=e||r<=e)?o^(n+(t-i)/(s-i)*(r-n)<e?1:0):o,a=i.vop(0),d=a.add(2,([e,t],n,i)=>e>=n[0]&&e<=n[0]+i[0]&&t>=n[1]&&t<=n[1]+i[1]),l=a.add(3,([e,t,n],i,r)=>e>=i[0]&&e<=i[0]+r[0]&&t>=i[1]&&t<=i[1]+r[1]&&n>=i[2]&&n<=i[2]+r[2]);a.default((e,t,n)=>{for(let i=e.length;--i>=0;){const r=e[i],s=t[i];if(r<s||r>s+n[i])return!1}return!0});const p=i.vop(0),u=p.add(2,([e,t],n,i)=>e>=n[0]-i[0]&&e<=n[0]+i[0]&&t>=n[1]-i[1]&&t<=n[1]+i[1]),I=p.add(3,([e,t,n],i,r)=>e>=i[0]-r[0]&&e<=i[0]+r[0]&&t>=i[1]-r[1]&&t<=i[1]+r[1]&&n>=i[2]-r[2]&&n<=i[2]+r[2]);p.default((e,t,n)=>{for(let i=e.length;--i>=0;){const r=e[i],s=t[i],o=n[i];if(r<s-o||r>s+o)return!1}return!0});const g=Object.freeze({type:r.IntersectionType.NONE}),y=(e,t,s,o)=>{const c=o[0]-s[0],a=o[1]-s[1],d=t[0]*a-t[1]*c;if(n.eqDeltaFixed(d,0))return g;const l=s[0]-e[0],p=s[1]-e[1],u=(a*l-c*p)/d,I=(t[1]*l-t[0]*p)/d;return u>=0&&I>=0&&I<=1?{type:r.IntersectionType.INTERSECT,isec:i.maddN([],t,u,e),alpha:u}:g},T=Math.min,h=Math.max,m=(e,t,n,i)=>{let r=e[0],s=1/t[0],o=(n[0]-r)*s,c=(i[0]-r)*s,a=T(o,c),d=h(o,c);return r=e[1],s=1/t[1],o=(n[1]-r)*s,c=(i[1]-r)*s,[h(a,T(o,c)),T(d,h(o,c))]},N=(e,t,n,i)=>{let r=e[0],s=1/t[0],o=(n[0]-r)*s,c=(i[0]-r)*s,a=T(o,c),d=h(o,c);return r=e[1],s=1/t[1],o=(n[1]-r)*s,c=(i[1]-r)*s,r=e[2],s=1/t[2],o=(n[2]-r)*s,c=(i[2]-r)*s,a=h(a,T(o,c)),d=T(d,h(o,c)),[h(a,T(o,c)),T(d,h(o,c))]},C=e=>(t,n,s,o)=>{const c=e(t,n,s,o),a=c[0],d=c[1],l=a<0;return d>h(a,0)?l?{type:r.IntersectionType.INTERSECT,inside:l,isec:[i.maddN([],n,d,t)],alpha:d}:{type:r.IntersectionType.INTERSECT,isec:[i.maddN([],n,a,t),i.maddN([],n,d,t)],alpha:a,beta:d}:g},f=C(m),E=C(N),S=i.vop(0),R=S.add(2,(e,t,n,i)=>B(n[0],e[0],t[0])+B(n[1],e[1],t[1])<=i*i),A=S.add(3,(e,t,n,i)=>B(n[0],e[0],t[0])+B(n[1],e[1],t[1])+B(n[2],e[2],t[2])<=i*i);S.default((e,t,n,i)=>{let r=0;for(let i=e.length;--i>=0;)r+=B(n[i],e[i],t[i]);return r<=i*i});const q=i.vop(0),P=q.add(2,(e,{0:t,1:n},i,r)=>B(i[0],e[0]-t,2*t)+B(i[1],e[1]-n,2*n)<=r*r),x=q.add(3,(e,{0:t,1:n,2:i},r,s)=>B(r[0],e[0]-t,2*t)+B(r[1],e[1]-n,2*n)+B(r[2],e[2]-t,2*i)<=s*s);q.default((e,t,n,i)=>{let r=0;for(let i=e.length;--i>=0;)r+=B(n[i],e[i]-t[i],2*t[i]);return r<=i*i});const B=(e,t,n)=>(e<t?e-t:e>t+n?e-t-n:0)**2;e.classifyPointInCircle=(e,t,r,s=n.EPS)=>n.sign(r*r-i.distSq(t,e),s),e.classifyPointInTriangle2=(e,t,r,s,o=n.EPS)=>{const c=i.clockwise2(t,r,s)?1:-1;return n.sign(Math.min(c*i.signedArea2(t,s,e),c*i.signedArea2(r,t,e),c*i.signedArea2(s,r,e)),o)},e.classifyPointPolyPair=c,e.intersectCircleCircle=(e,t,s,o)=>{const c=i.sub([],t,e),a=i.mag(c);if(n.eqDeltaFixed(a,0))return{type:r.IntersectionType.COINCIDENT};if(a<=s+o&&a>=Math.abs(s-o)){const t=((s*=s)-o*o+a*a)/(2*a),n=Math.sqrt(s-t*t),d=i.maddN([],c,t/a,e),l=i.mulN(null,i.perpendicularCCW(null,c),n/a);return{type:r.IntersectionType.INTERSECT,isec:[i.add([],d,l),i.sub([],d,l)]}}return g},e.intersectLineLine=(e,s,o,c,a=n.EPS)=>{const d=s[0]-e[0],l=s[1]-e[1],p=c[0]-o[0],u=c[1]-o[1],I=e[0]-o[0],g=e[1]-o[1],y=u*d-p*l;let T=p*g-u*I,h=d*g-l*I;if(n.eqDeltaFixed(y,0,a)){if(n.eqDeltaFixed(T,0,a)&&n.eqDeltaFixed(h,0,a)){let n=t.closestPointSegment(o,e,s,void 0,!0)||t.closestPointSegment(c,e,s,void 0,!0);return{type:n?r.IntersectionType.COINCIDENT:r.IntersectionType.COINCIDENT_NO_INTERSECT,isec:n}}return{type:r.IntersectionType.PARALLEL}}T/=y,h/=y;const m=1-a;return{type:a<T&&T<m&&a<h&&h<m?r.IntersectionType.INTERSECT:r.IntersectionType.INTERSECT_OUTSIDE,isec:i.mixN2([],e,s,T),alpha:T,beta:h,det:y}},e.intersectPlanePlane=(e,t,s,o)=>{const c=i.dot3(e,s);if(n.eqDeltaFixed(c,1))return n.eqDelta(t,o)?{type:r.IntersectionType.COINCIDENT}:g;const a=1/(1-c*c),d=(t-o*c)*a,l=(o-t*c)*a;return{type:r.IntersectionType.INTERSECT,isec:[i.add3(null,i.mulN3([],e,d),i.mulN3([],s,l)),i.cross3([],e,s)]}},e.intersectRayAABB=E,e.intersectRayCircle=(e,t,n,s)=>{const o=i.sub([],n,e),c=i.dot(o,t);let a=s*s+c*c-i.magSq(o);if(a>=0){a=Math.sqrt(a);const n=c+a,s=c-a,d=n>=0?s>=0?n>s?[i.maddN(o,t,s,e),i.maddN([],t,n,e)]:[i.maddN(o,t,n,e),i.maddN([],t,s,e)]:[i.maddN(o,t,n,e)]:s>=0?[i.maddN(o,t,s,e)]:void 0;return d?{type:r.IntersectionType.INTERSECT,isec:d}:g}return g},e.intersectRayLine=y,e.intersectRayPlane=(e,t,s,o,c=n.EPS)=>{const a=i.dot(s,t),d=n.sign(i.dot(s,e)-o,c);if(a>c&&d<0||a<-c&&d>0){const n=i.sub(null,i.mulN([],s,o),e),c=i.dot(s,n)/a;return{type:r.IntersectionType.INTERSECT,isec:i.maddN(n,t,c,e),alpha:c}}return 0===d?{type:r.IntersectionType.COINCIDENT,isec:i.copy(e)}:g},e.intersectRayPolyline=(e,t,n,s=!1)=>{const o=n.length-1;let c,a,d=1/0,l=0;s?(c=n[o],a=n[0]):(c=n[0],a=n[1]);for(let i=0;i<=o;c=a,a=n[++i]){const n=y(e,t,c,a).alpha;void 0!==n&&(l++,n<d&&(d=n))}return l>0?{type:r.IntersectionType.INTERSECT,isec:i.maddN2([],t,d,e),inside:!(1&l),alpha:d}:g},e.intersectRayPolylineAll=(e,t,n,s=!1)=>{const o=n.length-1;let c,a;s?(c=n[o],a=n[0]):(c=n[0],a=n[1]);const d=[];for(let r=0;r<=o;c=a,a=n[++r]){const n=y(e,t,c,a).alpha;void 0!==n&&d.push([n,i.maddN2([],t,n,e)])}return d.length?{type:r.IntersectionType.INTERSECT,isec:d.sort((e,t)=>e[0]-t[0]).map(e=>e[1])}:g},e.intersectRayRect=f,e.isParallelLine=(e,t,i,r)=>n.eqDeltaFixed((r[1]-i[1])*(t[0]-e[0])-(r[0]-i[0])*(t[1]-e[1]),0),e.pointInAABB=l,e.pointInBox=a,e.pointInCenteredAABB=I,e.pointInCenteredBox=p,e.pointInCenteredRect=u,e.pointInCircle=s,e.pointInCircumCircle=(e,t,n,r)=>i.magSq(e)*i.signedArea2(t,n,r)-i.magSq(t)*i.signedArea2(e,n,r)+i.magSq(n)*i.signedArea2(e,t,r)-i.magSq(r)*i.signedArea2(e,t,n)>0,e.pointInPolygon2=(e,t)=>{const n=t.length-1,i=e[0],r=e[1];let s=t[n],o=t[0],a=0;for(let e=0;e<=n;s=o,o=t[++e])a=c(i,r,s[0],s[1],o[0],o[1],a);return a},e.pointInRect=d,e.pointInSegment=(e,r,s,o=n.EPS)=>{const c=t.closestT(e,r,s);return void 0!==c&&i.distSq(e,i.mixN([],r,s,n.clamp01(c)))<o*o},e.pointInSphere=o,e.pointInTriangle2=(e,t,n,r)=>{const s=i.clockwise2(t,n,r)?1:-1;return s*i.signedArea2(t,r,e)>=0&&s*i.signedArea2(n,t,e)>=0&&s*i.signedArea2(r,n,e)>=0},e.testAABBSphere=A,e.testAabbAabb=([e,t,n],[i,r,s],[o,c,a],[d,l,p])=>!(e>o+d||o>e+i||t>c+l||c>t+r||n>a+p||a>n+s),e.testBoxSphere=S,e.testCenteredAABBSphere=x,e.testCenteredBoxSphere=q,e.testCenteredRectCircle=P,e.testCircleCircle=(e,t,n,r)=>i.distSq(e,t)<=Math.pow(n+r,2),e.testRayAABB=(e,t,n,i)=>{const r=N(e,t,n,i);return r[1]>h(r[0],0)},e.testRayRect=(e,t,n,i)=>{const r=m(e,t,n,i);return r[1]>h(r[0],0)},e.testRectCircle=R,e.testRectRect=([e,t],[n,i],[r,s],[o,c])=>!(e>r+o||r>e+n||t>s+c||s>t+i),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/geom-closest-point"),require("@thi.ng/math"),require("@thi.ng/vectors"),require("@thi.ng/geom-api")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/geom-closest-point","@thi.ng/math","@thi.ng/vectors","@thi.ng/geom-api"],t):t(((e=e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.geomIsec={}),e.thi.ng.geomClosestPoint,e.thi.ng.math,e.thi.ng.vectors,e.thi.ng.geomApi)}(this,(function(e,t,n,i,r){"use strict";const s=(e,t,n)=>i.distSq(t,e)<=n*n,o=s,c=(e,t,n,i,r,s,o)=>(i<t&&s>=t||s<t&&i>=t)&&(n<=e||r<=e)?o^(n+(t-i)/(s-i)*(r-n)<e?1:0):o,a=i.vop(0),l=a.add(2,([e,t],n,i)=>e>=n[0]&&e<=n[0]+i[0]&&t>=n[1]&&t<=n[1]+i[1]),d=a.add(3,([e,t,n],i,r)=>e>=i[0]&&e<=i[0]+r[0]&&t>=i[1]&&t<=i[1]+r[1]&&n>=i[2]&&n<=i[2]+r[2]);a.default((e,t,n)=>{for(let i=e.length;--i>=0;){const r=e[i],s=t[i];if(r<s||r>s+n[i])return!1}return!0});const p=i.vop(0),u=p.add(2,([e,t],n,i)=>e>=n[0]-i[0]&&e<=n[0]+i[0]&&t>=n[1]-i[1]&&t<=n[1]+i[1]),g=p.add(3,([e,t,n],i,r)=>e>=i[0]-r[0]&&e<=i[0]+r[0]&&t>=i[1]-r[1]&&t<=i[1]+r[1]&&n>=i[2]-r[2]&&n<=i[2]+r[2]);p.default((e,t,n)=>{for(let i=e.length;--i>=0;){const r=e[i],s=t[i],o=n[i];if(r<s-o||r>s+o)return!1}return!0});const y=Object.freeze({type:r.IntersectionType.NONE}),I=(e,t,s,o)=>{const c=o[0]-s[0],a=o[1]-s[1],l=t[0]*a-t[1]*c;if(n.eqDeltaFixed(l,0))return y;const d=s[0]-e[0],p=s[1]-e[1],u=(a*d-c*p)/l,g=(t[1]*d-t[0]*p)/l;return u>=0&&g>=0&&g<=1?{type:r.IntersectionType.INTERSECT,isec:i.maddN([],t,u,e),alpha:u}:y},h=Math.min,T=Math.max,m=(e,t,n,i)=>{let r=e[0],s=1/t[0],o=(n[0]-r)*s,c=(i[0]-r)*s,a=h(o,c),l=T(o,c);return r=e[1],s=1/t[1],o=(n[1]-r)*s,c=(i[1]-r)*s,[T(a,h(o,c)),h(l,T(o,c))]},N=(e,t,n,i)=>{let r=e[0],s=1/t[0],o=(n[0]-r)*s,c=(i[0]-r)*s,a=h(o,c),l=T(o,c);return r=e[1],s=1/t[1],o=(n[1]-r)*s,c=(i[1]-r)*s,r=e[2],s=1/t[2],o=(n[2]-r)*s,c=(i[2]-r)*s,a=T(a,h(o,c)),l=h(l,T(o,c)),[T(a,h(o,c)),h(l,T(o,c))]},C=e=>(t,n,s,o)=>{const c=e(t,n,s,o),a=c[0],l=c[1],d=a<0;return l>T(a,0)?d?{type:r.IntersectionType.INTERSECT,inside:d,isec:[i.maddN([],n,l,t)],alpha:l}:{type:r.IntersectionType.INTERSECT,isec:[i.maddN([],n,a,t),i.maddN([],n,l,t)],alpha:a,beta:l}:y},E=C(m),f=C(N),S=i.vop(0),R=S.add(2,(e,t,n,i)=>B(n[0],e[0],t[0])+B(n[1],e[1],t[1])<=i*i),A=S.add(3,(e,t,n,i)=>B(n[0],e[0],t[0])+B(n[1],e[1],t[1])+B(n[2],e[2],t[2])<=i*i);S.default((e,t,n,i)=>{let r=0;for(let i=e.length;--i>=0;)r+=B(n[i],e[i],t[i]);return r<=i*i});const q=i.vop(0),P=q.add(2,(e,{0:t,1:n},i,r)=>B(i[0],e[0]-t,2*t)+B(i[1],e[1]-n,2*n)<=r*r),x=q.add(3,(e,{0:t,1:n,2:i},r,s)=>B(r[0],e[0]-t,2*t)+B(r[1],e[1]-n,2*n)+B(r[2],e[2]-t,2*i)<=s*s);q.default((e,t,n,i)=>{let r=0;for(let i=e.length;--i>=0;)r+=B(n[i],e[i]-t[i],2*t[i]);return r<=i*i});const B=(e,t,n)=>(e<t?e-t:e>t+n?e-t-n:0)**2;e.classifyPointInCircle=(e,t,r,s=n.EPS)=>n.sign(r*r-i.distSq(t,e),s),e.classifyPointInTriangle2=(e,t,r,s,o=n.EPS)=>{const c=i.clockwise2(t,r,s)?1:-1;return n.sign(Math.min(c*i.signedArea2(t,s,e),c*i.signedArea2(r,t,e),c*i.signedArea2(s,r,e)),o)},e.classifyPointPolyPair=c,e.intersectCircleCircle=(e,t,s,o)=>{const c=i.sub([],t,e),a=i.mag(c);if(n.eqDeltaFixed(a,0))return{type:r.IntersectionType.COINCIDENT};if(a<=s+o&&a>=Math.abs(s-o)){const t=((s*=s)-o*o+a*a)/(2*a),n=Math.sqrt(s-t*t),l=i.maddN([],c,t/a,e),d=i.mulN(null,i.perpendicularCCW(null,c),n/a);return{type:r.IntersectionType.INTERSECT,isec:[i.add([],l,d),i.sub([],l,d)]}}return y},e.intersectLineLine=(e,s,o,c,a=n.EPS)=>{const l=s[0]-e[0],d=s[1]-e[1],p=c[0]-o[0],u=c[1]-o[1],g=e[0]-o[0],y=e[1]-o[1],I=u*l-p*d;let h=p*y-u*g,T=l*y-d*g;if(n.eqDeltaFixed(I,0,a)){if(n.eqDeltaFixed(h,0,a)&&n.eqDeltaFixed(T,0,a)){let n=t.closestPointSegment(o,e,s,void 0,!0)||t.closestPointSegment(c,e,s,void 0,!0);return{type:n?r.IntersectionType.COINCIDENT:r.IntersectionType.COINCIDENT_NO_INTERSECT,isec:n}}return{type:r.IntersectionType.PARALLEL}}h/=I,T/=I;const m=1-a;return{type:a<h&&h<m&&a<T&&T<m?r.IntersectionType.INTERSECT:r.IntersectionType.INTERSECT_OUTSIDE,isec:i.mixN2([],e,s,h),alpha:h,beta:T,det:I}},e.intersectLinePolylineAll=(e,t,n,s=!1)=>{const o=i.sub([],t,e),c=i.mag(o);i.normalize(null,o);const a=n.length-1;let l,d;s?(l=n[a],d=n[0]):(l=n[0],d=n[1]);const p=[];for(let t=0;t<=a;l=d,d=n[++t]){const t=I(e,o,l,d).alpha;void 0!==t&&t>=0&&t<=c&&p.push([t,i.maddN2([],o,t,e)])}return p.length?{type:r.IntersectionType.INTERSECT,isec:p.sort((e,t)=>e[0]-t[0]).map(e=>e[1])}:y},e.intersectPlanePlane=(e,t,s,o)=>{const c=i.dot3(e,s);if(n.eqDeltaFixed(c,1))return n.eqDelta(t,o)?{type:r.IntersectionType.COINCIDENT}:y;const a=1/(1-c*c),l=(t-o*c)*a,d=(o-t*c)*a;return{type:r.IntersectionType.INTERSECT,isec:[i.add3(null,i.mulN3([],e,l),i.mulN3([],s,d)),i.cross3([],e,s)]}},e.intersectRayAABB=f,e.intersectRayCircle=(e,t,n,s)=>{const o=i.sub([],n,e),c=i.dot(o,t);let a=s*s+c*c-i.magSq(o);if(a>=0){a=Math.sqrt(a);const n=c+a,s=c-a,l=n>=0?s>=0?n>s?[i.maddN(o,t,s,e),i.maddN([],t,n,e)]:[i.maddN(o,t,n,e),i.maddN([],t,s,e)]:[i.maddN(o,t,n,e)]:s>=0?[i.maddN(o,t,s,e)]:void 0;return l?{type:r.IntersectionType.INTERSECT,isec:l}:y}return y},e.intersectRayLine=I,e.intersectRayPlane=(e,t,s,o,c=n.EPS)=>{const a=i.dot(s,t),l=n.sign(i.dot(s,e)-o,c);if(a>c&&l<0||a<-c&&l>0){const n=i.sub(null,i.mulN([],s,o),e),c=i.dot(s,n)/a;return{type:r.IntersectionType.INTERSECT,isec:i.maddN(n,t,c,e),alpha:c}}return 0===l?{type:r.IntersectionType.COINCIDENT,isec:i.copy(e)}:y},e.intersectRayPolyline=(e,t,n,s=!1)=>{const o=n.length-1;let c,a,l=1/0,d=0;s?(c=n[o],a=n[0]):(c=n[0],a=n[1]);for(let i=0;i<=o;c=a,a=n[++i]){const n=I(e,t,c,a).alpha;void 0!==n&&(d++,n<l&&(l=n))}return d>0?{type:r.IntersectionType.INTERSECT,isec:i.maddN2([],t,l,e),inside:!(1&d),alpha:l}:y},e.intersectRayPolylineAll=(e,t,n,s=!1)=>{const o=n.length-1;let c,a;s?(c=n[o],a=n[0]):(c=n[0],a=n[1]);const l=[];for(let r=0;r<=o;c=a,a=n[++r]){const n=I(e,t,c,a).alpha;void 0!==n&&l.push([n,i.maddN2([],t,n,e)])}return l.length?{type:r.IntersectionType.INTERSECT,isec:l.sort((e,t)=>e[0]-t[0]).map(e=>e[1])}:y},e.intersectRayRect=E,e.isParallelLine=(e,t,i,r)=>n.eqDeltaFixed((r[1]-i[1])*(t[0]-e[0])-(r[0]-i[0])*(t[1]-e[1]),0),e.pointInAABB=d,e.pointInBox=a,e.pointInCenteredAABB=g,e.pointInCenteredBox=p,e.pointInCenteredRect=u,e.pointInCircle=s,e.pointInCircumCircle=(e,t,n,r)=>i.magSq(e)*i.signedArea2(t,n,r)-i.magSq(t)*i.signedArea2(e,n,r)+i.magSq(n)*i.signedArea2(e,t,r)-i.magSq(r)*i.signedArea2(e,t,n)>0,e.pointInPolygon2=(e,t)=>{const n=t.length-1,i=e[0],r=e[1];let s=t[n],o=t[0],a=0;for(let e=0;e<=n;s=o,o=t[++e])a=c(i,r,s[0],s[1],o[0],o[1],a);return a},e.pointInRect=l,e.pointInSegment=(e,r,s,o=n.EPS)=>{const c=t.closestT(e,r,s);return void 0!==c&&i.distSq(e,i.mixN([],r,s,n.clamp01(c)))<o*o},e.pointInSphere=o,e.pointInTriangle2=(e,t,n,r)=>{const s=i.clockwise2(t,n,r)?1:-1;return s*i.signedArea2(t,r,e)>=0&&s*i.signedArea2(n,t,e)>=0&&s*i.signedArea2(r,n,e)>=0},e.testAABBSphere=A,e.testAabbAabb=([e,t,n],[i,r,s],[o,c,a],[l,d,p])=>!(e>o+l||o>e+i||t>c+d||c>t+r||n>a+p||a>n+s),e.testBoxSphere=S,e.testCenteredAABBSphere=x,e.testCenteredBoxSphere=q,e.testCenteredRectCircle=P,e.testCircleCircle=(e,t,n,r)=>i.distSq(e,t)<=Math.pow(n+r,2),e.testRayAABB=(e,t,n,i)=>{const r=N(e,t,n,i);return r[1]>T(r[0],0)},e.testRayRect=(e,t,n,i)=>{const r=m(e,t,n,i);return r[1]>T(r[0],0)},e.testRectCircle=R,e.testRectRect=([e,t],[n,i],[r,s],[o,c])=>!(e>r+o||r>e+n||t>s+c||s>t+i),Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@thi.ng/geom-isec", | ||
"version": "0.4.26", | ||
"version": "0.5.0", | ||
"description": "2D/3D shape intersection checks", | ||
@@ -81,3 +81,3 @@ "module": "./index.js", | ||
"sideEffects": false, | ||
"gitHead": "775cdb99da136625e4633e3efdc0aa15ea7a3917" | ||
"gitHead": "75eb7c46c342cf6dfccdb8745a0191a991ca619d" | ||
} |
@@ -65,3 +65,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (gzipped, pre-treeshake): ESM: 2.37 KB / CJS: 2.53 KB / UMD: 2.50 KB | ||
Package sizes (gzipped, pre-treeshake): ESM: 2.48 KB / CJS: 2.64 KB / UMD: 2.61 KB | ||
@@ -68,0 +68,0 @@ ## Dependencies |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
118062
36
1098