transformation-matrix
Advanced tools
Comparing version 1.15.1 to 1.15.2
@@ -161,2 +161,26 @@ 'use strict'; | ||
}); | ||
}); | ||
var _fromTriangles = require('./fromTriangles'); | ||
Object.keys(_fromTriangles).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _fromTriangles[key]; | ||
} | ||
}); | ||
}); | ||
var _smoothMatrix = require('./smoothMatrix'); | ||
Object.keys(_smoothMatrix).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _smoothMatrix[key]; | ||
} | ||
}); | ||
}); |
@@ -13,2 +13,4 @@ export * from './applyToPoint'; | ||
export * from './transform'; | ||
export * from './translate'; | ||
export * from './translate'; | ||
export * from './fromTriangles'; | ||
export * from './smoothMatrix'; |
@@ -456,2 +456,75 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
} | ||
// CONCATENATED MODULE: ./src/smoothMatrix.js | ||
/** | ||
* Rounds all elements of the given matrix using the given precision | ||
* @param m {{a: number, b: number, c: number, d: number, e: number, f: number}} a matrix to round | ||
* @param [precision] a precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | ||
* @returns {{a: number, b: number, c: number, d: number, e: number, f: number}} the rounded matrix | ||
*/ | ||
function smoothMatrix(m) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10000000000; | ||
return { | ||
a: Math.round(m.a * precision) / precision, | ||
b: Math.round(m.b * precision) / precision, | ||
c: Math.round(m.c * precision) / precision, | ||
d: Math.round(m.d * precision) / precision, | ||
e: Math.round(m.e * precision) / precision, | ||
f: Math.round(m.f * precision) / precision | ||
}; | ||
} | ||
// CONCATENATED MODULE: ./src/fromTriangles.js | ||
/** | ||
* Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible. | ||
* @param t1 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the first triangle | ||
* @param t2 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the second triangle | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix which transforms t1 to t2 | ||
* @throws Exception if the matrix becomes not invertible | ||
*/ | ||
function fromTriangles(t1, t2) { | ||
// point p = first point of the triangle | ||
var px1 = t1[0].x != null ? t1[0].x : t1[0][0]; | ||
var py1 = t1[0].y != null ? t1[0].y : t1[0][1]; | ||
var px2 = t2[0].x != null ? t2[0].x : t2[0][0]; | ||
var py2 = t2[0].y != null ? t2[0].y : t2[0][1]; | ||
// point q = second point of the triangle | ||
var qx1 = t1[1].x != null ? t1[1].x : t1[1][0]; | ||
var qy1 = t1[1].y != null ? t1[1].y : t1[1][1]; | ||
var qx2 = t2[1].x != null ? t2[1].x : t2[1][0]; | ||
var qy2 = t2[1].y != null ? t2[1].y : t2[1][1]; | ||
// point r = third point of the triangle | ||
var rx1 = t1[2].x != null ? t1[2].x : t1[2][0]; | ||
var ry1 = t1[2].y != null ? t1[2].y : t1[2][1]; | ||
var rx2 = t2[2].x != null ? t2[2].x : t2[2][0]; | ||
var ry2 = t2[2].y != null ? t2[2].y : t2[2][1]; | ||
var r1 = { | ||
a: px1 - rx1, | ||
b: py1 - ry1, | ||
c: qx1 - rx1, | ||
d: qy1 - ry1, | ||
e: rx1, | ||
f: ry1 | ||
}; | ||
var r2 = { | ||
a: px2 - rx2, | ||
b: py2 - ry2, | ||
c: qx2 - rx2, | ||
d: qy2 - ry2, | ||
e: rx2, | ||
f: ry2 | ||
}; | ||
var inverseR1 = inverse(r1); | ||
var affineMatrix = transform([r2, inverseR1]); | ||
// round the matrix elements to smooth the finite inversion | ||
return smoothMatrix(affineMatrix); | ||
} | ||
// CONCATENATED MODULE: ./src/index.js | ||
@@ -477,2 +550,4 @@ /* concated harmony reexport applyToPoint */__webpack_require__.d(__webpack_exports__, "applyToPoint", function() { return applyToPoint; }); | ||
/* concated harmony reexport translate */__webpack_require__.d(__webpack_exports__, "translate", function() { return translate; }); | ||
/* concated harmony reexport fromTriangles */__webpack_require__.d(__webpack_exports__, "fromTriangles", function() { return fromTriangles; }); | ||
/* concated harmony reexport smoothMatrix */__webpack_require__.d(__webpack_exports__, "smoothMatrix", function() { return smoothMatrix; }); | ||
@@ -492,2 +567,4 @@ | ||
/***/ }) | ||
@@ -494,0 +571,0 @@ /******/ ]); |
@@ -1,2 +0,2 @@ | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.TransformationMatrix=n():r.TransformationMatrix=n()}(window,function(){return function(r){var n={};function t(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=n,t.d=function(r,n,e){t.o(r,n)||Object.defineProperty(r,n,{enumerable:!0,get:e})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,n){if(1&n&&(r=t(r)),8&n)return r;if(4&n&&"object"==typeof r&&r&&r.__esModule)return r;var e=Object.create(null);if(t.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:r}),2&n&&"string"!=typeof r)for(var o in r)t.d(e,o,function(n){return r[n]}.bind(null,o));return e},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},t.p="",t(t.s=0)}([function(r,n,t){"use strict";function e(r,n){return Array.isArray(n)?[r.a*n[0]+r.c*n[1]+r.e,r.b*n[0]+r.d*n[1]+r.f]:{x:r.a*n.x+r.c*n.y+r.e,y:r.b*n.x+r.d*n.y+r.f}}function o(r,n){return n.map(function(n){return e(r,n)})}function u(r){return{a:parseFloat(r.a),b:parseFloat(r.b),c:parseFloat(r.c),d:parseFloat(r.d),e:parseFloat(r.e),f:parseFloat(r.f)}}t.r(n);var a=/^matrix\(\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*\)$/i;function i(r){var n=r.match(a);if(null===n||n.length<7)throw new Error("'"+r+"' is not a matrix");return{a:parseFloat(n[1]),b:parseFloat(n[2]),c:parseFloat(n[3]),d:parseFloat(n[4]),e:parseFloat(n[5]),f:parseFloat(n[6])}}function f(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function c(r){var n=r.a,t=r.b,e=r.c,o=r.d,u=r.e,a=r.f,i=n*o-t*e;return{a:o/i,b:t/-i,c:e/-i,d:n/i,e:(o*u-e*a)/-i,f:(t*u-n*a)/i}}var d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},s=function(r){return"number"==typeof r&&!isNaN(r)&&isFinite(r)},l=function(r){return null!=r&&"object"===(void 0===r?"undefined":d(r))};function p(r){return l(r)&&r.hasOwnProperty("a")&&s(r.a)&&r.hasOwnProperty("b")&&s(r.b)&&r.hasOwnProperty("c")&&s(r.c)&&r.hasOwnProperty("d")&&s(r.d)&&r.hasOwnProperty("e")&&s(r.e)&&r.hasOwnProperty("f")&&s(r.f)}function y(r){return void 0===r}function b(r){return{a:1,c:0,e:r,b:0,d:1,f:arguments.length>1&&void 0!==arguments[1]?arguments[1]:0}}function v(){for(var r=arguments.length,n=Array(r),t=0;t<r;t++)n[t]=arguments[t];var e=function(r,n){return{a:r.a*n.a+r.c*n.b,c:r.a*n.c+r.c*n.d,e:r.a*n.e+r.c*n.f+r.e,b:r.b*n.a+r.d*n.b,d:r.b*n.c+r.d*n.d,f:r.b*n.e+r.d*n.f+r.f}};switch((n=Array.isArray(n[0])?n[0]:n).length){case 0:throw new Error("no matrices provided");case 1:return n[0];case 2:return e(n[0],n[1]);default:var o=function(r){return Array.isArray(r)?r:Array.from(r)}(n),u=o[0],a=o[1],i=o.slice(2),f=e(u,a);return v.apply(void 0,[f].concat(function(r){if(Array.isArray(r)){for(var n=0,t=Array(r.length);n<r.length;n++)t[n]=r[n];return t}return Array.from(r)}(i)))}}function m(){return v.apply(void 0,arguments)}var h=Math.cos,x=Math.sin,g=Math.PI;function w(r,n,t){var e=h(r),o=x(r),u={a:e,c:-o,e:0,b:o,d:e,f:0};return y(n)||y(t)?u:v([b(n,t),u,b(-n,-t)])}function P(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return w(r*g/180,n,t)}function S(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return y(n)&&(n=r),{a:r,c:0,e:0,b:0,d:n,f:0}}function O(r,n){return{a:1,c:r,e:0,b:n,d:1,f:0}}var A=Math.tan;function F(r,n){return{a:1,c:A(r),e:0,b:A(n),d:1,f:0}}function M(r,n){return F(r*Math.PI/180,n*Math.PI/180)}function j(r){return T(r)}function _(r){return T(r)}function T(r){return"matrix("+r.a+","+r.b+","+r.c+","+r.d+","+r.e+","+r.f+")"}t.d(n,"applyToPoint",function(){return e}),t.d(n,"applyToPoints",function(){return o}),t.d(n,"fromObject",function(){return u}),t.d(n,"fromString",function(){return i}),t.d(n,"identity",function(){return f}),t.d(n,"inverse",function(){return c}),t.d(n,"isAffineMatrix",function(){return p}),t.d(n,"rotate",function(){return w}),t.d(n,"rotateDEG",function(){return P}),t.d(n,"scale",function(){return S}),t.d(n,"shear",function(){return O}),t.d(n,"skew",function(){return F}),t.d(n,"skewDEG",function(){return M}),t.d(n,"toCSS",function(){return j}),t.d(n,"toSVG",function(){return _}),t.d(n,"toString",function(){return T}),t.d(n,"transform",function(){return v}),t.d(n,"compose",function(){return m}),t.d(n,"translate",function(){return b})}])}); | ||
!function(n,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.TransformationMatrix=r():n.TransformationMatrix=r()}(window,function(){return function(n){var r={};function t(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=n,t.c=r,t.d=function(n,r,e){t.o(n,r)||Object.defineProperty(n,r,{enumerable:!0,get:e})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,r){if(1&r&&(n=t(n)),8&r)return n;if(4&r&&"object"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(t.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:n}),2&r&&"string"!=typeof n)for(var o in n)t.d(e,o,function(r){return n[r]}.bind(null,o));return e},t.n=function(n){var r=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(r,"a",r),r},t.o=function(n,r){return Object.prototype.hasOwnProperty.call(n,r)},t.p="",t(t.s=0)}([function(n,r,t){"use strict";function e(n,r){return Array.isArray(r)?[n.a*r[0]+n.c*r[1]+n.e,n.b*r[0]+n.d*r[1]+n.f]:{x:n.a*r.x+n.c*r.y+n.e,y:n.b*r.x+n.d*r.y+n.f}}function o(n,r){return r.map(function(r){return e(n,r)})}function u(n){return{a:parseFloat(n.a),b:parseFloat(n.b),c:parseFloat(n.c),d:parseFloat(n.d),e:parseFloat(n.e),f:parseFloat(n.f)}}t.r(r);var a=/^matrix\(\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*\)$/i;function i(n){var r=n.match(a);if(null===r||r.length<7)throw new Error("'"+n+"' is not a matrix");return{a:parseFloat(r[1]),b:parseFloat(r[2]),c:parseFloat(r[3]),d:parseFloat(r[4]),e:parseFloat(r[5]),f:parseFloat(r[6])}}function f(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function c(n){var r=n.a,t=n.b,e=n.c,o=n.d,u=n.e,a=n.f,i=r*o-t*e;return{a:o/i,b:t/-i,c:e/-i,d:r/i,e:(o*u-e*a)/-i,f:(t*u-r*a)/i}}var d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},l=function(n){return"number"==typeof n&&!isNaN(n)&&isFinite(n)},s=function(n){return null!=n&&"object"===(void 0===n?"undefined":d(n))};function y(n){return s(n)&&n.hasOwnProperty("a")&&l(n.a)&&n.hasOwnProperty("b")&&l(n.b)&&n.hasOwnProperty("c")&&l(n.c)&&n.hasOwnProperty("d")&&l(n.d)&&n.hasOwnProperty("e")&&l(n.e)&&n.hasOwnProperty("f")&&l(n.f)}function p(n){return void 0===n}function b(n){return{a:1,c:0,e:n,b:0,d:1,f:arguments.length>1&&void 0!==arguments[1]?arguments[1]:0}}function v(){for(var n=arguments.length,r=Array(n),t=0;t<n;t++)r[t]=arguments[t];var e=function(n,r){return{a:n.a*r.a+n.c*r.b,c:n.a*r.c+n.c*r.d,e:n.a*r.e+n.c*r.f+n.e,b:n.b*r.a+n.d*r.b,d:n.b*r.c+n.d*r.d,f:n.b*r.e+n.d*r.f+n.f}};switch((r=Array.isArray(r[0])?r[0]:r).length){case 0:throw new Error("no matrices provided");case 1:return r[0];case 2:return e(r[0],r[1]);default:var o=function(n){return Array.isArray(n)?n:Array.from(n)}(r),u=o[0],a=o[1],i=o.slice(2),f=e(u,a);return v.apply(void 0,[f].concat(function(n){if(Array.isArray(n)){for(var r=0,t=Array(n.length);r<n.length;r++)t[r]=n[r];return t}return Array.from(n)}(i)))}}function h(){return v.apply(void 0,arguments)}var m=Math.cos,x=Math.sin,M=Math.PI;function g(n,r,t){var e=m(n),o=x(n),u={a:e,c:-o,e:0,b:o,d:e,f:0};return p(r)||p(t)?u:v([b(r,t),u,b(-r,-t)])}function w(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return g(n*M/180,r,t)}function P(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return p(r)&&(r=n),{a:n,c:0,e:0,b:0,d:r,f:0}}function S(n,r){return{a:1,c:n,e:0,b:r,d:1,f:0}}var O=Math.tan;function A(n,r){return{a:1,c:O(n),e:0,b:O(r),d:1,f:0}}function F(n,r){return A(n*Math.PI/180,r*Math.PI/180)}function j(n){return T(n)}function _(n){return T(n)}function T(n){return"matrix("+n.a+","+n.b+","+n.c+","+n.d+","+n.e+","+n.f+")"}function E(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e10;return{a:Math.round(n.a*r)/r,b:Math.round(n.b*r)/r,c:Math.round(n.c*r)/r,d:Math.round(n.d*r)/r,e:Math.round(n.e*r)/r,f:Math.round(n.f*r)/r}}function G(n,r){var t=null!=n[0].x?n[0].x:n[0][0],e=null!=n[0].y?n[0].y:n[0][1],o=null!=r[0].x?r[0].x:r[0][0],u=null!=r[0].y?r[0].y:r[0][1],a=null!=n[1].x?n[1].x:n[1][0],i=null!=n[1].y?n[1].y:n[1][1],f=null!=r[1].x?r[1].x:r[1][0],d=null!=r[1].y?r[1].y:r[1][1],l=null!=n[2].x?n[2].x:n[2][0],s=null!=n[2].y?n[2].y:n[2][1],y=null!=r[2].x?r[2].x:r[2][0],p=null!=r[2].y?r[2].y:r[2][1];return E(v([{a:o-y,b:u-p,c:f-y,d:d-p,e:y,f:p},c({a:t-l,b:e-s,c:a-l,d:i-s,e:l,f:s})]))}t.d(r,"applyToPoint",function(){return e}),t.d(r,"applyToPoints",function(){return o}),t.d(r,"fromObject",function(){return u}),t.d(r,"fromString",function(){return i}),t.d(r,"identity",function(){return f}),t.d(r,"inverse",function(){return c}),t.d(r,"isAffineMatrix",function(){return y}),t.d(r,"rotate",function(){return g}),t.d(r,"rotateDEG",function(){return w}),t.d(r,"scale",function(){return P}),t.d(r,"shear",function(){return S}),t.d(r,"skew",function(){return A}),t.d(r,"skewDEG",function(){return F}),t.d(r,"toCSS",function(){return j}),t.d(r,"toSVG",function(){return _}),t.d(r,"toString",function(){return T}),t.d(r,"transform",function(){return v}),t.d(r,"compose",function(){return h}),t.d(r,"translate",function(){return b}),t.d(r,"fromTriangles",function(){return G}),t.d(r,"smoothMatrix",function(){return E})}])}); | ||
//# sourceMappingURL=transformation-matrix.min.js.map |
{ | ||
"name": "transformation-matrix", | ||
"version": "1.15.1", | ||
"version": "1.15.2", | ||
"description": "2d transformation matrix functions written in ES6 syntax. Tree shaking ready!", | ||
@@ -9,3 +9,3 @@ "main": "./build-commonjs/index.js", | ||
"jsnext:main": "./build-es/index.js", | ||
"browser": "./build-umd/transformation-matrix.min.js", | ||
"unpkg": "./build-umd/transformation-matrix.min.js", | ||
"files": [ | ||
@@ -12,0 +12,0 @@ "*.md", |
@@ -14,1 +14,3 @@ export * from './applyToPoint' | ||
export * from './translate' | ||
export * from './fromTriangles' | ||
export * from './smoothMatrix' |
@@ -0,1 +1,3 @@ | ||
import {Matrix} from "transformation-matrix"; | ||
declare module 'transformation-matrix' { | ||
@@ -139,2 +141,9 @@ type Matrix = { | ||
declare module 'transformation-matrix/compose' { | ||
import { Matrix } from 'transformation-matrix'; | ||
/** Merge multiple matrices into one */ | ||
export function compose(...matrices: Matrix[]): Matrix; | ||
} | ||
declare module 'transformation-matrix/translate' { | ||
@@ -141,0 +150,0 @@ import { Matrix } from 'transformation-matrix'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
266481
6019