@thi.ng/geom-isec
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.3.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/geom-isec@0.3.2...@thi.ng/geom-isec@0.3.3) (2019-07-31) | ||
**Note:** Version bump only for package @thi.ng/geom-isec | ||
## [0.3.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/geom-isec@0.3.1...@thi.ng/geom-isec@0.3.2) (2019-07-12) | ||
@@ -8,0 +16,0 @@ |
@@ -1,363 +0,1 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@thi.ng/geom-closest-point'), require('@thi.ng/math'), require('@thi.ng/vectors')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@thi.ng/geom-closest-point', '@thi.ng/math', '@thi.ng/vectors'], factory) : | ||
(global = global || self, factory((global.thi = global.thi || {}, global.thi.ng = global.thi.ng || {}, global.thi.ng.geomIsec = {}), global.thi.ng.geomClosestPoint, global.thi.ng.math, global.thi.ng.vectors)); | ||
}(this, function (exports, geomClosestPoint, math, vectors) { 'use strict'; | ||
const pointInSegment = (p, a, b, eps = math.EPS) => { | ||
const t = geomClosestPoint.closestT(p, a, b); | ||
return t !== undefined | ||
? vectors.distSq(p, vectors.mixN([], a, b, math.clamp01(t))) < eps * eps | ||
: false; | ||
}; | ||
const pointInCircle = (p, pos, r) => vectors.distSq(pos, p) <= r * r; | ||
const pointInSphere = pointInCircle; | ||
const classifyPointInCircle = (p, pos, r, eps = math.EPS) => math.sign(r * r - vectors.distSq(pos, p), eps); | ||
const pointInCircumCircle = (a, b, c, d) => vectors.magSq(a) * vectors.signedArea2(b, c, d) - | ||
vectors.magSq(b) * vectors.signedArea2(a, c, d) + | ||
vectors.magSq(c) * vectors.signedArea2(a, b, d) - | ||
vectors.magSq(d) * vectors.signedArea2(a, b, c) > | ||
0; | ||
const pointInTriangle2 = (p, a, b, c) => { | ||
const s = vectors.clockwise2(a, b, c) ? 1 : -1; | ||
return (s * vectors.signedArea2(a, c, p) >= 0 && | ||
s * vectors.signedArea2(b, a, p) >= 0 && | ||
s * vectors.signedArea2(c, b, p) >= 0); | ||
}; | ||
const classifyPointInTriangle2 = (p, a, b, c, eps = math.EPS) => { | ||
const s = vectors.clockwise2(a, b, c) ? 1 : -1; | ||
return math.sign(Math.min(s * vectors.signedArea2(a, c, p), s * vectors.signedArea2(b, a, p), s * vectors.signedArea2(c, b, p)), eps); | ||
}; | ||
const pointInPolygon2 = (p, pts) => { | ||
const n = pts.length - 1; | ||
const px = p[0]; | ||
const py = p[1]; | ||
let a = pts[n]; | ||
let b = pts[0]; | ||
let inside = 0; | ||
for (let i = 0; i <= n; a = b, b = pts[++i]) { | ||
inside = classifyPointPolyPair(px, py, a[0], a[1], b[0], b[1], inside); | ||
} | ||
return inside; | ||
}; | ||
const classifyPointPolyPair = (px, py, ax, ay, bx, by, inside) => ((ay < py && by >= py) || (by < py && ay >= py)) && (ax <= px || bx <= px) | ||
? inside ^ (ax + ((py - ay) / (by - ay)) * (bx - ax) < px ? 1 : 0) | ||
: inside; | ||
const pointInAABB = ([x, y, z], pos, size) => x >= pos[0] && | ||
x <= pos[0] + size[0] && | ||
y >= pos[1] && | ||
y <= pos[1] + size[1] && | ||
z >= pos[2] && | ||
z <= pos[2] + size[2]; | ||
const pointInRect = ([x, y], pos, size) => x >= pos[0] && | ||
x <= pos[0] + size[0] && | ||
y >= pos[1] && | ||
y <= pos[1] + size[1]; | ||
const NONE = Object.freeze({ | ||
type: 0 | ||
}); | ||
const intersectCircleCircle = (a, b, ar, br) => { | ||
const delta = vectors.sub([], b, a); | ||
const d = vectors.mag(delta); | ||
if (math.eqDeltaFixed(d, 0)) { | ||
return { type: 2 }; | ||
} | ||
if (d <= ar + br && d >= Math.abs(ar - br)) { | ||
ar *= ar; | ||
const alpha = (ar - br * br + d * d) / (2 * d); | ||
const h = Math.sqrt(ar - alpha * alpha); | ||
const p = vectors.maddN([], delta, alpha / d, a); | ||
const t = vectors.mulN(null, vectors.perpendicularCCW(null, delta), h / d); | ||
return { | ||
type: 4 , | ||
isec: [vectors.add([], p, t), vectors.sub([], p, t)] | ||
}; | ||
} | ||
return NONE; | ||
}; | ||
const testCircleCircle = (a, b, ar, br) => vectors.distSq(a, b) <= Math.pow(ar + br, 2); | ||
const intersectLineLine = (a, b, c, d, eps = math.EPS) => { | ||
const bax = b[0] - a[0]; | ||
const bay = b[1] - a[1]; | ||
const dcx = d[0] - c[0]; | ||
const dcy = d[1] - c[1]; | ||
const acx = a[0] - c[0]; | ||
const acy = a[1] - c[1]; | ||
const det = dcy * bax - dcx * bay; | ||
let alpha = dcx * acy - dcy * acx; | ||
let beta = bax * acy - bay * acx; | ||
if (math.eqDeltaFixed(det, 0, eps)) { | ||
if (math.eqDeltaFixed(alpha, 0, eps) && math.eqDeltaFixed(beta, 0, eps)) { | ||
let isec = geomClosestPoint.closestPointSegment(c, a, b, undefined, true) || | ||
geomClosestPoint.closestPointSegment(d, a, b, undefined, true); | ||
return { | ||
type: isec | ||
? 2 | ||
: 3 , | ||
isec | ||
}; | ||
} | ||
return { type: 1 }; | ||
} | ||
alpha /= det; | ||
beta /= det; | ||
const ieps = 1 - eps; | ||
return { | ||
type: eps < alpha && alpha < ieps && (eps < beta && beta < ieps) | ||
? 4 | ||
: 5 , | ||
isec: vectors.mixN2([], a, b, alpha), | ||
alpha, | ||
beta, | ||
det | ||
}; | ||
}; | ||
const isParallelLine = (a, b, c, d) => math.eqDeltaFixed((d[1] - c[1]) * (b[0] - a[0]) - (d[0] - c[0]) * (b[1] - a[1]), 0); | ||
const intersectPlanePlane = (na, wa, nb, wb) => { | ||
const dn = vectors.dot3(na, nb); | ||
if (math.eqDeltaFixed(dn, 1)) { | ||
return math.eqDelta(wa, wb) ? { type: 2 } : NONE; | ||
} | ||
const det = 1 / (1 - dn * dn); | ||
const da = (wa - wb * dn) * det; | ||
const db = (wb - wa * dn) * det; | ||
return { | ||
type: 4 , | ||
isec: [ | ||
vectors.add3(null, vectors.mulN3([], na, da), vectors.mulN3([], nb, db)), | ||
vectors.cross3([], na, nb) | ||
] | ||
}; | ||
}; | ||
const intersectRayCircle = (rpos, dir, spos, r) => { | ||
const delta = vectors.sub([], spos, rpos); | ||
const w = vectors.dot(delta, dir); | ||
let d = r * r + w * w - vectors.magSq(delta); | ||
if (d >= 0) { | ||
d = Math.sqrt(d); | ||
const a = w + d; | ||
const b = w - d; | ||
const isec = a >= 0 | ||
? b >= 0 | ||
? a > b | ||
? [vectors.maddN(delta, dir, b, rpos), vectors.maddN([], dir, a, rpos)] | ||
: [vectors.maddN(delta, dir, a, rpos), vectors.maddN([], dir, b, rpos)] | ||
: [vectors.maddN(delta, dir, a, rpos)] | ||
: b >= 0 | ||
? [vectors.maddN(delta, dir, b, rpos)] | ||
: undefined; | ||
return isec ? { type: 4 , isec } : NONE; | ||
} | ||
return NONE; | ||
}; | ||
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: 4 , | ||
isec: vectors.maddN([], dir, t, rpos), | ||
alpha: t | ||
} | ||
: NONE; | ||
}; | ||
const intersectRayPlane = (rpos, dir, normal, w, eps = math.EPS) => { | ||
const d = vectors.dot(normal, dir); | ||
const cp = math.sign(vectors.dot(normal, rpos) - w, eps); | ||
if ((d > eps && cp < 0) || (d < -eps && cp > 0)) { | ||
const isec = vectors.sub(null, vectors.mulN([], normal, w), rpos); | ||
const alpha = vectors.dot(normal, isec) / d; | ||
return { | ||
type: 4 , | ||
isec: vectors.maddN(isec, dir, alpha, rpos), | ||
alpha | ||
}; | ||
} | ||
return cp === 0 | ||
? { | ||
type: 2 , | ||
isec: vectors.copy(rpos) | ||
} | ||
: NONE; | ||
}; | ||
const intersectRayPolyline = (rpos, dir, pts, closed = false) => { | ||
const n = pts.length - 1; | ||
let minD = Infinity; | ||
let cross = 0; | ||
let i, j; | ||
if (closed) { | ||
i = pts[n]; | ||
j = pts[0]; | ||
} | ||
else { | ||
i = pts[0]; | ||
j = pts[1]; | ||
} | ||
for (let k = 0; k <= n; i = j, j = pts[++k]) { | ||
const d = intersectRayLine(rpos, dir, i, j).alpha; | ||
if (d !== undefined) { | ||
cross++; | ||
if (d < minD) | ||
minD = d; | ||
} | ||
} | ||
return cross > 0 | ||
? { | ||
type: 4 , | ||
isec: vectors.maddN2([], dir, minD, rpos), | ||
inside: !(cross & 1), | ||
alpha: minD | ||
} | ||
: NONE; | ||
}; | ||
const intersectRayPolylineAll = (rpos, dir, pts, closed = false) => { | ||
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(rpos, dir, i, j).alpha; | ||
if (d !== undefined) { | ||
res.push([d, vectors.maddN2([], dir, d, rpos)]); | ||
} | ||
} | ||
return res.length | ||
? { | ||
type: 4 , | ||
isec: res.sort((a, b) => a[0] - b[0]).map((x) => x[1]) | ||
} | ||
: NONE; | ||
}; | ||
const min = Math.min; | ||
const max = Math.max; | ||
const rayRect = (rpos, dir, bmin, bmax) => { | ||
let p = rpos[0], d = 1 / dir[0]; | ||
let t1 = (bmin[0] - p) * d; | ||
let t2 = (bmax[0] - p) * d; | ||
let tmin = min(t1, t2); | ||
let tmax = max(t1, t2); | ||
(p = rpos[1]), (d = 1 / dir[1]); | ||
t1 = (bmin[1] - p) * d; | ||
t2 = (bmax[1] - p) * d; | ||
return [max(tmin, min(t1, t2)), min(tmax, max(t1, t2))]; | ||
}; | ||
const rayBox = (rpos, dir, bmin, bmax) => { | ||
let p = rpos[0], d = 1 / dir[0]; | ||
let t1 = (bmin[0] - p) * d; | ||
let t2 = (bmax[0] - p) * d; | ||
let tmin = min(t1, t2); | ||
let tmax = max(t1, t2); | ||
(p = rpos[1]), (d = 1 / dir[1]); | ||
t1 = (bmin[1] - p) * d; | ||
t2 = (bmax[1] - p) * d; | ||
(p = rpos[2]), (d = 1 / dir[2]); | ||
t1 = (bmin[2] - p) * d; | ||
t2 = (bmax[2] - p) * d; | ||
tmin = max(tmin, min(t1, t2)); | ||
tmax = min(tmax, max(t1, t2)); | ||
return [max(tmin, min(t1, t2)), min(tmax, max(t1, t2))]; | ||
}; | ||
const intersectWith = (fn) => (rpos, dir, bmin, bmax) => { | ||
const t = fn(rpos, dir, bmin, bmax); | ||
const tmin = t[0]; | ||
const tmax = t[1]; | ||
const inside = tmin < 0; | ||
return tmax > max(tmin, 0) | ||
? inside | ||
? { | ||
type: 4 , | ||
inside, | ||
isec: [vectors.maddN([], dir, tmax, rpos)], | ||
alpha: tmax | ||
} | ||
: { | ||
type: 4 , | ||
isec: [ | ||
vectors.maddN([], dir, tmin, rpos), | ||
vectors.maddN([], dir, tmax, rpos) | ||
], | ||
alpha: tmin, | ||
beta: tmax | ||
} | ||
: NONE; | ||
}; | ||
const intersectRayRect = intersectWith(rayRect); | ||
const intersectRayAABB = intersectWith(rayBox); | ||
const testRayRect = (rpos, dir, bmin, bmax) => { | ||
const t = rayRect(rpos, dir, bmin, bmax); | ||
return t[1] > max(t[0], 0); | ||
}; | ||
const testRayAABB = (rpos, dir, bmin, bmax) => { | ||
const t = rayBox(rpos, dir, bmin, bmax); | ||
return t[1] > max(t[0], 0); | ||
}; | ||
const testRectCircle = ([rx, ry], [w, h], [cx, cy], r) => axis(cx, rx, w) + axis(cy, ry, h) <= r * r; | ||
const testAABBSphere = ([rx, ry, rz], [w, h, d], [cx, cy, cz], r) => axis(cx, rx, w) + axis(cy, ry, h) + axis(cz, rz, d) <= r * r; | ||
const axis = (a, b, c) => Math.pow(a < b ? a - b : a > b + c ? a - b - c : 0, 2); | ||
const testRectRect = ([ax, ay], [aw, ah], [bx, by], [bw, bh]) => !(ax > bx + bw || bx > ax + aw || ay > by + bh || by > ay + ah); | ||
const testAabbAabb = ([ax, ay, az], [aw, ah, ad], [bx, by, bz], [bw, bh, bd]) => !(ax > bx + bw || | ||
bx > ax + aw || | ||
ay > by + bh || | ||
by > ay + ah || | ||
az > bz + bd || | ||
bz > az + ad); | ||
exports.classifyPointInCircle = classifyPointInCircle; | ||
exports.classifyPointInTriangle2 = classifyPointInTriangle2; | ||
exports.classifyPointPolyPair = classifyPointPolyPair; | ||
exports.intersectCircleCircle = intersectCircleCircle; | ||
exports.intersectLineLine = intersectLineLine; | ||
exports.intersectPlanePlane = intersectPlanePlane; | ||
exports.intersectRayAABB = intersectRayAABB; | ||
exports.intersectRayCircle = intersectRayCircle; | ||
exports.intersectRayLine = intersectRayLine; | ||
exports.intersectRayPlane = intersectRayPlane; | ||
exports.intersectRayPolyline = intersectRayPolyline; | ||
exports.intersectRayPolylineAll = intersectRayPolylineAll; | ||
exports.intersectRayRect = intersectRayRect; | ||
exports.isParallelLine = isParallelLine; | ||
exports.pointInAABB = pointInAABB; | ||
exports.pointInCircle = pointInCircle; | ||
exports.pointInCircumCircle = pointInCircumCircle; | ||
exports.pointInPolygon2 = pointInPolygon2; | ||
exports.pointInRect = pointInRect; | ||
exports.pointInSegment = pointInSegment; | ||
exports.pointInSphere = pointInSphere; | ||
exports.pointInTriangle2 = pointInTriangle2; | ||
exports.testAABBSphere = testAABBSphere; | ||
exports.testAabbAabb = testAabbAabb; | ||
exports.testCircleCircle = testCircleCircle; | ||
exports.testRayAABB = testRayAABB; | ||
exports.testRayRect = testRayRect; | ||
exports.testRectCircle = testRectCircle; | ||
exports.testRectRect = testRectRect; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
!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")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/geom-closest-point","@thi.ng/math","@thi.ng/vectors"],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)}(this,function(e,t,n,i){"use strict";const s=(e,t,n)=>i.distSq(t,e)<=n*n,r=s,a=(e,t,n,i,s,r,a)=>(i<t&&r>=t||r<t&&i>=t)&&(n<=e||s<=e)?a^(n+(t-i)/(r-i)*(s-n)<e?1:0):a,o=Object.freeze({type:0}),c=(e,t,s,r)=>{const a=r[0]-s[0],c=r[1]-s[1],l=t[0]*c-t[1]*a;if(n.eqDeltaFixed(l,0))return o;const d=s[0]-e[0],p=s[1]-e[1],u=(c*d-a*p)/l,g=(t[1]*d-t[0]*p)/l;return u>=0&&g>=0&&g<=1?{type:4,isec:i.maddN([],t,u,e),alpha:u}:o},l=Math.min,d=Math.max,p=(e,t,n,i)=>{let s=e[0],r=1/t[0],a=(n[0]-s)*r,o=(i[0]-s)*r,c=l(a,o),p=d(a,o);return s=e[1],r=1/t[1],a=(n[1]-s)*r,o=(i[1]-s)*r,[d(c,l(a,o)),l(p,d(a,o))]},u=(e,t,n,i)=>{let s=e[0],r=1/t[0],a=(n[0]-s)*r,o=(i[0]-s)*r,c=l(a,o),p=d(a,o);return s=e[1],r=1/t[1],a=(n[1]-s)*r,o=(i[1]-s)*r,s=e[2],r=1/t[2],a=(n[2]-s)*r,o=(i[2]-s)*r,c=d(c,l(a,o)),p=l(p,d(a,o)),[d(c,l(a,o)),l(p,d(a,o))]},g=e=>(t,n,s,r)=>{const a=e(t,n,s,r),c=a[0],l=a[1],p=c<0;return l>d(c,0)?p?{type:4,inside:p,isec:[i.maddN([],n,l,t)],alpha:l}:{type:4,isec:[i.maddN([],n,c,t),i.maddN([],n,l,t)],alpha:c,beta:l}:o},m=g(p),h=g(u),y=(e,t,n)=>Math.pow(e<t?e-t:e>t+n?e-t-n:0,2);e.classifyPointInCircle=(e,t,s,r=n.EPS)=>n.sign(s*s-i.distSq(t,e),r),e.classifyPointInTriangle2=(e,t,s,r,a=n.EPS)=>{const o=i.clockwise2(t,s,r)?1:-1;return n.sign(Math.min(o*i.signedArea2(t,r,e),o*i.signedArea2(s,t,e),o*i.signedArea2(r,s,e)),a)},e.classifyPointPolyPair=a,e.intersectCircleCircle=(e,t,s,r)=>{const a=i.sub([],t,e),c=i.mag(a);if(n.eqDeltaFixed(c,0))return{type:2};if(c<=s+r&&c>=Math.abs(s-r)){const t=((s*=s)-r*r+c*c)/(2*c),n=Math.sqrt(s-t*t),o=i.maddN([],a,t/c,e),l=i.mulN(null,i.perpendicularCCW(null,a),n/c);return{type:4,isec:[i.add([],o,l),i.sub([],o,l)]}}return o},e.intersectLineLine=(e,s,r,a,o=n.EPS)=>{const c=s[0]-e[0],l=s[1]-e[1],d=a[0]-r[0],p=a[1]-r[1],u=e[0]-r[0],g=e[1]-r[1],m=p*c-d*l;let h=d*g-p*u,y=c*g-l*u;if(n.eqDeltaFixed(m,0,o)){if(n.eqDeltaFixed(h,0,o)&&n.eqDeltaFixed(y,0,o)){let n=t.closestPointSegment(r,e,s,void 0,!0)||t.closestPointSegment(a,e,s,void 0,!0);return{type:n?2:3,isec:n}}return{type:1}}y/=m;const f=1-o;return{type:o<(h/=m)&&h<f&&o<y&&y<f?4:5,isec:i.mixN2([],e,s,h),alpha:h,beta:y,det:m}},e.intersectPlanePlane=(e,t,s,r)=>{const a=i.dot3(e,s);if(n.eqDeltaFixed(a,1))return n.eqDelta(t,r)?{type:2}:o;const c=1/(1-a*a),l=(t-r*a)*c,d=(r-t*a)*c;return{type:4,isec:[i.add3(null,i.mulN3([],e,l),i.mulN3([],s,d)),i.cross3([],e,s)]}},e.intersectRayAABB=h,e.intersectRayCircle=(e,t,n,s)=>{const r=i.sub([],n,e),a=i.dot(r,t);let c=s*s+a*a-i.magSq(r);if(c>=0){const n=a+(c=Math.sqrt(c)),s=a-c,l=n>=0?s>=0?n>s?[i.maddN(r,t,s,e),i.maddN([],t,n,e)]:[i.maddN(r,t,n,e),i.maddN([],t,s,e)]:[i.maddN(r,t,n,e)]:s>=0?[i.maddN(r,t,s,e)]:void 0;return l?{type:4,isec:l}:o}return o},e.intersectRayLine=c,e.intersectRayPlane=(e,t,s,r,a=n.EPS)=>{const c=i.dot(s,t),l=n.sign(i.dot(s,e)-r,a);if(c>a&&l<0||c<-a&&l>0){const n=i.sub(null,i.mulN([],s,r),e),a=i.dot(s,n)/c;return{type:4,isec:i.maddN(n,t,a,e),alpha:a}}return 0===l?{type:2,isec:i.copy(e)}:o},e.intersectRayPolyline=(e,t,n,s=!1)=>{const r=n.length-1;let a,l,d=1/0,p=0;s?(a=n[r],l=n[0]):(a=n[0],l=n[1]);for(let i=0;i<=r;a=l,l=n[++i]){const n=c(e,t,a,l).alpha;void 0!==n&&(p++,n<d&&(d=n))}return p>0?{type:4,isec:i.maddN2([],t,d,e),inside:!(1&p),alpha:d}:o},e.intersectRayPolylineAll=(e,t,n,s=!1)=>{const r=n.length-1;let a,l;s?(a=n[r],l=n[0]):(a=n[0],l=n[1]);const d=[];for(let s=0;s<=r;a=l,l=n[++s]){const n=c(e,t,a,l).alpha;void 0!==n&&d.push([n,i.maddN2([],t,n,e)])}return d.length?{type:4,isec:d.sort((e,t)=>e[0]-t[0]).map(e=>e[1])}:o},e.intersectRayRect=m,e.isParallelLine=(e,t,i,s)=>n.eqDeltaFixed((s[1]-i[1])*(t[0]-e[0])-(s[0]-i[0])*(t[1]-e[1]),0),e.pointInAABB=([e,t,n],i,s)=>e>=i[0]&&e<=i[0]+s[0]&&t>=i[1]&&t<=i[1]+s[1]&&n>=i[2]&&n<=i[2]+s[2],e.pointInCircle=s,e.pointInCircumCircle=(e,t,n,s)=>i.magSq(e)*i.signedArea2(t,n,s)-i.magSq(t)*i.signedArea2(e,n,s)+i.magSq(n)*i.signedArea2(e,t,s)-i.magSq(s)*i.signedArea2(e,t,n)>0,e.pointInPolygon2=(e,t)=>{const n=t.length-1,i=e[0],s=e[1];let r=t[n],o=t[0],c=0;for(let e=0;e<=n;r=o,o=t[++e])c=a(i,s,r[0],r[1],o[0],o[1],c);return c},e.pointInRect=([e,t],n,i)=>e>=n[0]&&e<=n[0]+i[0]&&t>=n[1]&&t<=n[1]+i[1],e.pointInSegment=(e,s,r,a=n.EPS)=>{const o=t.closestT(e,s,r);return void 0!==o&&i.distSq(e,i.mixN([],s,r,n.clamp01(o)))<a*a},e.pointInSphere=r,e.pointInTriangle2=(e,t,n,s)=>{const r=i.clockwise2(t,n,s)?1:-1;return r*i.signedArea2(t,s,e)>=0&&r*i.signedArea2(n,t,e)>=0&&r*i.signedArea2(s,n,e)>=0},e.testAABBSphere=([e,t,n],[i,s,r],[a,o,c],l)=>y(a,e,i)+y(o,t,s)+y(c,n,r)<=l*l,e.testAabbAabb=([e,t,n],[i,s,r],[a,o,c],[l,d,p])=>!(e>a+l||a>e+i||t>o+d||o>t+s||n>c+p||c>n+r),e.testCircleCircle=(e,t,n,s)=>i.distSq(e,t)<=Math.pow(n+s,2),e.testRayAABB=(e,t,n,i)=>{const s=u(e,t,n,i);return s[1]>d(s[0],0)},e.testRayRect=(e,t,n,i)=>{const s=p(e,t,n,i);return s[1]>d(s[0],0)},e.testRectCircle=([e,t],[n,i],[s,r],a)=>y(s,e,n)+y(r,t,i)<=a*a,e.testRectRect=([e,t],[n,i],[s,r],[a,o])=>!(e>s+a||s>e+n||t>r+o||r>t+i),Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@thi.ng/geom-isec", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "2D/3D shape intersection checks", | ||
@@ -17,25 +17,26 @@ "module": "./index.js", | ||
"scripts": { | ||
"build": "yarn clean && yarn build:es6 && yarn build:bundle", | ||
"build": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module", | ||
"build:release": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module all", | ||
"build:es6": "tsc --declaration", | ||
"build:bundle": "../../scripts/bundle-module", | ||
"test": "rimraf build && tsc -p test/tsconfig.json && nyc mocha build/test/*.js", | ||
"build:test": "rimraf build && tsc -p test/tsconfig.json", | ||
"test": "yarn build:test && mocha build/test/*.js", | ||
"cover": "yarn build:test && nyc mocha build/test/*.js && nyc report --reporter=lcov", | ||
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib", | ||
"cover": "yarn test && nyc report --reporter=lcov", | ||
"doc": "node_modules/.bin/typedoc --mode modules --out doc --ignoreCompilerErrors src", | ||
"pub": "yarn build && yarn publish --access public" | ||
"pub": "yarn build:release && yarn publish --access public" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^12.0.8", | ||
"@types/node": "^12.6.3", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.0.0", | ||
"typedoc": "^0.14.2", | ||
"typescript": "^3.5.2" | ||
"typescript": "^3.5.3" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/api": "^6.3.1", | ||
"@thi.ng/geom-api": "^0.3.0", | ||
"@thi.ng/geom-closest-point": "^0.3.2", | ||
"@thi.ng/math": "^1.4.1", | ||
"@thi.ng/vectors": "^3.0.2" | ||
"@thi.ng/api": "^6.3.2", | ||
"@thi.ng/geom-api": "^0.3.1", | ||
"@thi.ng/geom-closest-point": "^0.3.3", | ||
"@thi.ng/math": "^1.4.2", | ||
"@thi.ng/vectors": "^3.0.3" | ||
}, | ||
@@ -60,3 +61,3 @@ "keywords": [ | ||
"sideEffects": false, | ||
"gitHead": "47075afc37f3a16adee7c903a2935304c7cf5daf" | ||
"gitHead": "53eec7988c378fc37ae140e7174f36ef9b6208fe" | ||
} |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
92274
783
2
Updated@thi.ng/api@^6.3.2
Updated@thi.ng/geom-api@^0.3.1
Updated@thi.ng/math@^1.4.2
Updated@thi.ng/vectors@^3.0.3