Comparing version 2.1.0 to 2.1.1
@@ -1,1 +0,1 @@ | ||
!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).nudged=f()}}((function(){return function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,(function(r){return o(e[i][1][r]||r)}),p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(require,module,exports){module.exports=require("./lib/index")},{"./lib/index":19}],2:[function(require,module,exports){exports.mse=require("./mse"),exports.residuals=require("./residuals"),exports.rss=require("./rss")},{"./mse":3,"./residuals":4,"./rss":5}],3:[function(require,module,exports){const transformMany=require("../point/transformMany");module.exports=(tr,domain,range)=>{const n=Math.min(domain.length,range.length),codomain=transformMany(domain,tr);let dx,dy,sum=0;for(let i=0;i<n;i+=1)dx=codomain[i].x-range[i].x,dy=codomain[i].y-range[i].y,sum+=dx*dx+dy*dy;return sum/n}},{"../point/transformMany":30}],4:[function(require,module,exports){const distance=require("../point/distance"),transformMany=require("../point/transformMany");module.exports=(tr,domain,range)=>{const n=Math.min(domain.length,range.length),codomain=transformMany(domain,tr),arr=[];for(let i=0;i<n;i+=1)arr.push(distance(codomain[i],range[i]));return arr}},{"../point/distance":22,"../point/transformMany":30}],5:[function(require,module,exports){const transformMany=require("../point/transformMany");module.exports=(tr,domain,range)=>{const n=Math.min(domain.length,range.length),codomain=transformMany(domain,tr);let dx,dy,sum=0;for(let i=0;i<n;i+=1)dx=codomain[i].x-range[i].x,dy=codomain[i].y-range[i].y,sum+=dx*dx+dy*dy;return sum}},{"../point/transformMany":30}],6:[function(require,module,exports){const es=require("./estimators");module.exports=function(params){if(!params.estimator)throw new Error("Unexpected estimator type: "+params.estimator);switch(params.estimator.toUpperCase()){case"I":return es.I();case"L":return es.L(params.domain,params.range,params.angle);case"X":return es.X(params.domain,params.range);case"Y":return es.Y(params.domain,params.range);case"T":return es.T(params.domain,params.range);case"S":return es.S(params.domain,params.range,params.center);case"R":return es.R(params.domain,params.range,params.center);case"TS":return es.TS(params.domain,params.range);case"TR":return es.TR(params.domain,params.range);case"SR":return es.SR(params.domain,params.range,params.center);case"TSR":return es.TSR(params.domain,params.range);default:throw new Error("Unexpected estimator type: "+params.estimator)}}},{"./estimators":18}],7:[function(require,module,exports){module.exports=function(domain,range){return{a:1,b:0,x:0,y:0}}},{}],8:[function(require,module,exports){module.exports=function(domain,range,angle){const N=Math.min(domain.length,range.length);let a=0,b=0,c=0,d=0;const co=Math.cos(angle),si=Math.sin(angle);if(N<1)return{a:1,b:0,x:0,y:0};for(let i=0;i<N;i+=1)a+=domain[i].x,b+=domain[i].y,c+=range[i].x,d+=range[i].y;const t=(co*(c-a)+si*(d-b))/N;return{a:1,b:0,x:t*co,y:t*si}}},{}],9:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range,center){const N=Math.min(domain.length,range.length);let ac=0,ad=0,bc=0,bd=0;const cx=center.x,cy=center.y;let i,a,b,c,d;for(i=0;i<N;i+=1)a=domain[i].x-cx,b=domain[i].y-cy,c=range[i].x-cx,d=range[i].y-cy,ac+=a*c,ad+=a*d,bc+=b*c,bd+=b*d;const p=ac+bd,q=ad-bc,det=p*p+q*q;if(det<TOLERANCE)return{a:1,b:0,x:0,y:0};const den=Math.sqrt(det),ahat=p/den,bhat=q/den;return{a:ahat,b:bhat,x:cx-cx*ahat+cy*bhat,y:cy-cx*bhat-cy*ahat}}},{"../tolerance":32}],10:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range,center){const N=Math.min(domain.length,range.length);let ac=0,bd=0,aa=0,bb=0;const cx=center.x,cy=center.y;let i,a,b,c,d;for(i=0;i<N;i+=1)a=domain[i].x-cx,b=domain[i].y-cy,c=range[i].x-cx,d=range[i].y-cy,ac+=a*c,bd+=b*d,aa+=a*a,bb+=b*b;const det=aa+bb;if(Math.abs(det)<TOLERANCE)return{a:1,b:0,x:0,y:0};const ahat=Math.max(0,(ac+bd)/det);return{a:ahat,b:0,x:(1-ahat)*cx,y:(1-ahat)*cy}}},{"../tolerance":32}],11:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range,center){const N=Math.min(domain.length,range.length),cx=center.x,cy=center.y;let i,a,b,c,d,a2=0,b2=0,ac=0,bd=0,bc=0,ad=0;for(i=0;i<N;i+=1)a=domain[i].x-cx,b=domain[i].y-cy,c=range[i].x-cx,d=range[i].y-cy,a2+=a*a,b2+=b*b,ac+=a*c,bd+=b*d,bc+=b*c,ad+=a*d;const det=a2+b2;if(Math.abs(det)<TOLERANCE)return{a:1,b:0,x:0,y:0};const ahat=(ac+bd)/det,bhat=(-bc+ad)/det;return{a:ahat,b:bhat,x:cy*bhat-cx*ahat+cx,y:-cx*bhat-cy*ahat+cy}}},{"../tolerance":32}],12:[function(require,module,exports){module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(N<1)return{a:1,b:0,x:0,y:0};let dxs=0,dys=0,rxs=0,rys=0;for(let i=0;i<N;i+=1)dxs+=domain[i].x,dys+=domain[i].y,rxs+=range[i].x,rys+=range[i].y;return{a:1,b:0,x:(rxs-dxs)/N,y:(rys-dys)/N}}},{}],13:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(0===N)return{a:1,b:0,x:0,y:0};if(1===N){return{a:1,b:0,x:range[0].x-domain[0].x,y:range[0].y-domain[0].y}}let i,a,b,c,d,asum=0,bsum=0,csum=0,dsum=0,ac=0,ad=0,bc=0,bd=0;for(i=0;i<N;i+=1)a=domain[i].x,b=domain[i].y,c=range[i].x,d=range[i].y,asum+=a,bsum+=b,csum+=c,dsum+=d,ac+=a*c,ad+=a*d,bc+=b*c,bd+=b*d;const v=N*ac-asum*csum+(N*bd-bsum*dsum),w=N*ad-asum*dsum+(bsum*csum-N*bc),det=v*v+w*w;if(det<TOLERANCE)return{a:1,b:0,x:(csum-asum)/N,y:(dsum-bsum)/N};const den=Math.sqrt(det),ahat=v/den,bhat=w/den;return{a:ahat,b:bhat,x:(-asum*ahat+bsum*bhat+csum)/N,y:(-asum*bhat-bsum*ahat+dsum)/N}}},{"../tolerance":32}],14:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(0===N)return{a:1,b:0,x:0,y:0};if(1===N){return{a:1,b:0,x:range[0].x-domain[0].x,y:range[0].y-domain[0].y}}let i,a,b,c,d,a1=0,b1=0,c1=0,d1=0,a2=0,b2=0,ac=0,bd=0;for(i=0;i<N;i+=1)a=domain[i].x,b=domain[i].y,c=range[i].x,d=range[i].y,a1+=a,b1+=b,c1+=c,d1+=d,a2+=a*a,b2+=b*b,ac+=a*c,bd+=b*d;const N2=N*N,a12=a1*a1,b12=b1*b1,det=N2*a2-N*a12+N2*b2-N*b12;if(Math.abs(det)<TOLERANCE)return 0===N?{a:1,b:0,x:0,y:0}:{a:1,b:0,x:c1/N-a,y:d1/N-b};const p=a2+b2,q=ac+bd;return{a:(N2*q-N*(a1*c1+b1*d1))/det,b:0,x:(-N*a1*q+N*c1*p-b12*c1+a1*b1*d1)/det,y:(-N*b1*q+N*d1*p-a12*d1+a1*b1*c1)/det}}},{"../tolerance":32}],15:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(0===N)return{a:1,b:0,x:0,y:0};if(1===N){return{a:1,b:0,x:range[0].x-domain[0].x,y:range[0].y-domain[0].y}}let i,a,b,c,d,a1=0,b1=0,c1=0,d1=0,a2=0,b2=0,ad=0,bc=0,ac=0,bd=0;for(i=0;i<N;i+=1)a=domain[i].x,b=domain[i].y,c=range[i].x,d=range[i].y,a1+=a,b1+=b,c1+=c,d1+=d,a2+=a*a,b2+=b*b,ad+=a*d,bc+=b*c,ac+=a*c,bd+=b*d;const det=N*a2-a1*a1+N*b2-b1*b1;if(Math.abs(det)<TOLERANCE)return{a:1,b:0,x:c1/N-a,y:d1/N-b};return{a:(N*(ac+bd)-a1*c1-b1*d1)/det,b:(N*(ad-bc)+b1*c1-a1*d1)/det,x:(-a1*(ac+bd)+b1*(ad-bc)+a2*c1+b2*c1)/det,y:(-b1*(ac+bd)-a1*(ad-bc)+a2*d1+b2*d1)/det}}},{"../tolerance":32}],16:[function(require,module,exports){module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(N<1)return{a:1,b:0,x:0,y:0};let dxs=0,rxs=0;for(let i=0;i<N;i+=1)dxs+=domain[i].x,rxs+=range[i].x;return{a:1,b:0,x:(rxs-dxs)/N,y:0}}},{}],17:[function(require,module,exports){module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(N<1)return{a:1,b:0,x:0,y:0};let dys=0,rys=0;for(let i=0;i<N;i+=1)dys+=domain[i].y,rys+=range[i].y;return{a:1,b:0,x:0,y:(rys-dys)/N}}},{}],18:[function(require,module,exports){exports.I=require("./I"),exports.L=require("./L"),exports.X=require("./X"),exports.Y=require("./Y"),exports.T=require("./T"),exports.S=require("./S"),exports.R=require("./R"),exports.TS=require("./TS"),exports.TR=require("./TR"),exports.SR=require("./SR"),exports.TSR=require("./TSR")},{"./I":7,"./L":8,"./R":9,"./S":10,"./SR":11,"./T":12,"./TR":13,"./TS":14,"./TSR":15,"./X":16,"./Y":17}],19:[function(require,module,exports){exports.estimate=require("./estimate"),exports.estimators=require("./estimators"),exports.point=require("./point"),exports.transform=require("./transform"),exports.analysis=require("./analysis"),exports.tolerance=require("./tolerance"),exports.version=require("./version")},{"./analysis":2,"./estimate":6,"./estimators":18,"./point":25,"./tolerance":32,"./transform":46,"./version":58}],20:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(p,q,tolerance){"number"!=typeof tolerance&&(tolerance=TOLERANCE);const dx=Math.abs(p.x-q.x),dy=Math.abs(p.y-q.y);return dx<=tolerance&&dy<=tolerance}},{"../tolerance":32}],21:[function(require,module,exports){module.exports=(x,y)=>({x:x,y:y})},{}],22:[function(require,module,exports){module.exports=(p,q)=>{const dx=p.x-q.x,dy=p.y-q.y;return Math.sqrt(dx*dx+dy*dy)}},{}],23:[function(require,module,exports){module.exports=(p,q)=>p.x===q.x&&p.y===q.y},{}],24:[function(require,module,exports){module.exports=arrp=>{if(2!==arrp.length)throw new Error("Cannot read a point from array: "+JSON.stringify(arrp));return{x:arrp[0],y:arrp[1]}}},{}],25:[function(require,module,exports){exports.almostEqual=require("./almostEqual"),exports.create=require("./create"),exports.distance=require("./distance"),exports.equal=require("./equal"),exports.fromArray=require("./fromArray"),exports.offset=require("./offset"),exports.polarOffset=require("./polarOffset"),exports.toArray=require("./toArray"),exports.transform=require("./transform"),exports.transformMany=require("./transformMany"),exports.validate=require("./validate")},{"./almostEqual":20,"./create":21,"./distance":22,"./equal":23,"./fromArray":24,"./offset":26,"./polarOffset":27,"./toArray":28,"./transform":29,"./transformMany":30,"./validate":31}],26:[function(require,module,exports){module.exports=(p,dx,dy)=>({x:p.x+dx,y:p.y+dy})},{}],27:[function(require,module,exports){module.exports=(p,distance,angle)=>({x:p.x+distance*Math.cos(angle),y:p.y+distance*Math.sin(angle)})},{}],28:[function(require,module,exports){module.exports=p=>[p.x,p.y]},{}],29:[function(require,module,exports){module.exports=function(p,tr){return{x:tr.a*p.x-tr.b*p.y+tr.x,y:tr.b*p.x+tr.a*p.y+tr.y}}},{}],30:[function(require,module,exports){const transform=require("./transform");module.exports=(points,tr)=>{if(!Array.isArray(points)){throw TypeError("Expected an array but saw "+typeof points+" instead.")}const ps=[];for(let i=0;i<points.length;i+=1)ps.push(transform(points[i],tr));return ps}},{"./transform":29}],31:[function(require,module,exports){module.exports=p=>!("number"!=typeof p.x||!Number.isFinite(p.x))&&!("number"!=typeof p.y||!Number.isFinite(p.y))},{}],32:[function(require,module,exports){module.exports=1e-10},{}],33:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(tr,ts,tolerance){"number"!=typeof tolerance&&(tolerance=TOLERANCE);return Math.abs(tr.a-ts.a)+Math.abs(tr.b-ts.b)+Math.abs(tr.x-ts.x)+Math.abs(tr.y-ts.y)<=tolerance}},{"../tolerance":32}],34:[function(require,module,exports){module.exports=function(tr,ts){return{a:tr.a*ts.a-tr.b*ts.b,b:tr.a*ts.b+tr.b*ts.a,x:tr.a*ts.x-tr.b*ts.y+tr.x,y:tr.b*ts.x+tr.a*ts.y+tr.y}}},{}],35:[function(require,module,exports){module.exports=function(a,b,x,y){return{a:a,b:b,x:x,y:y}}},{}],36:[function(require,module,exports){module.exports=function(tr,ts){return tr.a===ts.a&&tr.b===ts.b&&tr.x===ts.x&&tr.y===ts.y}},{}],37:[function(require,module,exports){module.exports=arrtr=>({a:arrtr[0],b:arrtr[1],x:arrtr[2],y:arrtr[3]})},{}],38:[function(require,module,exports){module.exports=function(center,scale,rotation){const cx=center.x,cy=center.y,m=scale;if(m<0){throw new Error("Expected zero or positive scale factor but negative: "+m)}const co=Math.cos(rotation),si=Math.sin(rotation);return{a:m*co,b:m*si,x:m*(-cx*co+cy*si+cx)+(1-m)*cx,y:m*(-cx*si-cy*co+cy)+(1-m)*cy}}},{}],39:[function(require,module,exports){module.exports=function(center,radians){const co=Math.cos(radians),si=Math.sin(radians),cx=center.x,cy=center.y;return{a:co,b:si,x:-cx*co+cy*si+cx,y:-cx*si-cy*co+cy}}},{}],40:[function(require,module,exports){module.exports=function(center,multiplier){const cx=center.x,cy=center.y,m=multiplier;if(m<0){throw new Error("Expected zero or positive scale factor but saw negative: "+m)}return{a:m,b:0,x:(1-m)*cx,y:(1-m)*cy}}},{}],41:[function(require,module,exports){const cssMatrix=/\s*matrix\(([-+\w ,.%]+)\)/,cssMatrixDelimiter=/\s*,\s*/;module.exports=function(str){const matrixMatch=str.match(cssMatrix);if(!matrixMatch)throw new Error("Invalid CSS matrix string: "+str);const elems=matrixMatch[1].split(cssMatrixDelimiter).map((els=>parseFloat(els)));return{a:elems[0],b:elems[1],x:elems[4],y:elems[5]}}},{}],42:[function(require,module,exports){module.exports=function(p){return{a:1,b:0,x:p.x,y:p.y}}},{}],43:[function(require,module,exports){module.exports=function(tr){return Math.atan2(tr.b,tr.a)}},{}],44:[function(require,module,exports){module.exports=function(tr){return Math.sqrt(tr.b*tr.b+tr.a*tr.a)}},{}],45:[function(require,module,exports){module.exports=function(tr){return{x:tr.x,y:tr.y}}},{}],46:[function(require,module,exports){exports.SINGULAR={a:0,b:0,x:0,y:0},exports.IDENTITY={a:1,b:0,x:0,y:0};const isqrt2=1/Math.sqrt(2);exports.ROT45={a:isqrt2,b:isqrt2,x:0,y:0},exports.ROT90={a:0,b:1,x:0,y:0},exports.ROT180={a:-1,b:0,x:0,y:0},exports.ROT270={a:0,b:-1,x:0,y:0},exports.HALF={a:.5,b:0,x:0,y:0},exports.X2={a:2,b:0,x:0,y:0},exports.almostEqual=require("./almostEqual"),exports.compose=require("./compose"),exports.create=require("./create"),exports.equal=require("./equal"),exports.fromArray=require("./fromArray"),exports.fromPolar=require("./fromPolar"),exports.fromRotation=require("./fromRotation"),exports.fromScale=require("./fromScale"),exports.fromString=require("./fromString"),exports.fromTranslation=require("./fromTranslation"),exports.getRotation=require("./getRotation"),exports.getScale=require("./getScale"),exports.getTranslation=require("./getTranslation"),exports.multiply=exports.compose,exports.inverse=require("./inverse"),exports.rotateBy=require("./rotateBy"),exports.rotateTo=require("./rotateTo"),exports.scaleBy=require("./scaleBy"),exports.scaleTo=require("./scaleTo"),exports.toArray=require("./toArray"),exports.toMatrix=require("./toMatrix"),exports.toString=require("./toString"),exports.translateBy=require("./translateBy"),exports.translateTo=require("./translateTo"),exports.validate=require("./validate")},{"./almostEqual":33,"./compose":34,"./create":35,"./equal":36,"./fromArray":37,"./fromPolar":38,"./fromRotation":39,"./fromScale":40,"./fromString":41,"./fromTranslation":42,"./getRotation":43,"./getScale":44,"./getTranslation":45,"./inverse":47,"./rotateBy":48,"./rotateTo":49,"./scaleBy":50,"./scaleTo":51,"./toArray":52,"./toMatrix":53,"./toString":54,"./translateBy":55,"./translateTo":56,"./validate":57}],47:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(tr){const det=tr.a*tr.a+tr.b*tr.b;if(Math.abs(det)<TOLERANCE)throw new Error("Singular transformations cannot be inversed.");return{a:tr.a/det,b:-tr.b/det,x:(-tr.a*tr.x-tr.b*tr.y)/det,y:(tr.b*tr.x-tr.a*tr.y)/det}}},{"../tolerance":32}],48:[function(require,module,exports){module.exports=function(tr,center,radians){const co=Math.cos(radians),si=Math.sin(radians),cx=center.x,cy=center.y;return{a:tr.a*co-tr.b*si,b:tr.a*si+tr.b*co,x:(tr.x-cx)*co-(tr.y-cy)*si+cx,y:(tr.x-cx)*si+(tr.y-cy)*co+cy}}},{}],49:[function(require,module,exports){const rotateBy=require("./rotateBy");module.exports=function(tr,center,radians){const r=Math.atan2(tr.b,tr.a);return rotateBy(tr,center,radians-r)}},{"./rotateBy":48}],50:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(tr,center,multiplier){const m=multiplier,cx=center.x,cy=center.y;if(m<TOLERANCE){throw new Error("Expected positive scale factor but saw zero or negative: "+m)}return{a:m*tr.a,b:m*tr.b,x:m*tr.x+(1-m)*cx,y:m*tr.y+(1-m)*cy}}},{"../tolerance":32}],51:[function(require,module,exports){const scaleBy=require("./scaleBy"),TOLERANCE=require("../tolerance");module.exports=function(tr,center,scale){const orig=Math.sqrt(tr.a*tr.a+tr.b*tr.b);if(orig<TOLERANCE)throw new Error("Cannot scale singular transformation");return scaleBy(tr,center,scale/orig)}},{"../tolerance":32,"./scaleBy":50}],52:[function(require,module,exports){module.exports=function(tr){return[tr.a,tr.b,tr.x,tr.y]}},{}],53:[function(require,module,exports){module.exports=function(tr){return{a:tr.a,b:tr.b,c:-tr.b,d:tr.a,e:tr.x,f:tr.y}}},{}],54:[function(require,module,exports){module.exports=function(tr){const a=tr.a.toFixed(8);return"matrix("+a+","+tr.b.toFixed(8)+","+(-tr.b).toFixed(8)+","+a+","+tr.x.toFixed(8)+","+tr.y.toFixed(8)+")"}},{}],55:[function(require,module,exports){module.exports=function(tr,vec){return{a:tr.a,b:tr.b,x:tr.x+vec.x,y:tr.y+vec.y}}},{}],56:[function(require,module,exports){module.exports=function(tr,point){return{a:tr.a,b:tr.b,x:point.x,y:point.y}}},{}],57:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=tr=>"number"==typeof tr.a&&("number"==typeof tr.b&&("number"==typeof tr.x&&("number"==typeof tr.y&&!(tr.a*tr.a+tr.b*tr.b<TOLERANCE))))},{"../tolerance":32}],58:[function(require,module,exports){module.exports="2.1.0"},{}]},{},[1])(1)})); | ||
!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).nudged=f()}}((function(){return function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,(function(r){return o(e[i][1][r]||r)}),p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(require,module,exports){module.exports=require("./lib/index")},{"./lib/index":19}],2:[function(require,module,exports){exports.mse=require("./mse"),exports.residuals=require("./residuals"),exports.rss=require("./rss")},{"./mse":3,"./residuals":4,"./rss":5}],3:[function(require,module,exports){const transformMany=require("../point/transformMany");module.exports=(tr,domain,range)=>{const n=Math.min(domain.length,range.length),codomain=transformMany(domain,tr);let dx,dy,sum=0;for(let i=0;i<n;i+=1)dx=codomain[i].x-range[i].x,dy=codomain[i].y-range[i].y,sum+=dx*dx+dy*dy;return sum/n}},{"../point/transformMany":30}],4:[function(require,module,exports){const distance=require("../point/distance"),transformMany=require("../point/transformMany");module.exports=(tr,domain,range)=>{const n=Math.min(domain.length,range.length),codomain=transformMany(domain,tr),arr=[];for(let i=0;i<n;i+=1)arr.push(distance(codomain[i],range[i]));return arr}},{"../point/distance":22,"../point/transformMany":30}],5:[function(require,module,exports){const transformMany=require("../point/transformMany");module.exports=(tr,domain,range)=>{const n=Math.min(domain.length,range.length),codomain=transformMany(domain,tr);let dx,dy,sum=0;for(let i=0;i<n;i+=1)dx=codomain[i].x-range[i].x,dy=codomain[i].y-range[i].y,sum+=dx*dx+dy*dy;return sum}},{"../point/transformMany":30}],6:[function(require,module,exports){const es=require("./estimators");module.exports=function(params){if(!params.estimator)throw new Error("Unexpected estimator type: "+params.estimator);switch(params.estimator.toUpperCase()){case"I":return es.I();case"L":return es.L(params.domain,params.range,params.angle);case"X":return es.X(params.domain,params.range);case"Y":return es.Y(params.domain,params.range);case"T":return es.T(params.domain,params.range);case"S":return es.S(params.domain,params.range,params.center);case"R":return es.R(params.domain,params.range,params.center);case"TS":return es.TS(params.domain,params.range);case"TR":return es.TR(params.domain,params.range);case"SR":return es.SR(params.domain,params.range,params.center);case"TSR":return es.TSR(params.domain,params.range);default:throw new Error("Unexpected estimator type: "+params.estimator)}}},{"./estimators":18}],7:[function(require,module,exports){module.exports=function(domain,range){return{a:1,b:0,x:0,y:0}}},{}],8:[function(require,module,exports){module.exports=function(domain,range,angle){const N=Math.min(domain.length,range.length);let a=0,b=0,c=0,d=0;const co=Math.cos(angle),si=Math.sin(angle);if(N<1)return{a:1,b:0,x:0,y:0};for(let i=0;i<N;i+=1)a+=domain[i].x,b+=domain[i].y,c+=range[i].x,d+=range[i].y;const t=(co*(c-a)+si*(d-b))/N;return{a:1,b:0,x:t*co,y:t*si}}},{}],9:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range,center){const N=Math.min(domain.length,range.length);let ac=0,ad=0,bc=0,bd=0;const cx=center.x,cy=center.y;let i,a,b,c,d;for(i=0;i<N;i+=1)a=domain[i].x-cx,b=domain[i].y-cy,c=range[i].x-cx,d=range[i].y-cy,ac+=a*c,ad+=a*d,bc+=b*c,bd+=b*d;const p=ac+bd,q=ad-bc,det=p*p+q*q;if(det<TOLERANCE)return{a:1,b:0,x:0,y:0};const den=Math.sqrt(det),ahat=p/den,bhat=q/den;return{a:ahat,b:bhat,x:cx-cx*ahat+cy*bhat,y:cy-cx*bhat-cy*ahat}}},{"../tolerance":32}],10:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range,center){const N=Math.min(domain.length,range.length);let ac=0,bd=0,aa=0,bb=0;const cx=center.x,cy=center.y;let i,a,b,c,d;for(i=0;i<N;i+=1)a=domain[i].x-cx,b=domain[i].y-cy,c=range[i].x-cx,d=range[i].y-cy,ac+=a*c,bd+=b*d,aa+=a*a,bb+=b*b;const det=aa+bb;if(Math.abs(det)<TOLERANCE)return{a:1,b:0,x:0,y:0};const ahat=Math.max(0,(ac+bd)/det);return{a:ahat,b:0,x:(1-ahat)*cx,y:(1-ahat)*cy}}},{"../tolerance":32}],11:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range,center){const N=Math.min(domain.length,range.length),cx=center.x,cy=center.y;let i,a,b,c,d,a2=0,b2=0,ac=0,bd=0,bc=0,ad=0;for(i=0;i<N;i+=1)a=domain[i].x-cx,b=domain[i].y-cy,c=range[i].x-cx,d=range[i].y-cy,a2+=a*a,b2+=b*b,ac+=a*c,bd+=b*d,bc+=b*c,ad+=a*d;const det=a2+b2;if(Math.abs(det)<TOLERANCE)return{a:1,b:0,x:0,y:0};const ahat=(ac+bd)/det,bhat=(-bc+ad)/det;return{a:ahat,b:bhat,x:cy*bhat-cx*ahat+cx,y:-cx*bhat-cy*ahat+cy}}},{"../tolerance":32}],12:[function(require,module,exports){module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(N<1)return{a:1,b:0,x:0,y:0};let dxs=0,dys=0,rxs=0,rys=0;for(let i=0;i<N;i+=1)dxs+=domain[i].x,dys+=domain[i].y,rxs+=range[i].x,rys+=range[i].y;return{a:1,b:0,x:(rxs-dxs)/N,y:(rys-dys)/N}}},{}],13:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(0===N)return{a:1,b:0,x:0,y:0};if(1===N){return{a:1,b:0,x:range[0].x-domain[0].x,y:range[0].y-domain[0].y}}let i,a,b,c,d,asum=0,bsum=0,csum=0,dsum=0,ac=0,ad=0,bc=0,bd=0;for(i=0;i<N;i+=1)a=domain[i].x,b=domain[i].y,c=range[i].x,d=range[i].y,asum+=a,bsum+=b,csum+=c,dsum+=d,ac+=a*c,ad+=a*d,bc+=b*c,bd+=b*d;const v=N*ac-asum*csum+(N*bd-bsum*dsum),w=N*ad-asum*dsum+(bsum*csum-N*bc),det=v*v+w*w;if(det<TOLERANCE)return{a:1,b:0,x:(csum-asum)/N,y:(dsum-bsum)/N};const den=Math.sqrt(det),ahat=v/den,bhat=w/den;return{a:ahat,b:bhat,x:(-asum*ahat+bsum*bhat+csum)/N,y:(-asum*bhat-bsum*ahat+dsum)/N}}},{"../tolerance":32}],14:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(0===N)return{a:1,b:0,x:0,y:0};if(1===N){return{a:1,b:0,x:range[0].x-domain[0].x,y:range[0].y-domain[0].y}}let i,a,b,c,d,a1=0,b1=0,c1=0,d1=0,a2=0,b2=0,ac=0,bd=0;for(i=0;i<N;i+=1)a=domain[i].x,b=domain[i].y,c=range[i].x,d=range[i].y,a1+=a,b1+=b,c1+=c,d1+=d,a2+=a*a,b2+=b*b,ac+=a*c,bd+=b*d;const N2=N*N,a12=a1*a1,b12=b1*b1,det=N2*a2-N*a12+N2*b2-N*b12;if(Math.abs(det)<TOLERANCE)return 0===N?{a:1,b:0,x:0,y:0}:{a:1,b:0,x:c1/N-a,y:d1/N-b};const p=a2+b2,q=ac+bd;return{a:(N2*q-N*(a1*c1+b1*d1))/det,b:0,x:(-N*a1*q+N*c1*p-b12*c1+a1*b1*d1)/det,y:(-N*b1*q+N*d1*p-a12*d1+a1*b1*c1)/det}}},{"../tolerance":32}],15:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(0===N)return{a:1,b:0,x:0,y:0};if(1===N){return{a:1,b:0,x:range[0].x-domain[0].x,y:range[0].y-domain[0].y}}let i,a,b,c,d,a1=0,b1=0,c1=0,d1=0,a2=0,b2=0,ad=0,bc=0,ac=0,bd=0;for(i=0;i<N;i+=1)a=domain[i].x,b=domain[i].y,c=range[i].x,d=range[i].y,a1+=a,b1+=b,c1+=c,d1+=d,a2+=a*a,b2+=b*b,ad+=a*d,bc+=b*c,ac+=a*c,bd+=b*d;const det=N*a2-a1*a1+N*b2-b1*b1;if(Math.abs(det)<TOLERANCE)return{a:1,b:0,x:c1/N-a,y:d1/N-b};return{a:(N*(ac+bd)-a1*c1-b1*d1)/det,b:(N*(ad-bc)+b1*c1-a1*d1)/det,x:(-a1*(ac+bd)+b1*(ad-bc)+a2*c1+b2*c1)/det,y:(-b1*(ac+bd)-a1*(ad-bc)+a2*d1+b2*d1)/det}}},{"../tolerance":32}],16:[function(require,module,exports){module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(N<1)return{a:1,b:0,x:0,y:0};let dxs=0,rxs=0;for(let i=0;i<N;i+=1)dxs+=domain[i].x,rxs+=range[i].x;return{a:1,b:0,x:(rxs-dxs)/N,y:0}}},{}],17:[function(require,module,exports){module.exports=function(domain,range){const N=Math.min(domain.length,range.length);if(N<1)return{a:1,b:0,x:0,y:0};let dys=0,rys=0;for(let i=0;i<N;i+=1)dys+=domain[i].y,rys+=range[i].y;return{a:1,b:0,x:0,y:(rys-dys)/N}}},{}],18:[function(require,module,exports){exports.I=require("./I"),exports.L=require("./L"),exports.X=require("./X"),exports.Y=require("./Y"),exports.T=require("./T"),exports.S=require("./S"),exports.R=require("./R"),exports.TS=require("./TS"),exports.TR=require("./TR"),exports.SR=require("./SR"),exports.TSR=require("./TSR")},{"./I":7,"./L":8,"./R":9,"./S":10,"./SR":11,"./T":12,"./TR":13,"./TS":14,"./TSR":15,"./X":16,"./Y":17}],19:[function(require,module,exports){exports.estimate=require("./estimate"),exports.estimators=require("./estimators"),exports.point=require("./point"),exports.transform=require("./transform"),exports.analysis=require("./analysis"),exports.tolerance=require("./tolerance"),exports.version=require("./version")},{"./analysis":2,"./estimate":6,"./estimators":18,"./point":25,"./tolerance":32,"./transform":46,"./version":58}],20:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(p,q,tolerance){"number"!=typeof tolerance&&(tolerance=TOLERANCE);const dx=Math.abs(p.x-q.x),dy=Math.abs(p.y-q.y);return dx<=tolerance&&dy<=tolerance}},{"../tolerance":32}],21:[function(require,module,exports){module.exports=(x,y)=>({x:x,y:y})},{}],22:[function(require,module,exports){module.exports=(p,q)=>{const dx=p.x-q.x,dy=p.y-q.y;return Math.sqrt(dx*dx+dy*dy)}},{}],23:[function(require,module,exports){module.exports=(p,q)=>p.x===q.x&&p.y===q.y},{}],24:[function(require,module,exports){module.exports=arrp=>{if(2!==arrp.length)throw new Error("Cannot read a point from array: "+JSON.stringify(arrp));return{x:arrp[0],y:arrp[1]}}},{}],25:[function(require,module,exports){exports.almostEqual=require("./almostEqual"),exports.create=require("./create"),exports.distance=require("./distance"),exports.equal=require("./equal"),exports.fromArray=require("./fromArray"),exports.offset=require("./offset"),exports.polarOffset=require("./polarOffset"),exports.toArray=require("./toArray"),exports.transform=require("./transform"),exports.transformMany=require("./transformMany"),exports.validate=require("./validate")},{"./almostEqual":20,"./create":21,"./distance":22,"./equal":23,"./fromArray":24,"./offset":26,"./polarOffset":27,"./toArray":28,"./transform":29,"./transformMany":30,"./validate":31}],26:[function(require,module,exports){module.exports=(p,dx,dy)=>({x:p.x+dx,y:p.y+dy})},{}],27:[function(require,module,exports){module.exports=(p,distance,angle)=>({x:p.x+distance*Math.cos(angle),y:p.y+distance*Math.sin(angle)})},{}],28:[function(require,module,exports){module.exports=p=>[p.x,p.y]},{}],29:[function(require,module,exports){module.exports=function(p,tr){return{x:tr.a*p.x-tr.b*p.y+tr.x,y:tr.b*p.x+tr.a*p.y+tr.y}}},{}],30:[function(require,module,exports){const transform=require("./transform");module.exports=(points,tr)=>{if(!Array.isArray(points)){throw TypeError("Expected an array but saw "+typeof points+" instead.")}const ps=[];for(let i=0;i<points.length;i+=1)ps.push(transform(points[i],tr));return ps}},{"./transform":29}],31:[function(require,module,exports){module.exports=p=>!("number"!=typeof p.x||!Number.isFinite(p.x))&&!("number"!=typeof p.y||!Number.isFinite(p.y))},{}],32:[function(require,module,exports){module.exports=1e-10},{}],33:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(tr,ts,tolerance){"number"!=typeof tolerance&&(tolerance=TOLERANCE);return Math.abs(tr.a-ts.a)+Math.abs(tr.b-ts.b)+Math.abs(tr.x-ts.x)+Math.abs(tr.y-ts.y)<=tolerance}},{"../tolerance":32}],34:[function(require,module,exports){module.exports=function(tr,ts){return{a:tr.a*ts.a-tr.b*ts.b,b:tr.a*ts.b+tr.b*ts.a,x:tr.a*ts.x-tr.b*ts.y+tr.x,y:tr.b*ts.x+tr.a*ts.y+tr.y}}},{}],35:[function(require,module,exports){module.exports=function(a,b,x,y){return{a:a,b:b,x:x,y:y}}},{}],36:[function(require,module,exports){module.exports=function(tr,ts){return tr.a===ts.a&&tr.b===ts.b&&tr.x===ts.x&&tr.y===ts.y}},{}],37:[function(require,module,exports){module.exports=arrtr=>({a:arrtr[0],b:arrtr[1],x:arrtr[2],y:arrtr[3]})},{}],38:[function(require,module,exports){module.exports=function(center,scale,rotation){const cx=center.x,cy=center.y,m=scale;if(m<0){throw new Error("Expected zero or positive scale factor but negative: "+m)}const co=Math.cos(rotation),si=Math.sin(rotation);return{a:m*co,b:m*si,x:m*(-cx*co+cy*si+cx)+(1-m)*cx,y:m*(-cx*si-cy*co+cy)+(1-m)*cy}}},{}],39:[function(require,module,exports){module.exports=function(center,radians){const co=Math.cos(radians),si=Math.sin(radians),cx=center.x,cy=center.y;return{a:co,b:si,x:-cx*co+cy*si+cx,y:-cx*si-cy*co+cy}}},{}],40:[function(require,module,exports){module.exports=function(center,multiplier){const cx=center.x,cy=center.y,m=multiplier;if(m<0){throw new Error("Expected zero or positive scale factor but saw negative: "+m)}return{a:m,b:0,x:(1-m)*cx,y:(1-m)*cy}}},{}],41:[function(require,module,exports){const cssMatrix=/\s*matrix\(([-+\w ,.%]+)\)/,cssMatrixDelimiter=/\s*,\s*/;module.exports=function(str){const matrixMatch=str.match(cssMatrix);if(!matrixMatch)throw new Error("Invalid CSS matrix string: "+str);const elems=matrixMatch[1].split(cssMatrixDelimiter).map((els=>parseFloat(els)));return{a:elems[0],b:elems[1],x:elems[4],y:elems[5]}}},{}],42:[function(require,module,exports){module.exports=function(p){return{a:1,b:0,x:p.x,y:p.y}}},{}],43:[function(require,module,exports){module.exports=function(tr){return Math.atan2(tr.b,tr.a)}},{}],44:[function(require,module,exports){module.exports=function(tr){return Math.sqrt(tr.b*tr.b+tr.a*tr.a)}},{}],45:[function(require,module,exports){module.exports=function(tr){return{x:tr.x,y:tr.y}}},{}],46:[function(require,module,exports){exports.SINGULAR={a:0,b:0,x:0,y:0},exports.IDENTITY={a:1,b:0,x:0,y:0};const isqrt2=1/Math.sqrt(2);exports.ROT45={a:isqrt2,b:isqrt2,x:0,y:0},exports.ROT90={a:0,b:1,x:0,y:0},exports.ROT180={a:-1,b:0,x:0,y:0},exports.ROT270={a:0,b:-1,x:0,y:0},exports.HALF={a:.5,b:0,x:0,y:0},exports.X2={a:2,b:0,x:0,y:0},exports.almostEqual=require("./almostEqual"),exports.compose=require("./compose"),exports.create=require("./create"),exports.equal=require("./equal"),exports.fromArray=require("./fromArray"),exports.fromPolar=require("./fromPolar"),exports.fromRotation=require("./fromRotation"),exports.fromScale=require("./fromScale"),exports.fromString=require("./fromString"),exports.fromTranslation=require("./fromTranslation"),exports.getRotation=require("./getRotation"),exports.getScale=require("./getScale"),exports.getTranslation=require("./getTranslation"),exports.multiply=exports.compose,exports.inverse=require("./inverse"),exports.rotateBy=require("./rotateBy"),exports.rotateTo=require("./rotateTo"),exports.scaleBy=require("./scaleBy"),exports.scaleTo=require("./scaleTo"),exports.toArray=require("./toArray"),exports.toMatrix=require("./toMatrix"),exports.toString=require("./toString"),exports.translateBy=require("./translateBy"),exports.translateTo=require("./translateTo"),exports.validate=require("./validate")},{"./almostEqual":33,"./compose":34,"./create":35,"./equal":36,"./fromArray":37,"./fromPolar":38,"./fromRotation":39,"./fromScale":40,"./fromString":41,"./fromTranslation":42,"./getRotation":43,"./getScale":44,"./getTranslation":45,"./inverse":47,"./rotateBy":48,"./rotateTo":49,"./scaleBy":50,"./scaleTo":51,"./toArray":52,"./toMatrix":53,"./toString":54,"./translateBy":55,"./translateTo":56,"./validate":57}],47:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(tr){const det=tr.a*tr.a+tr.b*tr.b;if(Math.abs(det)<TOLERANCE)throw new Error("Singular transformations cannot be inversed.");return{a:tr.a/det,b:-tr.b/det,x:(-tr.a*tr.x-tr.b*tr.y)/det,y:(tr.b*tr.x-tr.a*tr.y)/det}}},{"../tolerance":32}],48:[function(require,module,exports){module.exports=function(tr,center,radians){const co=Math.cos(radians),si=Math.sin(radians),cx=center.x,cy=center.y;return{a:tr.a*co-tr.b*si,b:tr.a*si+tr.b*co,x:(tr.x-cx)*co-(tr.y-cy)*si+cx,y:(tr.x-cx)*si+(tr.y-cy)*co+cy}}},{}],49:[function(require,module,exports){const rotateBy=require("./rotateBy");module.exports=function(tr,center,radians){const r=Math.atan2(tr.b,tr.a);return rotateBy(tr,center,radians-r)}},{"./rotateBy":48}],50:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=function(tr,center,multiplier){const m=multiplier,cx=center.x,cy=center.y;if(m<TOLERANCE){throw new Error("Expected positive scale factor but saw zero or negative: "+m)}return{a:m*tr.a,b:m*tr.b,x:m*tr.x+(1-m)*cx,y:m*tr.y+(1-m)*cy}}},{"../tolerance":32}],51:[function(require,module,exports){const scaleBy=require("./scaleBy"),TOLERANCE=require("../tolerance");module.exports=function(tr,center,scale){const orig=Math.sqrt(tr.a*tr.a+tr.b*tr.b);if(orig<TOLERANCE)throw new Error("Cannot scale singular transformation");return scaleBy(tr,center,scale/orig)}},{"../tolerance":32,"./scaleBy":50}],52:[function(require,module,exports){module.exports=function(tr){return[tr.a,tr.b,tr.x,tr.y]}},{}],53:[function(require,module,exports){module.exports=function(tr){return{a:tr.a,b:tr.b,c:-tr.b,d:tr.a,e:tr.x,f:tr.y}}},{}],54:[function(require,module,exports){module.exports=function(tr){const a=tr.a.toFixed(8);return"matrix("+a+","+tr.b.toFixed(8)+","+(-tr.b).toFixed(8)+","+a+","+tr.x.toFixed(8)+","+tr.y.toFixed(8)+")"}},{}],55:[function(require,module,exports){module.exports=function(tr,vec){return{a:tr.a,b:tr.b,x:tr.x+vec.x,y:tr.y+vec.y}}},{}],56:[function(require,module,exports){module.exports=function(tr,point){return{a:tr.a,b:tr.b,x:point.x,y:point.y}}},{}],57:[function(require,module,exports){const TOLERANCE=require("../tolerance");module.exports=tr=>"number"==typeof tr.a&&("number"==typeof tr.b&&("number"==typeof tr.x&&("number"==typeof tr.y&&!(tr.a*tr.a+tr.b*tr.b<TOLERANCE))))},{"../tolerance":32}],58:[function(require,module,exports){module.exports="2.1.1"},{}]},{},[1])(1)})); |
{ | ||
"name": "nudged", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Affine transformation estimator e.g. for multi-touch gestures and calibration", | ||
@@ -30,3 +30,7 @@ "keywords": [ | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"lib", | ||
"CHANGELOG.md", | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
@@ -33,0 +37,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
108881
64
2178
1