@pacem/pacem-numerical 1.0.0-abel → 1.0.0-amaldi
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/pacem-numerical.js +5 -0
- package/dist/browser/pacem-numerical.min.js +5 -0
- package/dist/bundle/pacem-numerical.min.mjs +5 -0
- package/dist/bundle/pacem-numerical.mjs +5 -0
- package/dist/esm/index-geometry-linearalgebra.js +5 -0
- package/dist/esm/index-geometry.js +5 -0
- package/dist/esm/index-iife.js +5 -0
- package/dist/esm/index-mathematics-dataanalysis.js +5 -0
- package/dist/esm/index-mathematics.js +5 -0
- package/dist/esm/index.js +5 -0
- package/package.json +1 -1
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pacem/pacem-numerical v1.0.0-amaldi (https://js.pacem.it)
|
|
3
|
+
* Pacem (https://pacem.it)
|
|
4
|
+
* Licensed under Apache-2.0
|
|
5
|
+
*/
|
|
1
6
|
!function(t){"use strict";class e{static unit(t){const e={x:t.x,y:t.y};return this.normalize(e),e}static magSqr(t){return t.x*t.x+t.y*t.y}static mag(t){return Math.sqrt(e.magSqr(t))}static normalize(t){const r=e.mag(t);if(r<=0)throw"Cannot normalize a vector of length 0.";const n=1/r;t.x*=n,t.y*=n}static from(e,r){return t.Point.subtract(e,r)}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)}}class r{constructor(t,e,r=-1){this.x=t,this.y=e,this.index=r}equals(t){return this.x===t.x&&this.y===t.y}}class n{constructor(t,e,r){this.v0=t,this.v1=e,this.v2=r,this.circumCirc=function(t,e,r){const n=t.x,s=t.y,o=e.x,i=e.y,a=r.x,m=r.y,c=2*(n*(i-m)+o*(m-s)+a*(s-i));if(Math.abs(c)<1e-12)return{c:{x:0,y:0},r:1/0};const l=((n*n+s*s)*(i-m)+(o*o+i*i)*(m-s)+(a*a+m*m)*(s-i))/c,f=((n*n+s*s)*(a-o)+(o*o+i*i)*(n-a)+(a*a+m*m)*(o-n))/c;return{c:{x:l,y:f},r:Math.hypot(l-n,f-s)}}(t,e,r)}inCircumcircle(t){const e=this.circumCirc.c.x-t.x,r=this.circumCirc.c.y-t.y;return Math.hypot(e,r)<=this.circumCirc.r+1e-9}}function s(t,e){const r=[];e=e.filter(e=>!e.inCircumcircle(t)||(r.push({v0:e.v0,v1:e.v1}),r.push({v0:e.v1,v1:e.v2}),r.push({v0:e.v2,v1:e.v0}),!1));const s=function(t){const e=[];for(let r=0;r<t.length;++r){let n=!0;for(let e=0;e<t.length;++e)if(r!==e){const s=t[r],o=t[e];if(s.v0.equals(o.v0)&&s.v1.equals(o.v1)||s.v0.equals(o.v1)&&s.v1.equals(o.v0)){n=!1;break}}n&&e.push(t[r])}return e}(r);for(const r of s)e.push(new n(r.v0,r.v1,t));return e}function o(t){if(t.length<3)return[];const e=function(t){let e=1/0,s=1/0,o=-1/0,i=-1/0;for(const r of t)e=Math.min(e,r.x),s=Math.min(s,r.y),o=Math.max(o,r.x),i=Math.max(i,r.y);const a=10*(o-e),m=10*(i-s),c=new r(e-a,s-3*m),l=new r(e-a,i+m),f=new r(o+3*a,i+m);return new n(c,l,f)}(t);let o=[e];for(const e of t)o=s(e,o);return o=o.filter(t=>!(t.v0===e.v0||t.v0===e.v1||t.v0===e.v2||t.v1===e.v0||t.v1===e.v1||t.v1===e.v2||t.v2===e.v0||t.v2===e.v1||t.v2===e.v2)),o}class i{static triangulate(t){return function(t){if(t.length<3)return[];const e=o(t.map((t,e)=>new r(t.x,t.y,e))),n=[];for(const t of e)n.push(t.v0.index,t.v1.index,t.v2.index);return n}(t)}}const a=180/Math.PI,m=2*Math.PI;function c(e){return t.Point.isPoint(e)}let l=class r{static slopeRad(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}static slopeRad2(t,e){return(m+r.slopeRad(t,e))%m}static slopeDeg(t,e){return r.slopeRad(t,e)*a}static slopeDeg2(t,e){return(360+r.slopeDeg(t,e))%360}static intersect(e,n,...s){return Array.isArray(e)&&Array.isArray(n)?r._intersectSegments(e,n,!0):t.Rect.isRect(e)?r._intersectRects(...arguments):"vertices"in e?r._mergePolygons(e,n,"intersect")?.polygons??null:null}static boundingBox(t){let e=Number.MAX_VALUE,r=Number.MAX_VALUE,n=-Number.MAX_VALUE,s=-Number.MAX_VALUE;t.length;for(let o of t)e=Math.min(e,o.x),r=Math.min(r,o.y),n=Math.max(n,o.x),s=Math.max(s,o.y);return{x:e,y:r,width:n-e,height:s-r}}static combinePolygons(t,e,n){return r._mergePolygons(t,e,n)}static _mergePolygons(e,n,s){if(t.NullChecker.isNullOrEmpty(e?.vertices)||t.NullChecker.isNullOrEmpty(n?.vertices))return null;const o=e.vertices.filter(t=>r.inPolygon(t,n.vertices));if(e.vertices.length==o.length)return{polygons:"intersect"===s?[e]:[n]};const i=n.vertices.filter(t=>r.inPolygon(t,e.vertices));if(n.vertices.length===i.length)return{polygons:"intersect"===s?[n]:[e]};const a=r.boundingBox(e.vertices),m=r.boundingBox(n.vertices),c=r.intersect(a,m);if(!("union"===s||t.Rect.isRect(c)&&c.width>0&&c.height>0))return null;const{vertices:l}=e,{vertices:f}=n;if(l.length<3||f.length<3)return null;const u=(t,e,r)=>[t,r[(e+1)%r.length]],h=(t,e)=>t.x===e.x?t.y-e.y:t.x-e.x,y=l.map(u),x=f.map(u),g=l.concat(f),p=new Map,d=t=>{if(!p.has(t)){const e=[];p.set(t,e)}return p.get(t)};let M=!1;for(let e of y){const n=d(e);for(let s of x){const o=d(s),i=r.intersect(e,s);t.NullChecker.isNull(i)||(M=!0,g.push(i),n.push(i),o.push(i))}}if(0===o.length&&0===i.length&&!M)return"union"===s?{polygons:[e,n]}:null;const v=[];for(let e of y.concat(x)){const r=d(e);if(t.NullChecker.isNullOrEmpty(r))v.push(e);else{const t=e.concat(r).sort(h);for(let e=0;e<t.length-1;e++)v.push([t[e],t[e+1]])}}var b,w=!1;do{g.sort(h),g.filter((t,e,n)=>0===e||!r.areClose(t,n[e-1])),b=r.mesh(g);const{vertices:e,triangleIndices:n}=b;w=!1;for(let s=0;s<n.length;s+=3){const o=n[s],i=n[s+1],a=n[s+2],m=e[o],c=e[i],l=e[a],f=[[m,c],[c,l],[l,m]];for(let e of v)for(let n of f){const s=r.areClose(n[0],e[0])||r.areClose(n[1],e[1])||r.areClose(n[0],e[1])||r.areClose(n[1],e[0])?null:r.intersect(n,e);t.NullChecker.isNull(s)||-1!==g.findIndex(t=>r.areClose(t,s,4))||(w=!0,g.push(s))}}}while(w);const{vertices:z,triangleIndices:A}=b,N=[];for(let t=0;t<A.length;t+=3){const e=t+1,n=t+2,o=z[A[t]],i=z[A[e]],a=z[A[n]],m={x:(o.x+i.x+a.x)/3,y:(o.y+i.y+a.y)/3},c=r.inPolygon(m,l),u=r.inPolygon(m,f);(c&&u&&"intersect"===s||(c||u)&&"union"===s||(c&&!u||!c&&u)&&"difference"===s)&&N.push([o,i,a])}const C=N.flatMap(([t,e,r])=>[[t,e],[e,r],[r,t]]),_=[];for(let t=0;t<C.length;t++){const e=C[t];if(0==t){_.push(e);continue}const n=_.findIndex(t=>r.areClose(t[0],e[0])&&r.areClose(t[1],e[1])||r.areClose(t[0],e[1])&&r.areClose(t[1],e[0]));-1===n?_.push(e):_.splice(n,1)}if(_.length<3)return null;const q=[],X=t=>{const{length:e}=t,n=r.areClose(t[0],t[e-1]),s=t.slice(0,n?e-1:e);return s.length>3&&r.inSegment(s[0],[s[1],s[s.length-1]])&&s.shift(),s},[P,Y]=_.shift(),Z=[P,Y];for(;_.length>1;){const t=Z[Z.length-1],e=_.findIndex(e=>r.areClose(e[0],t)||r.areClose(e[1],t));if(-1===e){q.push({vertices:X(Z.splice(0))});const[t,e]=_.shift();Z.push(t,e)}else{const[n]=_.splice(e,1),s=r.areClose(n[0],t)?n[1]:r.areClose(n[1],t)?n[0]:null;Z.length>1&&r.inSegment(Z[Z.length-1],[Z[Z.length-2],s])?Z.splice(Z.length-1,1,s):Z.push(s)}}return q.push({vertices:X(Z)}),{polygons:q,mesh:b,triangles:N.map(t=>({vertices:t}))}}static mesh(t,...e){const r=[].concat(t).concat(e);return{vertices:r,triangleIndices:i.triangulate(r)}}static intersectLines(t,e,n,s){let o,i;if(Array.isArray(t)&&Array.isArray(e)&&2===t.length&&2===e.length&&"number"==typeof t[0]&&"number"==typeof e[0]&&"number"==typeof t[1]&&"number"==typeof e[1]&&(n=e[0],s=e[1],e=t[1],t=t[0]),"number"==typeof t&&"number"==typeof e){o=[{x:0,y:e},{x:1,y:t+e}],i=[{x:0,y:s},{x:1,y:n+s}]}else o=t,i=e;return r._intersectSegments(o,i,!1)}static cramer(t,e){Array.isArray(t)&&(t={a:t[0],b:t[1],c:t[2]}),Array.isArray(e)&&(e={a:e[0],b:e[1],c:e[2]});let r=(t.b*e.c-t.c*e.b)/(t.b*e.a-t.a*e.b),n=(t.c*e.a-t.a*e.c)/(t.b*e.a-t.a*e.b);return{x:-r.roundoff(),y:-n.roundoff()}}static mq(t,e){let r;if(c(t)?r=t:(r=t[0],e=t[1]),r.x===e.x)return[Number.NaN,Number.NaN];const n=(e.y-r.y)/(e.x-r.x);return[n,r.y-n*r.x]}static _intersectSegments(t,e,n){const s=t[0],o=t[1],i=e[0],a=e[1],m=Math.min(s.x,o.x),c=Math.min(s.y,o.y),l=Math.max(s.x,o.x),f=l-m,u=Math.max(s.y,o.y),h=u-c,y=Math.min(i.x,a.x),x=Math.min(i.y,a.y),g=Math.max(i.x,a.x),p=g-y,d=Math.max(i.y,a.y),M=d-x;if(0===f&&0===p)return null;if(0===h&&0===M)return null;const v=t=>t.x<y||t.x>g||t.x<m||t.x>l,b=t=>t.y<x||t.y>d||t.y<c||t.y>u;var w=null;if(0===f){if(n&&(y>m||g<l))return null;const t=r.mq(i,a);w=r.cramer([1,0,-m],[t[0],-1,t[1]]),n&&b(w)&&(w=null)}else if(0===p){if(n&&(m>y||l<g))return null;const t=r.mq(s,o);w=r.cramer([t[0],-1,t[1]],[1,0,-y]),n&&b(w)&&(w=null)}else if(0===h){if(n&&(x>c||d<u))return null;const t=r.mq(i,a);w=r.cramer([0,1,-c],[t[0],-1,t[1]]),n&&v(w)&&(w=null)}else if(0===M){if(n&&(c>x||u<d))return null;const t=r.mq(s,o);w=r.cramer([t[0],-1,t[1]],[0,1,-x]),n&&v(w)&&(w=null)}else{let t;if(!n||(t=r._intersectRects({x:m,y:c,width:f,height:h},{x:y,y:x,width:p,height:M}))&&t.width>0&&t.height>0){const e=r.mq(s,o),m=r.mq(i,a),c=e[0],l=m[0],f=e[1],u=m[1];if(c!==l){let e=(w=r.cramer([c,-1,f],[l,-1,u])).x,s=w.y;n&&(e<t.x||e>t.x+t.width||s<t.y||s>t.y+t.height)&&(w=null)}}}return null===w?null:{x:w.x,y:w.y}}static _intersectRects(...e){return t.Rect.intersect(...e)}static _areClose(t,e,r=12){return Math.abs(t.x-e.x).isCloseTo(0,r)&&Math.abs(t.y-e.y).isCloseTo(0,r)}static areClose(t,e,n=12){return r._areClose(t,e,n)}static dot(t,r){return e.dot(t,r)}static cross(t,r){return e.cross(t,r)}static distance(e,r){if(null!=(n=e)&&Array.isArray(n)&&2===n.length&&c(n[0])&&c(n[1]))return t.Point.distance(e[0],e[1]);if(c(r))return t.Point.distance(e,r);{const t=r[0],n=r[1];return Math.abs(t*e.x-e.y+n)/Math.sqrt(Math.pow(t,2)+1)}var n}static _pointSegmentDistance(t,n){const s=e.from(n[0],n[1]),o=e.from(n[0],t);return r.cross(s,o)}static isWithin(t,e,n,s=12){const o=r._pointSegmentDistance(t,e);return!o.isCloseTo(0,s)&&(n?o<0:o>0)}static isBeyond(t,e,n,s=12){return r.isWithin(t,e,!n,s)}static inLine(t,e,n=12){return r._pointSegmentDistance(t,e).isCloseTo(0,n)}static inSegment(t,e,n=12){const s=Math.min(e[0].x,e[1].x),o=Math.max(e[0].x,e[1].x),i=Math.min(e[0].y,e[1].y),a=Math.max(e[0].y,e[1].y);return t.x>=s&&t.x<=o&&t.y>=i&&t.y<=a&&r.inLine(t,e,n)}static inTriangle(e,n){let s;for(let o=0;o<3;o++){const i=n[o],a=n[(o+1)%3],m=t.Point.subtract(a,e),c=t.Point.subtract(i,e),l=r.cross(m,c);if(o>0&&l*s<=0)return!1;s=l}return!0}static inPolygon(t,e,n=12){if(!(e?.length>=3))throw"Not enough vertices";const s=e.length;if(3===s)return r.inTriangle(t,[e[0],e[1],e[2]]);n>0&&(e=e.map(t=>({x:t.x.roundoff(n),y:t.y.roundoff(n)})),t={x:t.x.roundoff(n),y:t.y.roundoff(n)});let o=Number.MAX_VALUE,i=Number.MAX_VALUE,a=Number.MIN_VALUE,m=Number.MIN_VALUE;for(let t=0;t<s;t++){const r=e[t];o=Math.min(o,r.x),i=Math.min(i,r.y),a=Math.max(a,r.x),m=Math.max(m,r.y)}if(t.x<o||t.x>a||t.y<i||t.y>m)return!1;const c=[{x:o-1,y:t.y},t];let l=0;for(let n=0;n<s;n++){const o=e[n],i=e[(n+1)%s],a=[o,i];if(o.y===t.y){const r=e[(n-1+s)%s];t.x>o.x&&(r.y-t.y)*(i.y-t.y)<0&&l++}else{if(i.y===t.y)continue;null!=r.intersect(a,c)&&l++}}return l%2==1}static area(t,...e){const r=[].concat(t).concat(e);let n=0;const s=r.length;if(s>=3){for(let t=0;t<r.length;t++){const{x:e,y:o}=r[t],i=t===s-1?0:t+1,{x:a,y:m}=r[i];n+=e*m-o*a}n*=.5}return Math.abs(n.roundoff())}static convexHull(t,...e){const r=[].concat(t).concat(e);if(!(r?.length>1))return r?.slice()??[];const n=r.map(t=>({x:t.x,y:t.y})).sort((t,e)=>t.x===e.x?t.y-e.y:t.x-e.x),s=[];for(const t of n){const e=s[s.length-1];e&&e.x===t.x&&e.y===t.y||s.push(t)}if(s.length<=2)return s;const o=(t,e,r)=>(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x),i=[];for(const t of s){for(;i.length>=2&&o(i[i.length-2],i[i.length-1],t)<=0;)i.pop();i.push(t)}const a=[];for(let t=s.length-1;t>=0;t--){const e=s[t];for(;a.length>=2&&o(a[a.length-2],a[a.length-1],e)<=0;)a.pop();a.push(e)}return i.pop(),a.pop(),i.concat(a)}};class f{static{this._eps=1e-12}static isPolygon(e){return function(e){let r;return"vertices"in e&&Array.isArray(e.vertices)&&(r=e.vertices).length>=3&&r.every(e=>t.Point.isPoint(e))}(e)}static from(...t){return{vertices:Array.from(t)}}static contains(t,e){return l.inPolygon(e,t.vertices,12)}static centroid(t){const e=f.boundingBox(t);return{x:e.x+e.width/2,y:e.y+e.height/2}}static boundingBox(t){return l.boundingBox(t.vertices)}static sides(t){const{vertices:e}=t,r=[];for(let t=1;t<=e.length;t++){const n=e[t%e.length],s=e[t-1];r.push([s,n])}return r}static isConvex(e){const{vertices:r}=e,n=r.length;if(n<=3)return!0;let s=0;for(let e=0;e<r.length;e++){const o=r[(e-1+n)%n],i=r[e],a=r[(e+1)%n],m=t.Angle.angleBetween(i,o,a);if(0!==s){if(s!=Math.sign(m))return!1}else s=Math.sign(m)}return!0}static isSelfIntersecting(e){const{vertices:r}=e;if(r.length<=3)return!1;const n=f.sides(e);for(let e of n)for(let r of n){if(r===e||r[0]===e[1]||e[0]===r[1])continue;const n=l.intersect(r,e);if(!t.NullChecker.isNull(n))return!0}return!1}static isCounterClockwise(e){const{vertices:[r,n,s]}=e;return t.Angle.angleBetween(n,r,s)>0}static expand(r,n){const{vertices:s}=r,o=s.length,i=[];for(let r=0;r<s.length;r++){const a=s[(r-1+o)%o],m=s[r],c=s[(r+1)%o],l=t.Angle.angleBetween(m,a,c),f=-n/Math.sin(Math.abs(l)/2),u=t.Matrix2D.scale(t.Matrix2D.identity,f),h=t.Point.subtract(m,a);e.normalize(h);const y=t.Point.subtract(m,c);e.normalize(y);const x=t.Point.add(h,y);e.normalize(x);const g=t.Matrix2D.multiply(x,u);i.push(t.Point.add(m,{x:g.x.roundoff(),y:g.y.roundoff()}))}return{vertices:i}}static area(t){return l.area(t.vertices)}static intersect(t,e){return l.intersect(t,e)}static convexHull(t){return{vertices:l.convexHull(t.vertices)}}}const u=180/Math.PI,h=1/u;class y{static from(...t){if(3!==t.length)throw new RangeError("Must provide exactly 3 numbers");return{x:t[0],y:t[1],z:t[2]}}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&3===r.length)return y.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Vector3D.`)}static i(){return{x:1,y:0,z:0}}static j(){return{x:0,y:1,z:0}}static k(){return{x:0,y:0,z:1}}static zero(){return{x:0,y:0,z:0}}static subtract(t,e){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static add(...t){var e={x:0,y:0,z:0};for(var r of t)e.x+=r.x,e.y+=r.y,e.z+=r.z;return e}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static scale(t,e,r=e,n=e){return{x:t.x*e,y:t.y*r,z:t.z*n}}static magSqr(t){return t.x*t.x+t.y*t.y+t.z*t.z}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)&&(e.z-t.z).isCloseTo(0)}static mag(t){return Math.sqrt(y.magSqr(t))}static negate(t){return{x:-t.x,y:-t.y,z:-t.z}}static unit(t){const e={x:t.x,y:t.y,z:t.z};return this.normalize(e),e}static normalize(t){const e=y.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";const r=1/e;t.x*=r,t.y*=r,t.z*=r}static angleBetween(t,e){let r;const n=y.unit(t),s=y.unit(e);if(y.dot(n,s)<0){const t={x:-n.x-s.x,y:-n.y-s.y,z:-n.z-s.z},e=y.mag(t);r=Math.PI-2*Math.asin(e/2)}else{const t={x:n.x-s.x,y:n.y-s.y,z:n.z-s.z},e=y.mag(t);r=2*Math.asin(e/2)}return u*r}}class x{static from(t,e,r){return{rho:t.clamp(0,1/0),theta:e.clamp(-180,180),phi:r.clamp(0,360)}}static fromVector(t,e,r){"number"==typeof t&&(t=y.from(t,e,r));const n=y.mag(t);if(n.isCloseTo(0))return x.from(0,0,0);const s=Math.atan2(t.x,t.z),o=Math.acos((t.y/n).clamp(-1,1));return x.from(n,s*u,o*u)}static toVector(t){const{rho:e,theta:r,phi:n}=t,s=n*h,o=r*h,i=Math.sin(s)*e;return{x:i*Math.sin(o),y:Math.cos(s)*e,z:i*Math.cos(o)}}static toRotationMatrix(t){const{theta:e,phi:r}=t,n=h*e,s=Math.sin(n),o=Math.cos(n),i=h*r,a=Math.sin(i),m=Math.cos(i);return p.from(s*m,s*a,o,0,o*m,o*a,-s,0,-a,m,0,0,0,0,0,1)}}class g{static modify(t,e){const{m11:r,m12:n,m13:s,m14:o,m21:i,m22:a,m23:m,m24:c,m31:l,m32:f,m33:u,m34:h,offsetX:y,offsetY:x,offsetZ:g,m44:p}=t,d={m11:r,m12:n,m13:s,m14:o,m21:i,m22:a,m23:m,m24:c,m31:l,m32:f,m33:u,m34:h,offsetX:y,offsetY:x,offsetZ:g,m44:p};return e(d),d}static clone(t){return g.modify(t,t=>{})}static multiply(t,e){return p.isIdentity(t)?e:p.isIdentity(e)?t:p.from(t.m11*e.m11+t.m12*e.m21+t.m13*e.m31+t.m14*e.offsetX,t.m11*e.m12+t.m12*e.m22+t.m13*e.m32+t.m14*e.offsetY,t.m11*e.m13+t.m12*e.m23+t.m13*e.m33+t.m14*e.offsetZ,t.m11*e.m14+t.m12*e.m24+t.m13*e.m34+t.m14*e.m44,t.m21*e.m11+t.m22*e.m21+t.m23*e.m31+t.m24*e.offsetX,t.m21*e.m12+t.m22*e.m22+t.m23*e.m32+t.m24*e.offsetY,t.m21*e.m13+t.m22*e.m23+t.m23*e.m33+t.m24*e.offsetZ,t.m21*e.m14+t.m22*e.m24+t.m23*e.m34+t.m24*e.m44,t.m31*e.m11+t.m32*e.m21+t.m33*e.m31+t.m34*e.offsetX,t.m31*e.m12+t.m32*e.m22+t.m33*e.m32+t.m34*e.offsetY,t.m31*e.m13+t.m32*e.m23+t.m33*e.m33+t.m34*e.offsetZ,t.m31*e.m14+t.m32*e.m24+t.m33*e.m34+t.m34*e.m44,t.offsetX*e.m11+t.offsetY*e.m21+t.offsetZ*e.m31+t.m44*e.offsetX,t.offsetX*e.m12+t.offsetY*e.m22+t.offsetZ*e.m32+t.m44*e.offsetY,t.offsetX*e.m13+t.offsetY*e.m23+t.offsetZ*e.m33+t.m44*e.offsetZ,t.offsetX*e.m14+t.offsetY*e.m24+t.offsetZ*e.m34+t.m44*e.m44)}}class p{static identity(){return{m11:1,m12:0,m13:0,m14:0,m21:0,m22:1,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,offsetX:0,offsetY:0,offsetZ:0,m44:1}}static from(...t){if(16!==t.length)throw new RangeError("Must provide exactly 16 numbers");return{m11:t[0],m12:t[1],m13:t[2],m14:t[3],m21:t[4],m22:t[5],m23:t[6],m24:t[7],m31:t[8],m32:t[9],m33:t[10],m34:t[11],offsetX:t[12],offsetY:t[13],offsetZ:t[14],m44:t[15]}}static transpose(t){return p.from(t.m11,t.m21,t.m31,t.offsetX,t.m12,t.m22,t.m32,t.offsetY,t.m13,t.m23,t.m33,t.offsetZ,t.m14,t.m24,t.m34,t.m44)}static toArray(t){return[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.offsetX,t.offsetY,t.offsetZ,t.m44]}static clone(t,e){return"function"==typeof e?g.modify(t,e):g.clone(t)}static scale(t,e,r,n){return"number"==typeof e?(r??=e,n??=e):(n=e.z,r=e.y,e=e.x),g.modify(t,t=>{t.m11*=e,t.m22*=r,t.m33*=n})}static translate(t,e){return g.modify(t,t=>{t.offsetX+=e.x,t.offsetY+=e.y,t.offsetZ+=e.z})}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&16===r.length)return p.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Matrix3D.`)}static isIdentity(t){return 1==t.m11&&0==t.m12&&0==t.m13&&0==t.m14&&0==t.m21&&1==t.m22&&0==t.m23&&0==t.m24&&0==t.m31&&0==t.m32&&1==t.m33&&0==t.m34&&0==t.offsetX&&0==t.offsetY&&0==t.offsetZ&&1==t.m44}static isAffine(t){return 0==t.m14&&0==t.m24&&0==t.m34&&1==t.m44}static determinant(t){if(p.isIdentity(t))return 1;if(p.isAffine(t))return t.m11*(t.m22*t.m33-t.m32*t.m23)-t.m12*(t.m21*t.m33-t.m31*t.m23)+t.m13*(t.m21*t.m32-t.m31*t.m22);{const e=t.m13*t.m24-t.m23*t.m14,r=t.m13*t.m34-t.m33*t.m14,n=t.m13*t.m44-t.offsetZ*t.m14,s=t.m23*t.m34-t.m33*t.m24,o=t.m23*t.m44-t.offsetZ*t.m24,i=t.m33*t.m44-t.offsetZ*t.m34,a=t.m22*r-t.m32*e-t.m12*s,m=t.m12*o-t.m22*n+t.offsetY*e,c=t.m32*n-t.offsetY*r-t.m12*i,l=t.m22*i-t.m32*o+t.offsetY*s;return t.offsetX*a+t.m31*m+t.m21*c+t.m11*l}}static multiply(...t){if(0===t.length)throw new ReferenceError("Matrix not provided.");const e=Array.from(t);let r=e[0];for(let t=1;t<e.length;t++)r=g.multiply(r,e[t]);return r}static invert(t){if(p.isAffine(t)){const e=p.determinant(t);if(0==e)return null;const r=t.m12*t.m23-t.m22*t.m13,n=t.m32*t.m13-t.m12*t.m33,s=t.m22*t.m33-t.m32*t.m23,o=t.m21*t.m13-t.m11*t.m23,i=t.m11*t.m33-t.m31*t.m13,a=t.m31*t.m23-t.m21*t.m33,m=t.m11*t.m22-t.m21*t.m12,c=t.m11*t.m32-t.m31*t.m12,l=t.m11*t.offsetY-t.offsetX*t.m12,f=t.m21*t.m32-t.m31*t.m22,u=t.m21*t.offsetY-t.offsetX*t.m22,h=t.m31*t.offsetY-t.offsetX*t.m32,y=t.m23*l-t.offsetZ*m-t.m13*u,x=t.m13*h-t.m33*l+t.offsetZ*c,g=t.m33*u-t.offsetZ*f-t.m23*h,d=m,M=-c,v=f,b=1/e;return p.from(s*b,n*b,r*b,0,a*b,i*b,o*b,0,v*b,M*b,d*b,0,g*b,x*b,y*b,1)}{const e=p.determinant(t);if(0==e)return null;const r=t.m33*t.m44-t.m34*t.offsetZ,n=t.m32*t.m44-t.m34*t.offsetY,s=t.m31*t.m44-t.m34*t.offsetX,o=t.m32*t.offsetZ-t.m33*t.offsetY,i=t.m31*t.offsetZ-t.m33*t.offsetX,a=t.m31*t.offsetY-t.m32*t.offsetX,m=t.m33*t.m44-t.m34*t.offsetZ,c=t.m32*t.m44-t.m34*t.offsetY,l=t.m31*t.m44-t.m34*t.offsetX,f=t.m32*t.offsetZ-t.m33*t.offsetY,u=t.m31*t.offsetZ-t.m33*t.offsetX,h=t.m31*t.offsetY-t.m32*t.offsetX,y=t.m23*t.m44-t.m24*t.offsetZ,x=t.m22*t.m44-t.m24*t.offsetY,g=t.m21*t.m44-t.m24*t.offsetX,d=t.m22*t.offsetZ-t.m23*t.offsetY,M=t.m21*t.offsetZ-t.m23*t.offsetX,v=t.m21*t.offsetY-t.m22*t.offsetX,b=t.m23*t.m34-t.m24*t.m33,w=t.m22*t.m34-t.m24*t.m32,z=t.m21*t.m34-t.m24*t.m31,A=t.m22*t.m33-t.m23*t.m32,N=t.m21*t.m33-t.m23*t.m31,C=t.m21*t.m32-t.m22*t.m31,_=t.m22*r-t.m23*n+t.m24*o,q=-(t.m21*r-t.m23*s+t.m24*i),X=t.m21*n-t.m22*s+t.m24*a,P=-(t.m21*o-t.m22*i+t.m23*a),Y=-(t.m12*m-t.m13*c+t.m14*f),Z=t.m11*m-t.m13*l+t.m14*u,E=-(t.m11*c-t.m12*l+t.m14*h),S=t.m11*f-t.m12*u+t.m13*h,I=t.m12*y-t.m13*x+t.m14*d,R=-(t.m11*y-t.m13*g+t.m14*M),T=t.m11*x-t.m12*g+t.m14*v,j=-(t.m11*d-t.m12*M+t.m13*v),D=-(t.m12*b-t.m13*w+t.m14*A),B=t.m11*b-t.m13*z+t.m14*N,L=-(t.m11*w-t.m12*z+t.m14*C),O=t.m11*A-t.m12*N+t.m13*C,V=1/e;return p.from(_*V,Y*V,I*V,D*V,q*V,Z*V,R*V,B*V,X*V,E*V,T*V,L*V,P*V,S*V,j*V,O*V)}}static transform(t,e){var r={x:t.x,y:t.y,z:t.z};if(!p.isIdentity(e)){var n=r.x,s=r.y,o=r.z;if(r.x=n*e.m11+s*e.m21+o*e.m31+e.offsetX,r.y=n*e.m12+s*e.m22+o*e.m32+e.offsetY,r.z=n*e.m13+s*e.m23+o*e.m33+e.offsetZ,!p.isAffine(e)){var i=n*e.m14+s*e.m24+o*e.m34+e.m44;0!=i&&(r.x/=i,r.y/=i,r.z/=i)}}return r}}class d{static identity(){return d.from(0,0,0,1)}static from(...t){if(4!==t.length)throw new RangeError("Must provide exactly 4 numbers");return{x:t[0],y:t[1],z:t[2],w:t[3]}}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&4===r.length)return d.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Quaternion.`)}static fromVectors(t,e){y.normalize(t),y.normalize(e);const r=(t,e,r,n)=>{const s=d.from(t,e,r,n);return d.normalize(s),s};let n=y.dot(t,e)+1;return n.isCloseTo(0)?Math.abs(t.x)>Math.abs(t.z)?r(-t.y,t.x,0,0):r(0,-t.z,t.y,0):r(t.y*e.z-t.z*e.y,t.z*e.x-t.x*e.z,t.x*e.y-t.y*e.x,n)}static normalize(t){const e=d.mag(t);if(e.isCloseTo(0))t.x=t.y=t.z=0,t.w=1;else{const r=1/e;t.x*=r,t.y*=r,t.z*=r,t.w*=r}}static unit(t){const e=d.from(t.x,t.y,t.z,t.w);return d.normalize(e),e}static fromAxisAngle(t,e){var r=h*(e%=360),n=y.mag(t);if(0==n)throw new RangeError("Invalid argument");var s=Math.sin(.5*r)/n,o=t.x*s,i=t.y*s,a=t.z*s;return d.from(o,i,a,Math.cos(.5*r))}static fromRotationMatrix(t){const e=t.m11+t.m22+t.m33+t.m44;if(e>0){const r=.5/Math.sqrt(e),n=.25/r,s=(t.m23-t.m32)*r,o=(t.m31-t.m13)*r,i=(t.m12-t.m21)*r;return d.from(s,o,i,n)}if(t.m11>t.m22&&t.m11>t.m22){const e=.5/Math.sqrt(t.m44+t.m11-t.m22-t.m33),r=(t.m23-t.m32)*e,n=.25/e,s=(t.m12+t.m21)*e,o=(t.m31+t.m13)*e;return d.from(n,s,o,r)}if(t.m22>t.m33){const e=.5/Math.sqrt(t.m44+t.m22-t.m11-t.m33),r=(t.m23+t.m32)*e,n=.25/e,s=(t.m12+t.m21)*e,o=(t.m31-t.m13)*e;return d.from(s,n,r,o)}{const e=.5/Math.sqrt(t.m44+t.m33-t.m11-t.m22),r=(t.m23+t.m32)*e,n=.25/e,s=(t.m12-t.m21)*e,o=(t.m31-t.m13)*e;return d.from(o,r,n,s)}}static conjugate(t){return d.from(-t.x,-t.y,-t.z,t.w)}static mag(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w)}static norm(t){return t.x*t.x+t.y*t.y+t.z*t.z}static axis(t){return 0==t.x&&0==t.y&&0==t.z?y.j():y.unit(t)}static transform(t,e){d.normalize(e);const r=y.cross(e,t),n=y.scale(r,2),s=y.cross(e,n);return{x:t.x+e.w*n.x+s.x,y:t.y+e.w*n.y+s.y,z:t.z+e.w*n.z+s.z}}static angle(t){let e=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),r=t.w;if(e>Number.MAX_VALUE){const n=Math.max(Math.abs(t.x),Math.max(Math.abs(t.y),Math.abs(t.z))),s=t.x/n,o=t.y/n,i=t.z/n;e=Math.sqrt(s*s+o*o+i*i),r/=n}return 114.59155902616465*Math.atan2(e,r)}static toRotationMatrix(t){var e=p.identity(),r=t.x,n=t.y,s=t.z,o=t.w;return e.m11=1-2*n*n-2*s*s,e.m12=2*r*n+2*o*s,e.m13=2*r*s-2*o*n,e.m21=2*r*n-2*o*s,e.m22=1-2*r*r-2*s*s,e.m23=2*n*s+2*o*r,e.m31=2*o*n+2*r*s,e.m32=2*n*s-2*o*r,e.m33=1-2*r*r-2*n*n,e}static invert(t){const e=d.unit(t);return d.conjugate(e)}static multiply(t,e){return d.from(t.w*e.x+t.x+e.w+t.y*e.z-t.z*e.y,t.w*e.y-t.x*e.z+t.y*e.w+t.z*e.x,t.w*e.z+t.x*e.y-t.y*e.x+t.z*e.w,t.w*e.w-t.x*e.x-t.y*e.y-t.z*e.z)}static dot(t,e){return d.multiply(t,d.conjugate(e)).w}}var M,v=Object.freeze({__proto__:null,Matrix3D:p,Quaternion:d,Spherical:x,Vector:e,Vector3D:y}),b=Object.freeze({__proto__:null,LinearAlgebra:v,Polygon:f,Utils:l,Utils3D:class{static intersect(t,e){const[r,n]=t,s=y.subtract(r,n),[o,i,a]=e,m=y.subtract(o,i),c=y.subtract(o,a),l=y.cross(s,c),f=y.dot(m,l);if(f.isCloseTo(0))return null;const u=1/f,h=y.subtract(r,o),x=u*y.dot(h,l);if(x<0||x>1)return null;const g=y.cross(h,m),p=u*y.dot(s,g);if(p<0||x+p>1)return null;const d=u*y.dot(c,g);return d<0||d.isCloseTo(0)?null:y.add(r,y.scale(s,d))}}});function w(t){return"number"==typeof t&&(t={real:t,img:0}),t}function z(t,e){const r={};return Object.defineProperty(r,"real",{value:t,writable:!1}),Object.defineProperty(r,"img",{value:e,writable:!1}),r}function A(){return M||(M=z(Number.NaN,Number.NaN))}class N{static build(t,e){return this.isComplex(t)?t:(e??=0,"number"!=typeof t||"number"!=typeof e?A():z(t,e||0))}static add(t,e){const r=w(t),n=w(e);return z(r.real+n.real,r.img+n.img)}static subtract(t,e){const r=w(t),n=w(e);return z(r.real-n.real,r.img-n.img)}static multiply(t,e){const r=w(t),n=w(e);return z(r.real*n.real-r.img*n.img,r.real*n.img+r.img*n.real)}static divide(t,e){const r=w(t),n=w(e),s=this.absSquare(n).roundoff();if(0===s)return A();const o=1/s;return z(o*(r.real*n.real+r.img*n.img),o*(r.img*n.real-r.real*n.img))}static absSquare(t){const e=w(t);return Math.pow(e.real,2)+Math.pow(e.img,2)}static modulus(t){return Math.sqrt(this.absSquare(t))}static isComplex(t){return null!=t&&"object"==typeof t&&"real"in t&&"img"in t&&"number"==typeof t.real&&"number"==typeof t.img}static conjugate(t){return z((t=w(t)).real,0==Math.abs(t.img)?0:-t.img)}static equals(t,e){const r=this.build(t),n=this.build(e);return!(!this.isComplex(t)||!this.isComplex(e))&&(r.real===n.real&&r.img===n.img)}static get NaC(){return A()}}const C={};function _(t,e){const r=C[e]=C[e]||{};return r[t]=r[t]||function(t,e){const r=2*Math.PI*t/e;return N.build(Math.cos(r),Math.sin(r))}(t,e)}function q(t){const e=[],r=t.length;if(1===r)return[N.build(t[0])];const n=q(t.filter((t,e)=>e%2==0)),s=q(t.filter((t,e)=>e%2==1));for(var o=0;o<r/2;o++){const t=n[o],i=N.multiply(_(o,r),s[o]);e[o]=N.add(t,i),e[o+r/2]=N.subtract(t,i)}return e}const X=Math.sqrt(Math.PI);class P{constructor(t,e){this.mean=t,this.stdev=Math.abs(e),this.variance=Math.pow(e,2)}static get normal(){return Y}weight(t){return Math.exp(-.5*Math.pow(this._z(t),2))}probabilityDensity(t){const e=this.stdev*Math.SQRT2*X;return this.weight(t)/e}_z(t){return(t-this.mean)/this.stdev}probability(t){return.5*function(t){const e=Math.abs(t),r=1/(1+.5*e),n=r*Math.exp(-e*e-1.26551223+r*(1.00002368+r*(.37409196+r*(.09678418+r*(r*(.27886807+r*(r*(1.48851587+r*(.17087277*r-.82215223))-1.13520398))-.18628806)))));return t>=0?n:2-n}(-this._z(t)/Math.SQRT2)}}const Y=new P(0,1);class Z{constructor(t){this.#t=t}#t;#e=null;_prepareBarycentric(){if(this.#e)return;const t=this.#t||[],e=t.length;if(0===e)return void(this.#e=[]);const r=new Array(e),n=new Array(e);for(let s=0;s<e;s++){let o=0,i=1;const a=t[s].x;for(let r=0;r<e;r++){if(r===s)continue;const e=a-t[r].x;if(0===e)throw new Error("Invalid function provided.");e<0&&(i=-i),o+=Math.log(Math.abs(e))}r[s]=-o,n[s]=i}let s=r[0];for(let t=1;t<e;t++)r[t]>s&&(s=r[t]);const o=new Array(e);for(let t=0;t<e;t++){const e=Math.exp(r[t]-s);o[t]=n[t]*e}this.#e=o}_computeBarycentric(t){const e=this.#t||[];this.#e||this._prepareBarycentric();const r=this.#e||[];let n=0,s=0;for(let o=0;o<e.length;o++){const i=e[o].x;if(t===i)return e[o].y;const a=r[o]/(t-i);n+=a*e[o].y,s+=a}return n/s}interpolate(t){return this._computeBarycentric(t)}static create(...t){const e=(arguments.length>0&&Array.isArray(arguments[0])?arguments[0]:Array.from(t)).map((t,e)=>"number"==typeof t?{x:e,y:t}:t);return new Z(e)}}const E={create:Z.create};class S{constructor(t){if(!t||t.length<2)throw new Error("Need at least 2 points");const e=t.slice().sort((t,e)=>t.x-e.x);this.xs=e.map(t=>t.x),this.ys=e.map(t=>t.y),this.ms=this.computeDerivatives()}computeDerivatives(){const t=this.xs.length,e=new Array(t-1),r=new Array(t-1);for(let n=0;n<t-1;n++)e[n]=this.xs[n+1]-this.xs[n],r[n]=(this.ys[n+1]-this.ys[n])/e[n];const n=new Array(t).fill(0);n[0]=r[0],n[t-1]=r[t-2];for(let s=1;s<t-1;s++){const t=r[s-1],o=r[s];if(0===t||0===o||t*o<=0)n[s]=0;else{const r=2*e[s]+e[s-1],i=e[s]+2*e[s-1];n[s]=(r+i)/(r/t+i/o)}}for(let e=0;e<t-1;e++)if(0===r[e])n[e]=0,n[e+1]=0;else{const t=n[e]/r[e],s=n[e+1]/r[e],o=t*t+s*s;if(o>9){const i=3/Math.sqrt(o);n[e]=i*t*r[e],n[e+1]=i*s*r[e]}}return n}interpolate(t){const e=this.xs,r=this.ys,n=this.ms,s=e.length;if(t<=e[0]){const s=n[0];return r[0]+s*(t-e[0])}if(t>=e[s-1]){const o=n[s-1];return r[s-1]+o*(t-e[s-1])}let o=0,i=s-1;for(;i-o>1;){const r=o+i>>1;e[r]<=t?o=r:i=r}const a=e[o+1]-e[o],m=(t-e[o])/a,c=m*m,l=c*m,f=l-2*c+m,u=-2*l+3*c,h=l-c;return(2*l-3*c+1)*r[o]+f*(n[o]*a)+u*r[o+1]+h*(n[o+1]*a)}static create(...t){const e=(arguments.length>0&&Array.isArray(arguments[0])?arguments[0]:Array.from(t)).map((t,e)=>"number"==typeof t?{x:e,y:t}:t);return new S(e)}}class I{constructor(t){if(!t||0===t.length)throw new Error("Need at least 1 point");const e=t.slice().sort((t,e)=>t.x-e.x);this.xs=e.map(t=>t.x);const r=e.length,n=e.map(t=>t.y);for(let t=1;t<r;t++)for(let e=r-1;e>=t;e--){const r=this.xs[e]-this.xs[e-t];if(0===r)throw new Error("Invalid function provided.");n[e]=(n[e]-n[e-1])/r}this.coeffs=n}interpolate(t){const e=this.xs,r=this.coeffs,n=r.length;if(0===n)return NaN;let s=r[n-1];for(let o=n-2;o>=0;o--)s=s*(t-e[o])+r[o];return s}static create(...t){const e=(arguments.length>0&&Array.isArray(arguments[0])?arguments[0]:Array.from(t)).map((t,e)=>"number"==typeof t?{x:e,y:t}:t);return new I(e)}}const R=(t,e)=>t;function T(t,e=R){return t.reduce((t,r,n)=>t+e(r,n),0)}function j(t,e=R){return T(t,e)/t.length}function D(t,e=R,r=!1){const n=j(t,e);return t.reduce((t,e)=>Math.pow(e-n,2)+t,0)/(t.length-(r?1:0))}function B(t,e=R,r=!1){const n=D(t,e,r);return Math.sqrt(n)}function L(t,e){return(r,n,s,o)=>{let i=r,a=n,m=t(i,a),c=e(i,a),l=s(m),f=s(c);for(;a-i>o;)l<f?(a=c,c=m,f=l,m=t(i,a),l=s(m)):(i=m,m=c,l=f,c=e(i,a),f=s(c));return.5*(m+c)}}const O={linear:(t=2)=>function(t){if(t<=1)throw new RangeError("segments must be a number grater than 1.");return(e,r,n,s=.001)=>L((e,r)=>e+(r-e)/t,(e,r)=>r-(r-e)/t)(e,r,n,s)}(t),goldenRatio:(t,e,r,n=.001)=>L((t,e)=>e-(e-t)/1.618,(t,e)=>t+(e-t)/1.618)(t,e,r,n),gaussian:(t,e,r,n=.001)=>{var s=null,o=null;const i=(t,e)=>(o??=e-t,s??=o/Math.sqrt(12),s*(e-t)/o);return L((t,e)=>Math.max(t,(e+t)/2-i(t,e)),(t,e)=>Math.min(e,(e+t)/2+i(t,e)))(t,e,r,n)}};var V=Object.freeze({__proto__:null,Fourier:class{static transform(t,e=!0){return(r=(t=t||[]).length)>0&&!(r&r-1)?this.fft(t,e):this.dft(t,e);var r}static invert(t,e=!0){return this.idft(t||[],e)}static dft(t,e=!0){const r=(t||[])?.length,n=e?1/Math.sqrt(r):1,s=[];for(let e=0;e<r;e++){s.push({real:0,img:0});for(let o=0;o<r;o++){const i=_(e*o,r),a=N.multiply(t[o],i),m=N.multiply(a,n);s[e]=N.add(s[e],m)}}return s}static idft(t,e=!0){const r=t.map(t=>N.build(t.img,t.real));return this.transform(r,e).map(t=>N.build(t.img,t.real))}static fft(t,e=!0){const r=q(t);if(!e)return r;const n=1/Math.sqrt(t.length);return r.map(t=>N.multiply(t,n))}},Gaussian:P,Lagrange:Z,Lagrangian:E,Newton:I,Pchip:S,SearchFunctions:O,Utils:class{static sum(t,e){return T(t,e)}static mean(t,e){return j(t,e)}static median(t,e){return function(t,e=R){const r=t.slice(0),n=r.length;r.sort((t,r)=>e(t)-e(r));const s=Math.ceil(r.length/2)-1;return n%2==1?r[s]:.5*(r[s+1]+r[s])}(t,e)}static mode(t,e){return function(t,e=R){const r=Object.groupBy(t,e);let n,s=0;for(let t in r){const e=r[t].length;e>s&&(n=parseInt(t),s=e)}return n}(t,e)}static var(t,e){return D(t,e,!0)}static varp(t,e){return D(t,e,!1)}static stdevp(t,e){return B(t,e,!1)}static stdev(t,e){return B(t,e,!0)}static correlation(t,e,r,n){return function(t,e,r=R,n=R){const s=Array.isArray(e);if(s&&e.length!==t.length)throw new Error("Sets must be of the same length.");const o=t.length,i=t,a=s?e:t,m=s?r:e,c=s?n:r,l=j(i,m),f=j(a,c);let u=0,h=0,y=0;for(let t=0;t<o;t++){const e=i[t],r=a[t],n=m(e,t)-l,s=c(r,t)-f;u+=n*s,h+=n*n,y+=s*s}return u/Math.sqrt(h*y)}(t,e,r,n)}static linearRegression(t,e,r,n){return function(t,e,r=R,n=R){const s=Array.isArray(e);if(s&&e.length!==t.length)throw new Error("Sets must be of the same length.");const o=t,i=s?e:t,a=s?r:e,m=a??(t=>t.x),c=(s?n:a)??(t=>t.y),l=t.length;let f=0,u=0,h=0,y=0;for(let t=0;t<l;t++){const e=o[t],r=i[t],n=m(e,t),s=c(r,t);f+=n*s,u+=n,h+=s,y+=n*n}const x=(l*f-u*h)/(l*y-Math.pow(u,2));return[x,(h-x*u)/l]}(t,e,r,n)}static gaussian(t,e){return new P(t,e)}}});const U="0123456789abcdefghijklmnopqrstuvwxyz",k="Radix out of range: possible values go between positive 1 exclusive and 36 inclusive";class F{static lcd(...e){if(t.NullChecker.isNullOrEmpty(e)||e.length<=1)throw"Insufficient set of numbers.";function r(t,e){return e?r(e,t%e):0===e?t:NaN}function n(t,e){return t*e/r(t,e)}let s=Math.round(e[0]);for(let t=1;t<e.length;t++)s=n(s,Math.round(e[t]));return s}static gcd(t,e){return t=Math.round(t),e=Math.round(e),0===t?e:F.gcd(e%t,t)}static rebaseInt(e,r,n){return t.Numbers.rebase(e,r,n)}static rebaseFloat(t,e,r,n=12){const s=F.rebaseFloat10ToN,o=F.rebaseFloatNTo10;if(10===e){const e=parseFloat(t.toString());return r%1==0?F.rebaseFloat10ToNIntBase(e,r,n):s(e,r,n)}if(10===r)return o(t.toString(),e,n);return s(o(t.toString(),e,n+1),r,n)}static rebaseFloatNTo10(t,e,r=12){const n=U;if(e<=1||e>n.length)throw new Error(k);const s=(t??"0").toString().toLowerCase(),o=Number.NaN;if("0"===s)return 0;const i=/^([-+]?) *([\da-z]+)?(.[\da-z]+)?$/.exec(s);if(i.length<2)return o;const a="-"===i[1]?-1:1,m=i[2]||"0",c=i[3]||".0";let l=0,f=0;for(let t of m+c.substr(1)){const r=n.indexOf(t);if(-1===r||r>=e)return o;l+=r*Math.pow(e,m.length-f-1),f++}return a*l}static rebaseFloat10ToNIntBase(t,e,r=12){const n=U;if(e<=1||e>36)throw new Error(k);const s=e;let o=Math.abs(t??0);if(0===o||Number.isNaN(o))return t.toString();let i=(o%1).roundoff(),a="";for(;;){let t=o/s,e=Math.floor(t),r=(o-e*s).roundoff(),i=Math.floor(r);if(a=i>=36?`[${i}]`+a:n[i]+a,e<=0)break;o=e}if(a=a.replace(/^0+/,""),a||="0",0===i)return a;let m="";do{o=(i*s).roundoff();const t=Math.floor(o),e=(o-t).roundoff();t>=36?m=`[${t}]`:m+=n[t],i=e}while(!i.isCloseTo(0)&&m.length<r);return/^0*$/.test(m)?a:(Math.sign(t)<0?"-":"")+a+"."+m.replace(/0+$/,"")}static rebaseFloat10ToN(e,r,n=12){const s=U;if(r<=1||r>s.length)throw new Error(k);const o=r;let i=Math.abs(e??0);if(0===i||Number.isNaN(i))return e.toString();let a=Math.sign(e)<0?"-":"",m=[],c=[];for(let t=0;t<20;t++)m.push("0"),c.push("0");const l=o%1==0?o:Math.ceil(o);function f(t,e,r){const n=t?m:c,o=n[e]=n[e]||"0",i=s.indexOf(o)+r,a=i%l,u=Math.floor(i/l);return n[e]=s[a],u>0&&(t?f(t,e+1,u):0===e?f(!0,0,u):f(!1,e-1,u)),u}let u=0;for(;;){const e=Math.floor(t.Numbers.log(i,o)),r=e>=0;if(f(r,r?e:Math.abs(1+e),1),i=(i-Math.pow(o,e).roundoff()).roundoff(),r||u++,0===i||u>=100){const t=a+(m.reverse().map(t=>t||"0").join("").replace(/^0+/,"")||"0"),e=c.map(t=>t||"0").join("").substr(0,n).replace(/0+$/,"");return/^0*$/.test(e)?t:t+"."+e}}}}var $=Object.freeze({__proto__:null,Utils:F}),Q=Object.freeze({__proto__:null,Complex:N,DataAnalysis:V,NumberTheory:$}),H=Object.freeze({__proto__:null,Geometry:b,Mathematics:Q});t.DeepMerger.merge(H)}(Pacem);
|
|
2
7
|
//# sourceMappingURL=pacem-numerical.min.js.map
|
|
@@ -1 +1,6 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pacem/pacem-numerical v1.0.0-amaldi (https://js.pacem.it)
|
|
3
|
+
* Pacem (https://pacem.it)
|
|
4
|
+
* Licensed under Apache-2.0
|
|
5
|
+
*/
|
|
1
6
|
var Ht=Object.defineProperty;var nt=(o,t)=>{for(var e in t)Ht(o,e,{get:t[e],enumerable:!0})};var jt={};nt(jt,{LinearAlgebra:()=>zt,Polygon:()=>gt,Utils:()=>R,Utils3D:()=>At});import{Point as rt,Rect as xt,NullChecker as st}from"@pacem/pacem-foundation";import{Point as Qt}from"@pacem/pacem-foundation";var T=class o{static unit(t){let e={x:t.x,y:t.y};return this.normalize(e),e}static magSqr(t){return t.x*t.x+t.y*t.y}static mag(t){return Math.sqrt(o.magSqr(t))}static normalize(t){let e=o.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";let n=1/e;t.x*=n,t.y*=n}static from(t,e){return Qt.subtract(t,e)}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)}};var _=class{constructor(t,e,n=-1){this.x=t,this.y=e,this.index=n}equals(t){return this.x===t.x&&this.y===t.y}};function Jt(o,t,e){let n=o.x,s=o.y,r=t.x,c=t.y,i=e.x,a=e.y,u=2*(n*(c-a)+r*(a-s)+i*(s-c));if(Math.abs(u)<1e-12)return{c:{x:0,y:0},r:1/0};let f=((n*n+s*s)*(c-a)+(r*r+c*c)*(a-s)+(i*i+a*a)*(s-c))/u,l=((n*n+s*s)*(i-r)+(r*r+c*c)*(n-i)+(i*i+a*a)*(r-n))/u,h=Math.hypot(f-n,l-s);return{c:{x:f,y:l},r:h}}var it=class{constructor(t,e,n){this.v0=t,this.v1=e,this.v2=n,this.circumCirc=Jt(t,e,n)}inCircumcircle(t){let e=this.circumCirc.c.x-t.x,n=this.circumCirc.c.y-t.y;return Math.hypot(e,n)<=this.circumCirc.r+1e-9}};function Kt(o){let t=1/0,e=1/0,n=-1/0,s=-1/0;for(let f of o)t=Math.min(t,f.x),e=Math.min(e,f.y),n=Math.max(n,f.x),s=Math.max(s,f.y);let r=(n-t)*10,c=(s-e)*10,i=new _(t-r,e-c*3),a=new _(t-r,s+c),u=new _(n+r*3,s+c);return new it(i,a,u)}function qt(o){let t=[];for(let e=0;e<o.length;++e){let n=!0;for(let s=0;s<o.length;++s)if(e!==s){let r=o[e],c=o[s];if(r.v0.equals(c.v0)&&r.v1.equals(c.v1)||r.v0.equals(c.v1)&&r.v1.equals(c.v0)){n=!1;break}}n&&t.push(o[e])}return t}function _t(o,t){let e=[];t=t.filter(s=>s.inCircumcircle(o)?(e.push({v0:s.v0,v1:s.v1}),e.push({v0:s.v1,v1:s.v2}),e.push({v0:s.v2,v1:s.v0}),!1):!0);let n=qt(e);for(let s of n)t.push(new it(s.v0,s.v1,o));return t}function te(o){if(o.length<3)return[];let t=Kt(o),e=[t];for(let n of o)e=_t(n,e);return e=e.filter(n=>!(n.v0===t.v0||n.v0===t.v1||n.v0===t.v2||n.v1===t.v0||n.v1===t.v1||n.v1===t.v2||n.v2===t.v0||n.v2===t.v1||n.v2===t.v2)),e}function ee(o){if(o.length<3)return[];let t=o.map((s,r)=>new _(s.x,s.y,r)),e=te(t),n=[];for(let s of e)n.push(s.v0.index,s.v1.index,s.v2.index);return n}var at=class{static triangulate(t){return ee(t)}};var ne=180/Math.PI,Zt=2*Math.PI,Q=12;function ut(o){return rt.isPoint(o)}function se(o){return o!=null&&Array.isArray(o)&&o.length===2&&ut(o[0])&&ut(o[1])}var R=class o{static slopeRad(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}static slopeRad2(t,e){return(Zt+o.slopeRad(t,e))%Zt}static slopeDeg(t,e){return o.slopeRad(t,e)*ne}static slopeDeg2(t,e){return(360+o.slopeDeg(t,e))%360}static intersect(t,e,...n){return Array.isArray(t)&&Array.isArray(e)?o._intersectSegments(t,e,!0):xt.isRect(t)?o._intersectRects(...arguments):"vertices"in t?o._mergePolygons(t,e,"intersect")?.polygons??null:null}static boundingBox(t){let e=Number.MAX_VALUE,n=Number.MAX_VALUE,s=-Number.MAX_VALUE,r=-Number.MAX_VALUE,c=t.length;for(let i of t)e=Math.min(e,i.x),n=Math.min(n,i.y),s=Math.max(s,i.x),r=Math.max(r,i.y);return{x:e,y:n,width:s-e,height:r-n}}static combinePolygons(t,e,n){return o._mergePolygons(t,e,n)}static _mergePolygons(t,e,n){if(st.isNullOrEmpty(t?.vertices)||st.isNullOrEmpty(e?.vertices))return null;let s=t.vertices.filter(y=>o.inPolygon(y,e.vertices));if(t.vertices.length==s.length)return{polygons:n==="intersect"?[t]:[e]};let r=e.vertices.filter(y=>o.inPolygon(y,t.vertices));if(e.vertices.length===r.length)return{polygons:n==="intersect"?[e]:[t]};let c=o.boundingBox(t.vertices),i=o.boundingBox(e.vertices),a=o.intersect(c,i);if(n!=="union"&&(!xt.isRect(a)||!(a.width>0)||!(a.height>0)))return null;let{vertices:u}=t,{vertices:f}=e;if(u.length<3||f.length<3)return null;let l=(y,w,b)=>[y,b[(w+1)%b.length]],h=(y,w)=>y.x===w.x?y.y-w.y:y.x-w.x,m=u.map(l),x=f.map(l),d=u.concat(f),g=new Map,C=y=>{if(!g.has(y)){let w=[];g.set(y,w)}return g.get(y)},z=!1;for(let y of m){let w=C(y);for(let b of x){let v=C(b),B=o.intersect(y,b);st.isNull(B)||(z=!0,d.push(B),w.push(B),v.push(B))}}if(s.length===0&&r.length===0&&!z)return n==="union"?{polygons:[t,e]}:null;let A=[];for(let y of m.concat(x)){let w=C(y);if(st.isNullOrEmpty(w))A.push(y);else{let b=y.concat(w).sort(h);for(let v=0;v<b.length-1;v++)A.push([b[v],b[v+1]])}}var Y=!1,X;do{d.sort(h),d.filter((b,v,B)=>v===0||!o.areClose(b,B[v-1])),X=o.mesh(d);let{vertices:y,triangleIndices:w}=X;Y=!1;for(let b=0;b<w.length;b+=3){let v=w[b],B=w[b+1],k=w[b+2],F=y[v],G=y[B],L=y[k],$=[[F,G],[G,L],[L,F]];for(let H of A)for(let E of $){let yt=o.areClose(E[0],H[0])||o.areClose(E[1],H[1])||o.areClose(E[0],H[1])||o.areClose(E[1],H[0])?null:o.intersect(E,H);!st.isNull(yt)&&d.findIndex(Gt=>o.areClose(Gt,yt,4))===-1&&(Y=!0,d.push(yt))}}}while(Y);let{vertices:M,triangleIndices:p}=X,j=[];for(let y=0;y<p.length;y+=3){let w=y,b=y+1,v=y+2,B=M[p[w]],k=M[p[b]],F=M[p[v]],G={x:(B.x+k.x+F.x)/3,y:(B.y+k.y+F.y)/3},L=o.inPolygon(G,u),$=o.inPolygon(G,f);(L&&$&&n==="intersect"||(L||$)&&n==="union"||(L&&!$||!L&&$)&&n==="difference")&&j.push([B,k,F])}let V=j.flatMap(([y,w,b])=>[[y,w],[w,b],[b,y]]),D=[];for(let y=0;y<V.length;y++){let w=V[y];if(y==0){D.push(w);continue}let b=D.findIndex(v=>o.areClose(v[0],w[0])&&o.areClose(v[1],w[1])||o.areClose(v[0],w[1])&&o.areClose(v[1],w[0]));b===-1?D.push(w):D.splice(b,1)}if(D.length<3)return null;let O=[],K=y=>{let{length:w}=y,b=o.areClose(y[0],y[w-1]),v=y.slice(0,b?w-1:w);return v.length>3&&o.inSegment(v[0],[v[1],v[v.length-1]])&&v.shift(),v},[et,q]=D.shift(),I=[et,q];for(;D.length>1;){let y=I[I.length-1],w=D.findIndex(b=>o.areClose(b[0],y)||o.areClose(b[1],y));if(w===-1){O.push({vertices:K(I.splice(0))});let[b,v]=D.shift();I.push(b,v)}else{let[b]=D.splice(w,1),v=o.areClose(b[0],y)?b[1]:o.areClose(b[1],y)?b[0]:null;I.length>1&&o.inSegment(I[I.length-1],[I[I.length-2],v])?I.splice(I.length-1,1,v):I.push(v)}}return O.push({vertices:K(I)}),{polygons:O,mesh:X,triangles:j.map(y=>({vertices:y}))}}static mesh(t,...e){let n=[].concat(t).concat(e),s=at.triangulate(n);return{vertices:n,triangleIndices:s}}static intersectLines(t,e,n,s){let r,c;if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&typeof t[0]=="number"&&typeof e[0]=="number"&&typeof t[1]=="number"&&typeof e[1]=="number"&&(n=e[0],s=e[1],e=t[1],t=t[0]),typeof t=="number"&&typeof e=="number"){let i=t,a=e;r=[{x:0,y:a},{x:1,y:i+a}],c=[{x:0,y:s},{x:1,y:n+s}]}else r=t,c=e;return o._intersectSegments(r,c,!1)}static cramer(t,e){Array.isArray(t)&&(t={a:t[0],b:t[1],c:t[2]}),Array.isArray(e)&&(e={a:e[0],b:e[1],c:e[2]});let n=(t.b*e.c-t.c*e.b)/(t.b*e.a-t.a*e.b),s=(t.c*e.a-t.a*e.c)/(t.b*e.a-t.a*e.b);return{x:-n.roundoff(),y:-s.roundoff()}}static mq(t,e){let n;if(ut(t)?n=t:(n=t[0],e=t[1]),n.x===e.x)return[Number.NaN,Number.NaN];let s=(e.y-n.y)/(e.x-n.x),r=n.y-s*n.x;return[s,r]}static _intersectSegments(t,e,n){let s=t[0],r=t[1],c=e[0],i=e[1],a=Math.min(s.x,r.x),u=Math.min(s.y,r.y),f=Math.max(s.x,r.x),l=f-a,h=Math.max(s.y,r.y),m=h-u,x=Math.min(c.x,i.x),d=Math.min(c.y,i.y),g=Math.max(c.x,i.x),C=g-x,z=Math.max(c.y,i.y),A=z-d;if(l===0&&C===0||m===0&&A===0)return null;let Y=p=>p.x<x||p.x>g||p.x<a||p.x>f,X=p=>p.y<d||p.y>z||p.y<u||p.y>h;var M=null;if(l===0){if(n&&(x>a||g<f))return null;let p=o.mq(c,i);M=o.cramer([1,0,-a],[p[0],-1,p[1]]),n&&X(M)&&(M=null)}else if(C===0){if(n&&(a>x||f<g))return null;let p=o.mq(s,r);M=o.cramer([p[0],-1,p[1]],[1,0,-x]),n&&X(M)&&(M=null)}else if(m===0){if(n&&(d>u||z<h))return null;let p=o.mq(c,i);M=o.cramer([0,1,-u],[p[0],-1,p[1]]),n&&Y(M)&&(M=null)}else if(A===0){if(n&&(u>d||h<z))return null;let p=o.mq(s,r);M=o.cramer([p[0],-1,p[1]],[0,1,-d]),n&&Y(M)&&(M=null)}else{let p;if(!n||(p=o._intersectRects({x:a,y:u,width:l,height:m},{x,y:d,width:C,height:A}))&&p.width>0&&p.height>0){let j=o.mq(s,r),V=o.mq(c,i),D=j[0],O=V[0],K=j[1],et=V[1];if(D!==O){M=o.cramer([D,-1,K],[O,-1,et]);let q=M.x,I=M.y;n&&(q<p.x||q>p.x+p.width||I<p.y||I>p.y+p.height)&&(M=null)}}}return M===null?null:{x:M.x,y:M.y}}static _intersectRects(...t){return xt.intersect(...t)}static _areClose(t,e,n=Q){return Math.abs(t.x-e.x).isCloseTo(0,n)&&Math.abs(t.y-e.y).isCloseTo(0,n)}static areClose(t,e,n=Q){return o._areClose(t,e,n)}static dot(t,e){return T.dot(t,e)}static cross(t,e){return T.cross(t,e)}static distance(t,e){if(se(t))return rt.distance(t[0],t[1]);if(ut(e))return rt.distance(t,e);{let n=e[0],s=e[1];return Math.abs(n*t.x-t.y+s)/Math.sqrt(Math.pow(n,2)+1)}}static _pointSegmentDistance(t,e){let n=T.from(e[0],e[1]),s=T.from(e[0],t);return o.cross(n,s)}static isWithin(t,e,n,s=Q){let r=o._pointSegmentDistance(t,e);return r.isCloseTo(0,s)?!1:n?r<0:r>0}static isBeyond(t,e,n,s=Q){return o.isWithin(t,e,!n,s)}static inLine(t,e,n=Q){return o._pointSegmentDistance(t,e).isCloseTo(0,n)}static inSegment(t,e,n=Q){let s=Math.min(e[0].x,e[1].x),r=Math.max(e[0].x,e[1].x),c=Math.min(e[0].y,e[1].y),i=Math.max(e[0].y,e[1].y);return t.x>=s&&t.x<=r&&t.y>=c&&t.y<=i&&o.inLine(t,e,n)}static inTriangle(t,e){let n;for(let s=0;s<3;s++){let r=e[s],c=e[(s+1)%3],i=rt.subtract(c,t),a=rt.subtract(r,t),u=o.cross(i,a);if(s>0&&u*n<=0)return!1;n=u}return!0}static inPolygon(t,e,n=Q){if(!(e?.length>=3))throw"Not enough vertices";let s=e.length;if(s===3)return o.inTriangle(t,[e[0],e[1],e[2]]);n>0&&(e=e.map(h=>({x:h.x.roundoff(n),y:h.y.roundoff(n)})),t={x:t.x.roundoff(n),y:t.y.roundoff(n)});let r=Number.MAX_VALUE,c=Number.MAX_VALUE,i=Number.MIN_VALUE,a=Number.MIN_VALUE;for(let h=0;h<s;h++){let m=e[h];r=Math.min(r,m.x),c=Math.min(c,m.y),i=Math.max(i,m.x),a=Math.max(a,m.y)}if(t.x<r||t.x>i||t.y<c||t.y>a)return!1;let u={x:r-1,y:t.y},f=[u,t],l=0;for(let h=0;h<s;h++){let m=e[h],x=e[(h+1)%s],d=[m,x];if(m.y===t.y){let g=e[(h-1+s)%s];t.x>m.x&&(g.y-t.y)*(x.y-t.y)<0&&l++}else{if(x.y===t.y)continue;o.intersect(d,f)!=null&&l++}}return l%2===1}static area(t,...e){let n=[].concat(t).concat(e),s=0,r=n.length;if(r>=3){for(let c=0;c<n.length;c++){let{x:i,y:a}=n[c],u=c===r-1?0:c+1,{x:f,y:l}=n[u];s+=i*l-a*f}s*=.5}return Math.abs(s.roundoff())}static convexHull(t,...e){let n=[].concat(t).concat(e);if(!(n?.length>1))return n?.slice()??[];let s=n.map(u=>({x:u.x,y:u.y})).sort((u,f)=>u.x===f.x?u.y-f.y:u.x-f.x),r=[];for(let u of s){let f=r[r.length-1];(!f||f.x!==u.x||f.y!==u.y)&&r.push(u)}if(r.length<=2)return r;let c=(u,f,l)=>(f.x-u.x)*(l.y-u.y)-(f.y-u.y)*(l.x-u.x),i=[];for(let u of r){for(;i.length>=2&&c(i[i.length-2],i[i.length-1],u)<=0;)i.pop();i.push(u)}let a=[];for(let u=r.length-1;u>=0;u--){let f=r[u];for(;a.length>=2&&c(a[a.length-2],a[a.length-1],f)<=0;)a.pop();a.push(f)}return i.pop(),a.pop(),i.concat(a)}};import{Point as ot,Matrix2D as dt,Angle as pt,NullChecker as re}from"@pacem/pacem-foundation";function oe(o){let t;return"vertices"in o&&Array.isArray(o.vertices)&&(t=o.vertices).length>=3&&t.every(e=>ot.isPoint(e))}var gt=class o{static{this._eps=1e-12}static isPolygon(t){return oe(t)}static from(...t){return{vertices:Array.from(t)}}static contains(t,e){return R.inPolygon(e,t.vertices,12)}static centroid(t){let e=o.boundingBox(t);return{x:e.x+e.width/2,y:e.y+e.height/2}}static boundingBox(t){return R.boundingBox(t.vertices)}static sides(t){let{vertices:e}=t,n=[];for(let s=1;s<=e.length;s++){let r=e[s%e.length],c=e[s-1];n.push([c,r])}return n}static isConvex(t){let{vertices:e}=t,n=e.length;if(n<=3)return!0;let s=0;for(let r=0;r<e.length;r++){let c=e[(r-1+n)%n],i=e[r],a=e[(r+1)%n],u=pt.angleBetween(i,c,a);if(s===0){s=Math.sign(u);continue}if(s!=Math.sign(u))return!1}return!0}static isSelfIntersecting(t){let{vertices:e}=t;if(e.length<=3)return!1;let n=o.sides(t);for(let s of n)for(let r of n){if(r===s||r[0]===s[1]||s[0]===r[1])continue;let c=R.intersect(r,s);if(!re.isNull(c))return!0}return!1}static isCounterClockwise(t){let{vertices:[e,n,s]}=t;return pt.angleBetween(n,e,s)>0}static expand(t,e){let{vertices:n}=t,s=n.length,r=[];for(let c=0;c<n.length;c++){let i=n[(c-1+s)%s],a=n[c],u=n[(c+1)%s],f=pt.angleBetween(a,i,u),l=-e/Math.sin(Math.abs(f)/2),h=dt.scale(dt.identity,l),m=ot.subtract(a,i);T.normalize(m);let x=ot.subtract(a,u);T.normalize(x);let d=ot.add(m,x);T.normalize(d);let g=dt.multiply(d,h);r.push(ot.add(a,{x:g.x.roundoff(),y:g.y.roundoff()}))}return{vertices:r}}static area(t){return R.area(t.vertices)}static intersect(t,e){return R.intersect(t,e)}static convexHull(t){return{vertices:R.convexHull(t.vertices)}}};import{parseAsNumericalArray as vt}from"@pacem/pacem-foundation";var ft=180/Math.PI,ct=1/ft,N=class o{static from(...t){if(t.length!==3)throw new RangeError("Must provide exactly 3 numbers");return{x:t[0],y:t[1],z:t[2]}}static parse(t){let e=vt(t);if(e&&e.length===3)return o.from.apply(null,e);throw new Error(`Cannot parse "${t}" as a valid Vector3D.`)}static i(){return{x:1,y:0,z:0}}static j(){return{x:0,y:1,z:0}}static k(){return{x:0,y:0,z:1}}static zero(){return{x:0,y:0,z:0}}static subtract(t,e){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static add(...t){var e={x:0,y:0,z:0};for(var n of t)e.x+=n.x,e.y+=n.y,e.z+=n.z;return e}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static scale(t,e,n=e,s=e){return{x:t.x*e,y:t.y*n,z:t.z*s}}static magSqr(t){return t.x*t.x+t.y*t.y+t.z*t.z}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)&&(e.z-t.z).isCloseTo(0)}static mag(t){return Math.sqrt(o.magSqr(t))}static negate(t){return{x:-t.x,y:-t.y,z:-t.z}}static unit(t){let e={x:t.x,y:t.y,z:t.z};return this.normalize(e),e}static normalize(t){let e=o.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";let n=1/e;t.x*=n,t.y*=n,t.z*=n}static angleBetween(t,e){let n,s=o.unit(t),r=o.unit(e);if(o.dot(s,r)<0){let i={x:-s.x-r.x,y:-s.y-r.y,z:-s.z-r.z},a=o.mag(i);n=Math.PI-2*Math.asin(a/2)}else{let i={x:s.x-r.x,y:s.y-r.y,z:s.z-r.z},a=o.mag(i);n=2*Math.asin(a/2)}return ft*n}},bt=class o{static from(t,e,n){return{rho:t.clamp(0,1/0),theta:e.clamp(-180,180),phi:n.clamp(0,360)}}static fromVector(t,e,n){typeof t=="number"&&(t=N.from(t,e,n));let s=N.mag(t);if(s.isCloseTo(0))return o.from(0,0,0);let r=Math.atan2(t.x,t.z),c=Math.acos((t.y/s).clamp(-1,1));return o.from(s,r*ft,c*ft)}static toVector(t){let{rho:e,theta:n,phi:s}=t,r=s*ct,c=n*ct,i=Math.sin(r)*e;return{x:i*Math.sin(c),y:Math.cos(r)*e,z:i*Math.cos(c)}}static toRotationMatrix(t){let{theta:e,phi:n}=t,s=ct*e,r=Math.sin(s),c=Math.cos(s),i=ct*n,a=Math.sin(i),u=Math.cos(i);return U.from(r*u,r*a,c,0,c*u,c*a,-r,0,-a,u,0,0,0,0,0,1)}},W=class o{static modify(t,e){let{m11:n,m12:s,m13:r,m14:c,m21:i,m22:a,m23:u,m24:f,m31:l,m32:h,m33:m,m34:x,offsetX:d,offsetY:g,offsetZ:C,m44:z}=t,A={m11:n,m12:s,m13:r,m14:c,m21:i,m22:a,m23:u,m24:f,m31:l,m32:h,m33:m,m34:x,offsetX:d,offsetY:g,offsetZ:C,m44:z};return e(A),A}static clone(t){return o.modify(t,e=>{})}static multiply(t,e){return U.isIdentity(t)?e:U.isIdentity(e)?t:U.from(t.m11*e.m11+t.m12*e.m21+t.m13*e.m31+t.m14*e.offsetX,t.m11*e.m12+t.m12*e.m22+t.m13*e.m32+t.m14*e.offsetY,t.m11*e.m13+t.m12*e.m23+t.m13*e.m33+t.m14*e.offsetZ,t.m11*e.m14+t.m12*e.m24+t.m13*e.m34+t.m14*e.m44,t.m21*e.m11+t.m22*e.m21+t.m23*e.m31+t.m24*e.offsetX,t.m21*e.m12+t.m22*e.m22+t.m23*e.m32+t.m24*e.offsetY,t.m21*e.m13+t.m22*e.m23+t.m23*e.m33+t.m24*e.offsetZ,t.m21*e.m14+t.m22*e.m24+t.m23*e.m34+t.m24*e.m44,t.m31*e.m11+t.m32*e.m21+t.m33*e.m31+t.m34*e.offsetX,t.m31*e.m12+t.m32*e.m22+t.m33*e.m32+t.m34*e.offsetY,t.m31*e.m13+t.m32*e.m23+t.m33*e.m33+t.m34*e.offsetZ,t.m31*e.m14+t.m32*e.m24+t.m33*e.m34+t.m34*e.m44,t.offsetX*e.m11+t.offsetY*e.m21+t.offsetZ*e.m31+t.m44*e.offsetX,t.offsetX*e.m12+t.offsetY*e.m22+t.offsetZ*e.m32+t.m44*e.offsetY,t.offsetX*e.m13+t.offsetY*e.m23+t.offsetZ*e.m33+t.m44*e.offsetZ,t.offsetX*e.m14+t.offsetY*e.m24+t.offsetZ*e.m34+t.m44*e.m44)}},U=class o{static identity(){return{m11:1,m12:0,m13:0,m14:0,m21:0,m22:1,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,offsetX:0,offsetY:0,offsetZ:0,m44:1}}static from(...t){if(t.length!==16)throw new RangeError("Must provide exactly 16 numbers");return{m11:t[0],m12:t[1],m13:t[2],m14:t[3],m21:t[4],m22:t[5],m23:t[6],m24:t[7],m31:t[8],m32:t[9],m33:t[10],m34:t[11],offsetX:t[12],offsetY:t[13],offsetZ:t[14],m44:t[15]}}static transpose(t){return o.from(t.m11,t.m21,t.m31,t.offsetX,t.m12,t.m22,t.m32,t.offsetY,t.m13,t.m23,t.m33,t.offsetZ,t.m14,t.m24,t.m34,t.m44)}static toArray(t){return[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.offsetX,t.offsetY,t.offsetZ,t.m44]}static clone(t,e){return typeof e=="function"?W.modify(t,e):W.clone(t)}static scale(t,e,n,s){return typeof e=="number"?(n??=e,s??=e):(s=e.z,n=e.y,e=e.x),W.modify(t,r=>{r.m11*=e,r.m22*=n,r.m33*=s})}static translate(t,e){return W.modify(t,n=>{n.offsetX+=e.x,n.offsetY+=e.y,n.offsetZ+=e.z})}static parse(t){let e=vt(t);if(e&&e.length===16)return o.from.apply(null,e);throw new Error(`Cannot parse "${t}" as a valid Matrix3D.`)}static isIdentity(t){return t.m11==1&&t.m12==0&&t.m13==0&&t.m14==0&&t.m21==0&&t.m22==1&&t.m23==0&&t.m24==0&&t.m31==0&&t.m32==0&&t.m33==1&&t.m34==0&&t.offsetX==0&&t.offsetY==0&&t.offsetZ==0&&t.m44==1}static isAffine(t){return t.m14==0&&t.m24==0&&t.m34==0&&t.m44==1}static determinant(t){if(o.isIdentity(t))return 1;if(o.isAffine(t))return t.m11*(t.m22*t.m33-t.m32*t.m23)-t.m12*(t.m21*t.m33-t.m31*t.m23)+t.m13*(t.m21*t.m32-t.m31*t.m22);{let e=t.m13*t.m24-t.m23*t.m14,n=t.m13*t.m34-t.m33*t.m14,s=t.m13*t.m44-t.offsetZ*t.m14,r=t.m23*t.m34-t.m33*t.m24,c=t.m23*t.m44-t.offsetZ*t.m24,i=t.m33*t.m44-t.offsetZ*t.m34,a=t.m22*n-t.m32*e-t.m12*r,u=t.m12*c-t.m22*s+t.offsetY*e,f=t.m32*s-t.offsetY*n-t.m12*i,l=t.m22*i-t.m32*c+t.offsetY*r;return t.offsetX*a+t.m31*u+t.m21*f+t.m11*l}}static multiply(...t){if(t.length===0)throw new ReferenceError("Matrix not provided.");let e=Array.from(t),n=e[0];for(let s=1;s<e.length;s++)n=W.multiply(n,e[s]);return n}static invert(t){if(o.isAffine(t)){let e=o.determinant(t);if(e==0)return null;let n=t.m12*t.m23-t.m22*t.m13,s=t.m32*t.m13-t.m12*t.m33,r=t.m22*t.m33-t.m32*t.m23,c=t.m21*t.m13-t.m11*t.m23,i=t.m11*t.m33-t.m31*t.m13,a=t.m31*t.m23-t.m21*t.m33,u=t.m11*t.m22-t.m21*t.m12,f=t.m11*t.m32-t.m31*t.m12,l=t.m11*t.offsetY-t.offsetX*t.m12,h=t.m21*t.m32-t.m31*t.m22,m=t.m21*t.offsetY-t.offsetX*t.m22,x=t.m31*t.offsetY-t.offsetX*t.m32,d=t.m23*l-t.offsetZ*u-t.m13*m,g=t.m13*x-t.m33*l+t.offsetZ*f,C=t.m33*m-t.offsetZ*h-t.m23*x,z=u,A=-f,Y=h,X=1/e;return o.from(r*X,s*X,n*X,0,a*X,i*X,c*X,0,Y*X,A*X,z*X,0,C*X,g*X,d*X,1)}else{let e=o.determinant(t);if(e==0)return null;let n=t.m33*t.m44-t.m34*t.offsetZ,s=t.m32*t.m44-t.m34*t.offsetY,r=t.m31*t.m44-t.m34*t.offsetX,c=t.m32*t.offsetZ-t.m33*t.offsetY,i=t.m31*t.offsetZ-t.m33*t.offsetX,a=t.m31*t.offsetY-t.m32*t.offsetX,u=t.m33*t.m44-t.m34*t.offsetZ,f=t.m32*t.m44-t.m34*t.offsetY,l=t.m31*t.m44-t.m34*t.offsetX,h=t.m32*t.offsetZ-t.m33*t.offsetY,m=t.m31*t.offsetZ-t.m33*t.offsetX,x=t.m31*t.offsetY-t.m32*t.offsetX,d=t.m23*t.m44-t.m24*t.offsetZ,g=t.m22*t.m44-t.m24*t.offsetY,C=t.m21*t.m44-t.m24*t.offsetX,z=t.m22*t.offsetZ-t.m23*t.offsetY,A=t.m21*t.offsetZ-t.m23*t.offsetX,Y=t.m21*t.offsetY-t.m22*t.offsetX,X=t.m23*t.m34-t.m24*t.m33,M=t.m22*t.m34-t.m24*t.m32,p=t.m21*t.m34-t.m24*t.m31,j=t.m22*t.m33-t.m23*t.m32,V=t.m21*t.m33-t.m23*t.m31,D=t.m21*t.m32-t.m22*t.m31,O=t.m22*n-t.m23*s+t.m24*c,K=-(t.m21*n-t.m23*r+t.m24*i),et=t.m21*s-t.m22*r+t.m24*a,q=-(t.m21*c-t.m22*i+t.m23*a),I=-(t.m12*u-t.m13*f+t.m14*h),y=t.m11*u-t.m13*l+t.m14*m,w=-(t.m11*f-t.m12*l+t.m14*x),b=t.m11*h-t.m12*m+t.m13*x,v=t.m12*d-t.m13*g+t.m14*z,B=-(t.m11*d-t.m13*C+t.m14*A),k=t.m11*g-t.m12*C+t.m14*Y,F=-(t.m11*z-t.m12*A+t.m13*Y),G=-(t.m12*X-t.m13*M+t.m14*j),L=t.m11*X-t.m13*p+t.m14*V,$=-(t.m11*M-t.m12*p+t.m14*D),H=t.m11*j-t.m12*V+t.m13*D,E=1/e;return o.from(O*E,I*E,v*E,G*E,K*E,y*E,B*E,L*E,et*E,w*E,k*E,$*E,q*E,b*E,F*E,H*E)}}static transform(t,e){var n={x:t.x,y:t.y,z:t.z};if(!o.isIdentity(e)){var s=n.x,r=n.y,c=n.z;if(n.x=s*e.m11+r*e.m21+c*e.m31+e.offsetX,n.y=s*e.m12+r*e.m22+c*e.m32+e.offsetY,n.z=s*e.m13+r*e.m23+c*e.m33+e.offsetZ,!o.isAffine(e)){var i=s*e.m14+r*e.m24+c*e.m34+e.m44;i!=0&&(n.x/=i,n.y/=i,n.z/=i)}}return n}},wt=class o{static identity(){return o.from(0,0,0,1)}static from(...t){if(t.length!==4)throw new RangeError("Must provide exactly 4 numbers");return{x:t[0],y:t[1],z:t[2],w:t[3]}}static parse(t){let e=vt(t);if(e&&e.length===4)return o.from.apply(null,e);throw new Error(`Cannot parse "${t}" as a valid Quaternion.`)}static fromVectors(t,e){N.normalize(t),N.normalize(e);let n=(r,c,i,a)=>{let u=o.from(r,c,i,a);return o.normalize(u),u},s=N.dot(t,e)+1;return s.isCloseTo(0)?Math.abs(t.x)>Math.abs(t.z)?n(-t.y,t.x,0,0):n(0,-t.z,t.y,0):n(t.y*e.z-t.z*e.y,t.z*e.x-t.x*e.z,t.x*e.y-t.y*e.x,s)}static normalize(t){let e=o.mag(t);if(e.isCloseTo(0))t.x=t.y=t.z=0,t.w=1;else{let n=1/e;t.x*=n,t.y*=n,t.z*=n,t.w*=n}}static unit(t){let e=o.from(t.x,t.y,t.z,t.w);return o.normalize(e),e}static fromAxisAngle(t,e){e%=360;var n=ct*e,s=N.mag(t);if(s==0)throw new RangeError("Invalid argument");var r=Math.sin(.5*n)/s,c=t.x*r,i=t.y*r,a=t.z*r;return o.from(c,i,a,Math.cos(.5*n))}static fromRotationMatrix(t){let e=t.m11+t.m22+t.m33+t.m44;if(e>0){let n=.5/Math.sqrt(e),s=.25/n,r=(t.m23-t.m32)*n,c=(t.m31-t.m13)*n,i=(t.m12-t.m21)*n;return o.from(r,c,i,s)}else if(t.m11>t.m22&&t.m11>t.m22){let n=.5/Math.sqrt(t.m44+t.m11-t.m22-t.m33),s=(t.m23-t.m32)*n,r=.25/n,c=(t.m12+t.m21)*n,i=(t.m31+t.m13)*n;return o.from(r,c,i,s)}else if(t.m22>t.m33){let n=.5/Math.sqrt(t.m44+t.m22-t.m11-t.m33),s=(t.m23+t.m32)*n,r=.25/n,c=(t.m12+t.m21)*n,i=(t.m31-t.m13)*n;return o.from(c,r,s,i)}else{let n=.5/Math.sqrt(t.m44+t.m33-t.m11-t.m22),s=(t.m23+t.m32)*n,r=.25/n,c=(t.m12-t.m21)*n,i=(t.m31-t.m13)*n;return o.from(i,s,r,c)}}static conjugate(t){return o.from(-t.x,-t.y,-t.z,t.w)}static mag(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w)}static norm(t){return t.x*t.x+t.y*t.y+t.z*t.z}static axis(t){return t.x==0&&t.y==0&&t.z==0?N.j():N.unit(t)}static transform(t,e){o.normalize(e);let n=N.cross(e,t),s=N.scale(n,2),r=N.cross(e,s);return{x:t.x+e.w*s.x+r.x,y:t.y+e.w*s.y+r.y,z:t.z+e.w*s.z+r.z}}static angle(t){let e=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),n=t.w;if(e>Number.MAX_VALUE){let s=Math.max(Math.abs(t.x),Math.max(Math.abs(t.y),Math.abs(t.z))),r=t.x/s,c=t.y/s,i=t.z/s;e=Math.sqrt(r*r+c*c+i*i),n/=s}return Math.atan2(e,n)*114.59155902616465}static toRotationMatrix(t){var e=U.identity(),n=t.x,s=t.y,r=t.z,c=t.w;return e.m11=1-2*s*s-2*r*r,e.m12=2*n*s+2*c*r,e.m13=2*n*r-2*c*s,e.m21=2*n*s-2*c*r,e.m22=1-2*n*n-2*r*r,e.m23=2*s*r+2*c*n,e.m31=2*c*s+2*n*r,e.m32=2*s*r-2*c*n,e.m33=1-2*n*n-2*s*s,e}static invert(t){let e=o.unit(t);return o.conjugate(e)}static multiply(t,e){return o.from(t.w*e.x+t.x+e.w+t.y*e.z-t.z*e.y,t.w*e.y-t.x*e.z+t.y*e.w+t.z*e.x,t.w*e.z+t.x*e.y-t.y*e.x+t.z*e.w,t.w*e.w-t.x*e.x-t.y*e.y-t.z*e.z)}static dot(t,e){var n=o.multiply(t,o.conjugate(e));return n.w}};var At=class{static intersect(t,e){let[n,s]=t,r=N.subtract(n,s),[c,i,a]=e,u=N.subtract(c,i),f=N.subtract(c,a),l=N.cross(r,f),h=N.dot(u,l);if(h.isCloseTo(0))return null;let m=1/h,x=N.subtract(n,c),d=m*N.dot(x,l);if(d<0||d>1)return null;let g=N.cross(x,u),C=m*N.dot(r,g);if(C<0||d+C>1)return null;let z=m*N.dot(f,g);return z<0||z.isCloseTo(0)?null:N.add(n,N.scale(r,z))}};var zt={};nt(zt,{Matrix3D:()=>U,Quaternion:()=>wt,Spherical:()=>bt,Vector:()=>T,Vector3D:()=>N});var kt={};nt(kt,{Complex:()=>S,DataAnalysis:()=>Bt,NumberTheory:()=>Pt});function P(o){return typeof o=="number"&&(o={real:o,img:0}),o}var Lt;function J(o,t){let e={};return Object.defineProperty(e,"real",{value:o,writable:!1}),Object.defineProperty(e,"img",{value:t,writable:!1}),e}function Mt(){return Lt||(Lt=J(Number.NaN,Number.NaN))}var S=class{static build(t,e){return this.isComplex(t)?t:(e??=0,typeof t!="number"||typeof e!="number"?Mt():J(t,e||0))}static add(t,e){let n=P(t),s=P(e);return J(n.real+s.real,n.img+s.img)}static subtract(t,e){let n=P(t),s=P(e);return J(n.real-s.real,n.img-s.img)}static multiply(t,e){let n=P(t),s=P(e);return J(n.real*s.real-n.img*s.img,n.real*s.img+n.img*s.real)}static divide(t,e){let n=P(t),s=P(e),r=this.absSquare(s).roundoff();if(r===0)return Mt();let c=1/r;return J(c*(n.real*s.real+n.img*s.img),c*(n.img*s.real-n.real*s.img))}static absSquare(t){let e=P(t);return Math.pow(e.real,2)+Math.pow(e.img,2)}static modulus(t){return Math.sqrt(this.absSquare(t))}static isComplex(t){return t!=null&&typeof t=="object"&&"real"in t&&"img"in t&&typeof t.real=="number"&&typeof t.img=="number"}static conjugate(t){return t=P(t),J(t.real,Math.abs(t.img)==0?0:-t.img)}static equals(t,e){let n=this.build(t),s=this.build(e);return!this.isComplex(t)||!this.isComplex(e)?!1:n.real===s.real&&n.img===s.img}static get NaC(){return Mt()}};var Bt={};nt(Bt,{Fourier:()=>Nt,Gaussian:()=>tt,Lagrange:()=>lt,Lagrangian:()=>le,Newton:()=>Et,Pchip:()=>Xt,SearchFunctions:()=>be,Utils:()=>It});function ce(o,t){let e=2*Math.PI*o/t;return S.build(Math.cos(e),Math.sin(e))}var Vt={};function Ot(o,t){let e=Vt[t]=Vt[t]||{};return e[o]=e[o]||ce(o,t)}function ie(o){return o>0&&(o&o-1)===0}function Ct(o){let t=[],e=o.length;if(e===1)return[S.build(o[0])];let n=Ct(o.filter((c,i)=>i%2===0)),s=Ct(o.filter((c,i)=>i%2===1));for(var r=0;r<e/2;r++){let c=n[r],i=S.multiply(Ot(r,e),s[r]);t[r]=S.add(c,i),t[r+e/2]=S.subtract(c,i)}return t}var Nt=class{static transform(t,e=!0){return t=t||[],ie(t.length)?this.fft(t,e):this.dft(t,e)}static invert(t,e=!0){return this.idft(t||[],e)}static dft(t,e=!0){let n=(t||[])?.length,s=e?1/Math.sqrt(n):1,r=[];for(let c=0;c<n;c++){r.push({real:0,img:0});for(let i=0;i<n;i++){let a=Ot(c*i,n),u=S.multiply(t[i],a),f=S.multiply(u,s);r[c]=S.add(r[c],f)}}return r}static idft(t,e=!0){let n=t.map(r=>S.build(r.img,r.real));return this.transform(n,e).map(r=>S.build(r.img,r.real))}static fft(t,e=!0){let n=Ct(t);if(!e)return n;let s=1/Math.sqrt(t.length);return n.map(r=>S.multiply(r,s))}};var ae=Math.sqrt(Math.PI);function ue(o){let t=Math.abs(o),e=1/(1+.5*t),n=e*Math.exp(-t*t-1.26551223+e*(1.00002368+e*(.37409196+e*(.09678418+e*(-.18628806+e*(.27886807+e*(-1.13520398+e*(1.48851587+e*(-.82215223+e*.17087277)))))))));return o>=0?n:2-n}var tt=class{constructor(t,e){this.mean=t,this.stdev=Math.abs(e),this.variance=Math.pow(e,2)}static get normal(){return fe}weight(t){return Math.exp(-.5*Math.pow(this._z(t),2))}probabilityDensity(t){let e=this.stdev*Math.SQRT2*ae;return this.weight(t)/e}_z(t){return(t-this.mean)/this.stdev}probability(t){return .5*ue(-this._z(t)/Math.SQRT2)}},fe=new tt(0,1);var lt=class o{constructor(t){this.#e=t}#e;#t=null;_prepareBarycentric(){if(this.#t)return;let t=this.#e||[],e=t.length;if(e===0){this.#t=[];return}let n=new Array(e),s=new Array(e);for(let i=0;i<e;i++){let a=0,u=1,f=t[i].x;for(let l=0;l<e;l++){if(l===i)continue;let h=f-t[l].x;if(h===0)throw new Error("Invalid function provided.");h<0&&(u=-u),a+=Math.log(Math.abs(h))}n[i]=-a,s[i]=u}let r=n[0];for(let i=1;i<e;i++)n[i]>r&&(r=n[i]);let c=new Array(e);for(let i=0;i<e;i++){let a=Math.exp(n[i]-r);c[i]=s[i]*a}this.#t=c}_computeBarycentric(t){let e=this.#e||[];this.#t||this._prepareBarycentric();let n=this.#t||[],s=0,r=0;for(let c=0;c<e.length;c++){let i=e[c].x;if(t===i)return e[c].y;let a=n[c]/(t-i);s+=a*e[c].y,r+=a}return s/r}interpolate(t){return this._computeBarycentric(t)}static create(...t){var e=[];arguments.length>0&&Array.isArray(arguments[0])?e=arguments[0]:e=Array.from(t);let n=e.map((s,r)=>typeof s=="number"?{x:r,y:s}:s);return new o(n)}},le={create:lt.create},Xt=class o{constructor(t){if(!t||t.length<2)throw new Error("Need at least 2 points");let e=t.slice().sort((n,s)=>n.x-s.x);this.xs=e.map(n=>n.x),this.ys=e.map(n=>n.y),this.ms=this.computeDerivatives()}computeDerivatives(){let t=this.xs.length,e=new Array(t-1),n=new Array(t-1);for(let r=0;r<t-1;r++)e[r]=this.xs[r+1]-this.xs[r],n[r]=(this.ys[r+1]-this.ys[r])/e[r];let s=new Array(t).fill(0);s[0]=n[0],s[t-1]=n[t-2];for(let r=1;r<t-1;r++){let c=n[r-1],i=n[r];if(c===0||i===0||c*i<=0)s[r]=0;else{let a=2*e[r]+e[r-1],u=e[r]+2*e[r-1];s[r]=(a+u)/(a/c+u/i)}}for(let r=0;r<t-1;r++)if(n[r]===0)s[r]=0,s[r+1]=0;else{let c=s[r]/n[r],i=s[r+1]/n[r],a=c*c+i*i;if(a>9){let u=3/Math.sqrt(a);s[r]=u*c*n[r],s[r+1]=u*i*n[r]}}return s}interpolate(t){let e=this.xs,n=this.ys,s=this.ms,r=e.length;if(t<=e[0]){let g=s[0];return n[0]+g*(t-e[0])}if(t>=e[r-1]){let g=s[r-1];return n[r-1]+g*(t-e[r-1])}let c=0,i=r-1;for(;i-c>1;){let g=c+i>>1;e[g]<=t?c=g:i=g}let a=e[c+1]-e[c],u=(t-e[c])/a,f=u*u,l=f*u,h=2*l-3*f+1,m=l-2*f+u,x=-2*l+3*f,d=l-f;return h*n[c]+m*(s[c]*a)+x*n[c+1]+d*(s[c+1]*a)}static create(...t){var e=[];arguments.length>0&&Array.isArray(arguments[0])?e=arguments[0]:e=Array.from(t);let n=e.map((s,r)=>typeof s=="number"?{x:r,y:s}:s);return new o(n)}},Et=class o{constructor(t){if(!t||t.length===0)throw new Error("Need at least 1 point");let e=t.slice().sort((r,c)=>r.x-c.x);this.xs=e.map(r=>r.x);let n=e.length,s=e.map(r=>r.y);for(let r=1;r<n;r++)for(let c=n-1;c>=r;c--){let i=this.xs[c]-this.xs[c-r];if(i===0)throw new Error("Invalid function provided.");s[c]=(s[c]-s[c-1])/i}this.coeffs=s}interpolate(t){let e=this.xs,n=this.coeffs,s=n.length;if(s===0)return NaN;let r=n[s-1];for(let c=s-2;c>=0;c--)r=r*(t-e[c])+n[c];return r}static create(...t){var e=[];arguments.length>0&&Array.isArray(arguments[0])?e=arguments[0]:e=Array.from(t);let n=e.map((s,r)=>typeof s=="number"?{x:r,y:s}:s);return new o(n)}};var Z=(o,t)=>o;function he(o,t=Z){let e=Object.groupBy(o,t),n,s=0;for(let r in e){let c=e[r].length;c>s&&(n=parseInt(r),s=c)}return n}function me(o,t=Z){let e=o.slice(0),n=e.length;e.sort((r,c)=>{let i=t(r),a=t(c);return i-a});let s=Math.ceil(e.length/2)-1;return n%2==1?e[s]:.5*(e[s+1]+e[s])}function $t(o,t=Z){return o.reduce((e,n,s)=>e+t(n,s),0)}function ht(o,t=Z){return $t(o,t)/o.length}function Yt(o,t=Z,e=!1){let n=ht(o,t);return o.reduce((s,r)=>Math.pow(r-n,2)+s,0)/(o.length-(e?1:0))}function Ft(o,t=Z,e=!1){let n=Yt(o,t,e);return Math.sqrt(n)}function ye(o,t,e=Z,n=Z){let s=Array.isArray(t);if(s&&t.length!==o.length)throw new Error("Sets must be of the same length.");let r=o.length,c=o,i=s?t:o,a=s?e:t,u=s?n:e,f=ht(c,a),l=ht(i,u),h=0,m=0,x=0;for(let d=0;d<r;d++){let g=c[d],C=i[d],z=a(g,d)-f,A=u(C,d)-l;h+=z*A,m+=z*z,x+=A*A}return h/Math.sqrt(m*x)}function xe(o,t,e=Z,n=Z){let s=Array.isArray(t);if(s&&t.length!==o.length)throw new Error("Sets must be of the same length.");let r=o,c=s?t:o,i=s?e:t,a=s?n:i,u=i??(A=>A.x),f=a??(A=>A.y),l=o.length,h=0,m=0,x=0,d=0,g=0;for(let A=0;A<l;A++){let Y=r[A],X=c[A],M=u(Y,A),p=f(X,A);h+=M*p,m+=M,x+=p,d+=M*M,g+=p*p}let C=(l*h-m*x)/(l*d-Math.pow(m,2)),z=(x-C*m)/l;return[C,z]}var It=class{static sum(t,e){return $t(t,e)}static mean(t,e){return ht(t,e)}static median(t,e){return me(t,e)}static mode(t,e){return he(t,e)}static var(t,e){return Yt(t,e,!0)}static varp(t,e){return Yt(t,e,!1)}static stdevp(t,e){return Ft(t,e,!1)}static stdev(t,e){return Ft(t,e,!0)}static correlation(t,e,n,s){return ye(t,e,n,s)}static linearRegression(t,e,n,s){return xe(t,e,n,s)}static gaussian(t,e){return new tt(t,e)}};function Dt(o,t){return(n,s,r,c)=>{let i=n,a=s,u=o(i,a),f=t(i,a),l=r(u),h=r(f);for(;a-i>c;)l<h?(a=f,f=u,h=l,u=o(i,a),l=r(u)):(i=u,u=f,l=h,f=t(i,a),h=r(f));return .5*(u+f)}}var St=.001,de=(o,t,e,n=St)=>Dt((a,u)=>u-(u-a)/1.618,(a,u)=>a+(u-a)/1.618)(o,t,e,n);function pe(o){if(o<=1)throw new RangeError("segments must be a number grater than 1.");return(t,e,n,s=St)=>Dt((a,u)=>a+(u-a)/o,(a,u)=>u-(u-a)/o)(t,e,n,s)}var ge=(o,t,e,n=St)=>{var s=null,r=null;let c=(f,l)=>(r??=l-f,s??=r/Math.sqrt(12),s*(l-f)/r);return Dt((f,l)=>Math.max(f,(l+f)/2-c(f,l)),(f,l)=>Math.min(l,(l+f)/2+c(f,l)))(o,t,e,n)},be={linear:(o=2)=>pe(o),goldenRatio:de,gaussian:ge};var Pt={};nt(Pt,{Utils:()=>Rt});import{Numbers as Ut,NullChecker as we}from"@pacem/pacem-foundation";var mt="0123456789abcdefghijklmnopqrstuvwxyz",Tt=`Radix out of range: possible values go between positive 1 exclusive and ${mt.length} inclusive`,Rt=class o{static lcd(...t){if(we.isNullOrEmpty(t)||t.length<=1)throw"Insufficient set of numbers.";function e(r,c){return c?e(c,r%c):c===0?r:NaN}function n(r,c){return r*c/e(r,c)}let s=Math.round(t[0]);for(let r=1;r<t.length;r++)s=n(s,Math.round(t[r]));return s}static gcd(t,e){return t=Math.round(t),e=Math.round(e),t===0?e:o.gcd(e%t,t)}static rebaseInt(t,e,n){return Ut.rebase(t,e,n)}static rebaseFloat(t,e,n,s=12){let r=o.rebaseFloat10ToN,c=o.rebaseFloatNTo10;if(e===10){let a=parseFloat(t.toString());return n%1===0?o.rebaseFloat10ToNIntBase(a,n,s):r(a,n,s)}if(n===10)return c(t.toString(),e,s);let i=c(t.toString(),e,s+1);return r(i,n,s)}static rebaseFloatNTo10(t,e,n=12){let s=mt;if(e<=1||e>s.length)throw new Error(Tt);let r=(t??"0").toString().toLowerCase(),c=Number.NaN;if(r==="0")return 0;let i=/^([-+]?) *([\da-z]+)?(.[\da-z]+)?$/.exec(r);if(i.length<2)return c;let a=i[1]==="-"?-1:1,u=i[2]||"0",f=i[3]||".0",l=0,h=0;for(let m of u+f.substr(1)){let x=s.indexOf(m);if(x===-1||x>=e)return c;l+=x*Math.pow(e,u.length-h-1),h++}return a*l}static rebaseFloat10ToNIntBase(t,e,n=12){let s=mt;if(e<=1||e>s.length)throw new Error(Tt);let r=e,c=Math.abs(t??0);if(c===0||Number.isNaN(c))return t.toString();let i=(c%1).roundoff(),a="";do{let f=c/r,l=Math.floor(f),h=(c-l*r).roundoff(),m=Math.floor(h);if(m>=s.length?a=`[${m}]`+a:a=s[m]+a,l<=0)break;c=l}while(!0);if(a=a.replace(/^0+/,""),a||="0",i===0)return a;let u="";do{c=(i*r).roundoff();let f=Math.floor(c),l=(c-f).roundoff();f>=s.length?u=`[${f}]`:u+=s[f],i=l}while(!i.isCloseTo(0)&&u.length<n);return/^0*$/.test(u)?a:(Math.sign(t)<0?"-":"")+a+"."+u.replace(/0+$/,"")}static rebaseFloat10ToN(t,e,n=12){let s=mt;if(e<=1||e>s.length)throw new Error(Tt);let r=e,c=Math.abs(t??0);if(c===0||Number.isNaN(c))return t.toString();let i=Math.sign(t)<0?"-":"",a=[],u=[];for(let m=0;m<20;m++)a.push("0"),u.push("0");let f=r%1===0?r:Math.ceil(r);function l(m,x,d){let g=m?a:u,C=g[x]=g[x]||"0",z=s.indexOf(C)+d,A=z%f,Y=Math.floor(z/f);return g[x]=s[A],Y>0&&(m?l(m,x+1,Y):x===0?l(!0,0,Y):l(!1,x-1,Y)),Y}let h=0;do{let m=Math.floor(Ut.log(c,r)),x=m>=0,d=x?m:Math.abs(1+m);if(l(x,d,1),c=(c-Math.pow(r,m).roundoff()).roundoff(),x||h++,c===0||h>=100){let g=i+(a.reverse().map(z=>z||"0").join("").replace(/^0+/,"")||"0"),C=u.map(z=>z||"0").join("").substr(0,n).replace(/0+$/,"");return/^0*$/.test(C)?g:g+"."+C}}while(!0)}};export{jt as Geometry,kt as Mathematics};
|
package/dist/esm/index-iife.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pacem/pacem-numerical v1.0.0-amaldi (https://js.pacem.it)
|
|
3
|
+
* Pacem (https://pacem.it)
|
|
4
|
+
* Licensed under Apache-2.0
|
|
5
|
+
*/
|
|
1
6
|
export * from './math/complex';
|
|
2
7
|
export * as DataAnalysis from './index-mathematics-dataanalysis.js';
|
|
3
8
|
export * as NumberTheory from './math/math';
|
package/dist/esm/index.js
CHANGED