@vertexvis/geometry
Advanced tools
Comparing version
@@ -475,2 +475,16 @@ 'use strict'; | ||
/** | ||
* Returns a rectangle where each side of `rect` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* rectangle will be centered within the original bounds of `rect`. | ||
* | ||
* @param to - the maximum area this rectangle can have | ||
* @param rect - the rectangle to scale to fit the specified area | ||
*/ | ||
var scaleFit = function (to, rect) { | ||
var scale = Math.min(Math.sqrt(to / area(rect)), 1); | ||
var dimensions$1 = floor(proportionalScale(scale, rect)); | ||
var position = subtract(center$1(rect), center$2(dimensions$1)); | ||
return fromPointAndDimensions(position, dimensions$1); | ||
}; | ||
/** | ||
* Returns true if two rectangles are equal in position and size. | ||
@@ -489,2 +503,8 @@ */ | ||
/** | ||
* Returns the area of the rectangle. | ||
*/ | ||
var area = function (rect) { | ||
return rect.width * rect.height; | ||
}; | ||
/** | ||
* Returns the center point of the rectangle. | ||
@@ -534,4 +554,6 @@ */ | ||
cropFit: cropFit, | ||
scaleFit: scaleFit, | ||
isEqual: isEqual$2, | ||
offset: offset, | ||
area: area, | ||
center: center$1, | ||
@@ -614,2 +636,14 @@ topLeft: topLeft, | ||
/** | ||
* Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* dimensions will be centered within the original bounds of `dimensions`. | ||
* | ||
* @param to - the maximum area this dimensions can have | ||
* @param dimensions - the dimensions to scale to fit the specified area | ||
*/ | ||
var scaleFit$1 = function (to, dimensions) { | ||
var _a = scaleFit(to, toRectangle(dimensions)), width = _a.width, height = _a.height; | ||
return { width: width, height: height }; | ||
}; | ||
/** | ||
* Returns a `Dimensions` with each length rounded. | ||
@@ -624,2 +658,11 @@ */ | ||
/** | ||
* Returns a `Dimensions` with each length rounded down. | ||
*/ | ||
var floor = function (dimensions) { | ||
return { | ||
width: Math.floor(dimensions.width), | ||
height: Math.floor(dimensions.height), | ||
}; | ||
}; | ||
/** | ||
* Returns the center point of the given `dimensions`. | ||
@@ -639,2 +682,9 @@ */ | ||
/** | ||
* Returns the area of the given `dimensions`. | ||
*/ | ||
var area$1 = function (_a) { | ||
var width = _a.width, height = _a.height; | ||
return width * height; | ||
}; | ||
/** | ||
* Returns a `Dimensions` fitted to the provided aspect ratio. | ||
@@ -669,5 +719,8 @@ * | ||
cropFit: cropFit$1, | ||
scaleFit: scaleFit$1, | ||
round: round, | ||
floor: floor, | ||
center: center$2, | ||
aspectRatio: aspectRatio, | ||
area: area$1, | ||
fitToRatio: fitToRatio, | ||
@@ -674,0 +727,0 @@ toRectangle: toRectangle |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib");function n(t,n){return void 0===t&&(t=0),void 0===n&&(n=0),{x:t,y:n}}function r(t,n){return{x:t.x-n.x,y:t.y-n.y}}function e(t,n){return{x:t.x+n.x,y:t.y+n.y}}function i(t,n){return t.x===n.x&&t.y===n.y}var o=Object.freeze({__proto__:null,create:n,polar:function(t,r){var e=u(r);return n(Math.cos(c(e))*t,Math.sin(c(e))*t)},distance:function(t,n){var e=r(t,n);return Math.sqrt(e.x*e.x+e.y*e.y)},subtract:r,add:e,isEqual:i,negate:function(t){return n(-t.x,-t.y)},scale:function(t,n,r){return{x:t.x*n,y:t.y*r}}}),u=function(t){return(t+3600)%360},a=function(t){return t*(180/Math.PI)},c=function(t){return t*(Math.PI/180)},h=Object.freeze({__proto__:null,fromPoints:function(t,n){var e=r(n,t),i=Math.atan2(e.y,e.x);return u(a(i)-270)},normalize:u,toDegrees:a,toRadians:c});function f(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length?{x:t[0].x||0,y:t[0].y||0,z:t[0].z||0}:3===t.length?{x:t[0],y:t[1],z:t[2]}:{x:0,y:0,z:0}}var x=function(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)},y=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.reduce((function(t,n){return{x:t.x+n.x,y:t.y+n.y,z:t.z+n.z}}),t)},s=function(t,n){return{x:n.x*t,y:n.y*t,z:n.z*t}},d=function(t,n){return t.x*n.x+t.y*n.y+t.z*n.z},z=function(t,n){return f(Math.max(t.x,n.x),Math.max(t.y,n.y),Math.max(t.z,n.z))},l=function(t,n){return f(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.min(t.z,n.z))},g=Object.freeze({__proto__:null,create:f,isValid:function(t){return[t.x,t.y,t.z].every((function(t){return isFinite(t)&&!isNaN(t)}))},fromArray:function(t){return f(t[0],t[1],t[2])},toArray:function(t){return[t.x,t.y,t.z]},right:function(){return f(1,0,0)},up:function(){return f(0,1,0)},forward:function(){return f(0,0,-1)},left:function(){return f(-1,0,0)},down:function(){return f(0,-1,0)},back:function(){return f(0,0,1)},origin:function(){return f(0,0,0)},normalize:function(t){var n=x(t);return{x:t.x/n,y:t.y/n,z:t.z/n}},magnitude:x,cross:function(t,n){return{x:t.y*n.z-t.z*n.y,y:t.z*n.x-t.x*n.z,z:t.x*n.y-t.y*n.x}},add:y,subtract:function(t,n){return{x:t.x-n.x,y:t.y-n.y,z:t.z-n.z}},multiply:function(t,n){return{x:t.x*n.x,y:t.y*n.y,z:t.z*n.z}},scale:s,dot:d,angleTo:function(t,n){var r=d(t,n)/(x(t)*x(n));return Math.acos(r)},projection:function(t,n){return s(d(t,n)/x(t),t)},rotateAboutAxis:function(t,n,r,e){if(0!==t){var i=n.x,o=n.y,u=n.z,a=e.x,c=e.y,h=e.z,f=r.x,x=r.y,y=r.z;return{x:(a*(x*x+y*y)-f*(c*x+h*y-f*i-x*o-y*u))*(1-Math.cos(t))+i*Math.cos(t)+(-h*x+c*y-y*o+x*u)*Math.sin(t),y:(c*(f*f+y*y)-x*(a*f+h*y-f*i-x*o-y*u))*(1-Math.cos(t))+o*Math.cos(t)+(h*f-a*y+y*i-f*u)*Math.sin(t),z:(h*(f*f+x*x)-y*(a*f+c*x-f*i-x*o-y*u))*(1-Math.cos(t))+u*Math.cos(t)+(-c*f+a*x-x*i+f*o)*Math.sin(t)}}return n},distance:function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)+Math.pow(t.z-n.z,2))},isEqual:function(t,n){return t.x===n.x&&t.y===n.y&&t.z===n.z},max:z,min:l}),m=function(t,n){return{min:t,max:n}};function M(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];var i=t.__spreadArrays([n],r);return i.reduce((function(t,n){return m(l(t.min,n.min),z(t.max,n.max))}))}var _=Object.freeze({__proto__:null,create:m,fromVectors:function(t){return M.apply(void 0,t.map((function(t){return m(t,t)})))},center:function(t){return s(.5,y(t.min,t.max))},union:M}),p=function(t,n,r,e){return{x:t,y:n,width:r,height:e}},w=function(t,n){return p(t.x,t.y,n.width,n.height)},v=function(t,n){var e=Math.min(t.width/n.width,t.height/n.height),i=E(e,n),o=r(j(t),F(i));return w(o,i)},b=function(t,n){var e=Math.max(t.width/n.width,t.height/n.height),i=E(e,n),o=r(j(t),F(i));return w(o,i)},j=function(t){return{x:t.x+t.width/2,y:t.y+t.height/2}},q=function(t){return n(t.x,t.y)},O=Object.freeze({__proto__:null,create:p,fromDimensions:function(t){return p(0,0,t.width,t.height)},fromPointAndDimensions:w,fromPoints:function(t,n){var r=Math.min(t.x,n.x),e=Math.min(t.y,n.y),i=Math.max(t.x,n.x),o=Math.max(t.y,n.y);return p(r,e,i-r,o-e)},containFit:v,cropFit:b,isEqual:function(t,n){return i(t,n)&&A(t,n)},offset:function(t,n){return w(e(q(n),t),n)},center:j,topLeft:q,bottomRight:function(t){return n(t.x+t.width,t.y+t.height)},isPortrait:function(t){return t.width<t.height},isLandscape:function(t){return t.width>t.height},isSquare:function(t){return t.width===t.height}}),P=function(t,n){return{width:t,height:n}},A=function(t,n){return t.width===n.width&&t.height===n.height},R=function(t,n,r){return{width:r.width*t,height:r.height*n}},E=function(t,n){return R(t,t,n)},F=function(t){return{x:t.width/2,y:t.height/2}};function V(t,r){return void 0===r&&(r=n()),w(r,t)}var D=Object.freeze({__proto__:null,create:P,square:function(t){return P(t,t)},isEqual:A,scale:R,proportionalScale:E,trim:function(t,n){return{width:Math.min(t.width,n.width),height:Math.min(t.height,n.height)}},containFit:function(t,n){var r=v(V(t),V(n));return{width:r.width,height:r.height}},cropFit:function(t,n){var r=b(V(t),V(n));return{width:r.width,height:r.height}},round:function(t){return{width:Math.round(t.width),height:Math.round(t.height)}},center:F,aspectRatio:function(t){return t.width/t.height},fitToRatio:function(t,n){return n.width>=n.height*t?P(n.height*t,n.height):P(n.width,n.width/t)},toRectangle:V}),B=function(t,n,r,e,i,o){return void 0===t&&(t=1),void 0===n&&(n=0),void 0===r&&(r=0),void 0===e&&(e=1),void 0===i&&(i=0),void 0===o&&(o=0),{a:t,b:n,c:r,d:e,tx:i,ty:o}},I=function(){return B()},L=function(t,n){var r=c(t),e=Math.cos(r),i=Math.sin(r),o=n.a*e+n.c*i,u=n.b*e+n.d*i,a=n.a*-i+n.c*e,h=n.b*-i+n.d*e;return B(o,u,a,h,n.tx,n.ty)},N=function(t,n,r){var e=r.a*t+r.c*n+r.tx,i=r.b*t+r.d*n+r.ty;return B(r.a,r.b,r.c,r.d,e,i)},S=Object.freeze({__proto__:null,create:B,identity:I,translation:function(t,n){return N(t,n,I())},rotation:function(t){return L(t,I())},rotate:L,translate:N,transformPoint:function(t,r){return n(t.a*r.x+t.c*r.y+t.tx,t.b*r.x+t.d*r.y+t.ty)}}),T=function(t,n,r,e){return{x:t,y:n,z:r,w:e}},k=Object.freeze({__proto__:null,create:T}),C=Object.freeze({__proto__:null,create:function(t){if(16!==t.length)throw new Error("Must have 16 items");return t},multiplyVector3:function(t,n){var r=n.x,e=n.y,i=n.z,o=t[0]*r+t[1]*e+t[2]*i+t[3],u=t[4]*r+t[5]*e+t[6]*i+t[7],a=t[8]*r+t[9]*e+t[10]*i+t[11],c=t[12]*r+t[13]*e+t[14]*i+t[15];return T(o,u,a,c)}});exports.Angle=h,exports.BoundingBox=_,exports.Dimensions=D,exports.Matrix=S,exports.Matrix4=C,exports.Point=o,exports.Rectangle=O,exports.Vector3=g,exports.Vector4=k; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib");function n(t,n){return void 0===t&&(t=0),void 0===n&&(n=0),{x:t,y:n}}function r(t,n){return{x:t.x-n.x,y:t.y-n.y}}function e(t,n){return{x:t.x+n.x,y:t.y+n.y}}function i(t,n){return t.x===n.x&&t.y===n.y}var o=Object.freeze({__proto__:null,create:n,polar:function(t,r){var e=u(r);return n(Math.cos(a(e))*t,Math.sin(a(e))*t)},distance:function(t,n){var e=r(t,n);return Math.sqrt(e.x*e.x+e.y*e.y)},subtract:r,add:e,isEqual:i,negate:function(t){return n(-t.x,-t.y)},scale:function(t,n,r){return{x:t.x*n,y:t.y*r}}}),u=function(t){return(t+3600)%360},h=function(t){return t*(180/Math.PI)},a=function(t){return t*(Math.PI/180)},c=Object.freeze({__proto__:null,fromPoints:function(t,n){var e=r(n,t),i=Math.atan2(e.y,e.x);return u(h(i)-270)},normalize:u,toDegrees:h,toRadians:a});function f(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length?{x:t[0].x||0,y:t[0].y||0,z:t[0].z||0}:3===t.length?{x:t[0],y:t[1],z:t[2]}:{x:0,y:0,z:0}}var x=function(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)},y=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.reduce((function(t,n){return{x:t.x+n.x,y:t.y+n.y,z:t.z+n.z}}),t)},d=function(t,n){return{x:n.x*t,y:n.y*t,z:n.z*t}},s=function(t,n){return t.x*n.x+t.y*n.y+t.z*n.z},l=function(t,n){return f(Math.max(t.x,n.x),Math.max(t.y,n.y),Math.max(t.z,n.z))},g=function(t,n){return f(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.min(t.z,n.z))},z=Object.freeze({__proto__:null,create:f,isValid:function(t){return[t.x,t.y,t.z].every((function(t){return isFinite(t)&&!isNaN(t)}))},fromArray:function(t){return f(t[0],t[1],t[2])},toArray:function(t){return[t.x,t.y,t.z]},right:function(){return f(1,0,0)},up:function(){return f(0,1,0)},forward:function(){return f(0,0,-1)},left:function(){return f(-1,0,0)},down:function(){return f(0,-1,0)},back:function(){return f(0,0,1)},origin:function(){return f(0,0,0)},normalize:function(t){var n=x(t);return{x:t.x/n,y:t.y/n,z:t.z/n}},magnitude:x,cross:function(t,n){return{x:t.y*n.z-t.z*n.y,y:t.z*n.x-t.x*n.z,z:t.x*n.y-t.y*n.x}},add:y,subtract:function(t,n){return{x:t.x-n.x,y:t.y-n.y,z:t.z-n.z}},multiply:function(t,n){return{x:t.x*n.x,y:t.y*n.y,z:t.z*n.z}},scale:d,dot:s,angleTo:function(t,n){var r=s(t,n)/(x(t)*x(n));return Math.acos(r)},projection:function(t,n){return d(s(t,n)/x(t),t)},rotateAboutAxis:function(t,n,r,e){if(0!==t){var i=n.x,o=n.y,u=n.z,h=e.x,a=e.y,c=e.z,f=r.x,x=r.y,y=r.z;return{x:(h*(x*x+y*y)-f*(a*x+c*y-f*i-x*o-y*u))*(1-Math.cos(t))+i*Math.cos(t)+(-c*x+a*y-y*o+x*u)*Math.sin(t),y:(a*(f*f+y*y)-x*(h*f+c*y-f*i-x*o-y*u))*(1-Math.cos(t))+o*Math.cos(t)+(c*f-h*y+y*i-f*u)*Math.sin(t),z:(c*(f*f+x*x)-y*(h*f+a*x-f*i-x*o-y*u))*(1-Math.cos(t))+u*Math.cos(t)+(-a*f+h*x-x*i+f*o)*Math.sin(t)}}return n},distance:function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)+Math.pow(t.z-n.z,2))},isEqual:function(t,n){return t.x===n.x&&t.y===n.y&&t.z===n.z},max:l,min:g}),M=function(t,n){return{min:t,max:n}};function w(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];var i=t.__spreadArrays([n],r);return i.reduce((function(t,n){return M(g(t.min,n.min),l(t.max,n.max))}))}var m=Object.freeze({__proto__:null,create:M,fromVectors:function(t){return w.apply(void 0,t.map((function(t){return M(t,t)})))},center:function(t){return d(.5,y(t.min,t.max))},union:w}),_=function(t,n,r,e){return{x:t,y:n,width:r,height:e}},p=function(t,n){return _(t.x,t.y,n.width,n.height)},v=function(t,n){var e=Math.min(t.width/n.width,t.height/n.height),i=V(e,n),o=r(O(t),B(i));return p(o,i)},b=function(t,n){var e=Math.max(t.width/n.width,t.height/n.height),i=V(e,n),o=r(O(t),B(i));return p(o,i)},j=function(t,n){var e=Math.min(Math.sqrt(t/q(n)),1),i=D(V(e,n)),o=r(O(n),B(i));return p(o,i)},q=function(t){return t.width*t.height},O=function(t){return{x:t.x+t.width/2,y:t.y+t.height/2}},P=function(t){return n(t.x,t.y)},A=Object.freeze({__proto__:null,create:_,fromDimensions:function(t){return _(0,0,t.width,t.height)},fromPointAndDimensions:p,fromPoints:function(t,n){var r=Math.min(t.x,n.x),e=Math.min(t.y,n.y),i=Math.max(t.x,n.x),o=Math.max(t.y,n.y);return _(r,e,i-r,o-e)},containFit:v,cropFit:b,scaleFit:j,isEqual:function(t,n){return i(t,n)&&R(t,n)},offset:function(t,n){return p(e(P(n),t),n)},area:q,center:O,topLeft:P,bottomRight:function(t){return n(t.x+t.width,t.y+t.height)},isPortrait:function(t){return t.width<t.height},isLandscape:function(t){return t.width>t.height},isSquare:function(t){return t.width===t.height}}),F=function(t,n){return{width:t,height:n}},R=function(t,n){return t.width===n.width&&t.height===n.height},E=function(t,n,r){return{width:r.width*t,height:r.height*n}},V=function(t,n){return E(t,t,n)},D=function(t){return{width:Math.floor(t.width),height:Math.floor(t.height)}},B=function(t){return{x:t.width/2,y:t.height/2}};function I(t,r){return void 0===r&&(r=n()),p(r,t)}var L=Object.freeze({__proto__:null,create:F,square:function(t){return F(t,t)},isEqual:R,scale:E,proportionalScale:V,trim:function(t,n){return{width:Math.min(t.width,n.width),height:Math.min(t.height,n.height)}},containFit:function(t,n){var r=v(I(t),I(n));return{width:r.width,height:r.height}},cropFit:function(t,n){var r=b(I(t),I(n));return{width:r.width,height:r.height}},scaleFit:function(t,n){var r=j(t,I(n));return{width:r.width,height:r.height}},round:function(t){return{width:Math.round(t.width),height:Math.round(t.height)}},floor:D,center:B,aspectRatio:function(t){return t.width/t.height},area:function(t){return t.width*t.height},fitToRatio:function(t,n){return n.width>=n.height*t?F(n.height*t,n.height):F(n.width,n.width/t)},toRectangle:I}),N=function(t,n,r,e,i,o){return void 0===t&&(t=1),void 0===n&&(n=0),void 0===r&&(r=0),void 0===e&&(e=1),void 0===i&&(i=0),void 0===o&&(o=0),{a:t,b:n,c:r,d:e,tx:i,ty:o}},S=function(){return N()},T=function(t,n){var r=a(t),e=Math.cos(r),i=Math.sin(r),o=n.a*e+n.c*i,u=n.b*e+n.d*i,h=n.a*-i+n.c*e,c=n.b*-i+n.d*e;return N(o,u,h,c,n.tx,n.ty)},k=function(t,n,r){var e=r.a*t+r.c*n+r.tx,i=r.b*t+r.d*n+r.ty;return N(r.a,r.b,r.c,r.d,e,i)},C=Object.freeze({__proto__:null,create:N,identity:S,translation:function(t,n){return k(t,n,S())},rotation:function(t){return T(t,S())},rotate:T,translate:k,transformPoint:function(t,r){return n(t.a*r.x+t.c*r.y+t.tx,t.b*r.x+t.d*r.y+t.ty)}}),G=function(t,n,r,e){return{x:t,y:n,z:r,w:e}},H=Object.freeze({__proto__:null,create:G}),J=Object.freeze({__proto__:null,create:function(t){if(16!==t.length)throw new Error("Must have 16 items");return t},multiplyVector3:function(t,n){var r=n.x,e=n.y,i=n.z,o=t[0]*r+t[1]*e+t[2]*i+t[3],u=t[4]*r+t[5]*e+t[6]*i+t[7],h=t[8]*r+t[9]*e+t[10]*i+t[11],a=t[12]*r+t[13]*e+t[14]*i+t[15];return G(o,u,h,a)}});exports.Angle=c,exports.BoundingBox=m,exports.Dimensions=L,exports.Matrix=C,exports.Matrix4=J,exports.Point=o,exports.Rectangle=A,exports.Vector3=z,exports.Vector4=H; | ||
//# sourceMappingURL=bundle.cjs.min.js.map |
@@ -471,2 +471,16 @@ import { __spreadArrays } from 'tslib'; | ||
/** | ||
* Returns a rectangle where each side of `rect` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* rectangle will be centered within the original bounds of `rect`. | ||
* | ||
* @param to - the maximum area this rectangle can have | ||
* @param rect - the rectangle to scale to fit the specified area | ||
*/ | ||
var scaleFit = function (to, rect) { | ||
var scale = Math.min(Math.sqrt(to / area(rect)), 1); | ||
var dimensions$1 = floor(proportionalScale(scale, rect)); | ||
var position = subtract(center$1(rect), center$2(dimensions$1)); | ||
return fromPointAndDimensions(position, dimensions$1); | ||
}; | ||
/** | ||
* Returns true if two rectangles are equal in position and size. | ||
@@ -485,2 +499,8 @@ */ | ||
/** | ||
* Returns the area of the rectangle. | ||
*/ | ||
var area = function (rect) { | ||
return rect.width * rect.height; | ||
}; | ||
/** | ||
* Returns the center point of the rectangle. | ||
@@ -530,4 +550,6 @@ */ | ||
cropFit: cropFit, | ||
scaleFit: scaleFit, | ||
isEqual: isEqual$2, | ||
offset: offset, | ||
area: area, | ||
center: center$1, | ||
@@ -610,2 +632,14 @@ topLeft: topLeft, | ||
/** | ||
* Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* dimensions will be centered within the original bounds of `dimensions`. | ||
* | ||
* @param to - the maximum area this dimensions can have | ||
* @param dimensions - the dimensions to scale to fit the specified area | ||
*/ | ||
var scaleFit$1 = function (to, dimensions) { | ||
var _a = scaleFit(to, toRectangle(dimensions)), width = _a.width, height = _a.height; | ||
return { width: width, height: height }; | ||
}; | ||
/** | ||
* Returns a `Dimensions` with each length rounded. | ||
@@ -620,2 +654,11 @@ */ | ||
/** | ||
* Returns a `Dimensions` with each length rounded down. | ||
*/ | ||
var floor = function (dimensions) { | ||
return { | ||
width: Math.floor(dimensions.width), | ||
height: Math.floor(dimensions.height), | ||
}; | ||
}; | ||
/** | ||
* Returns the center point of the given `dimensions`. | ||
@@ -635,2 +678,9 @@ */ | ||
/** | ||
* Returns the area of the given `dimensions`. | ||
*/ | ||
var area$1 = function (_a) { | ||
var width = _a.width, height = _a.height; | ||
return width * height; | ||
}; | ||
/** | ||
* Returns a `Dimensions` fitted to the provided aspect ratio. | ||
@@ -665,5 +715,8 @@ * | ||
cropFit: cropFit$1, | ||
scaleFit: scaleFit$1, | ||
round: round, | ||
floor: floor, | ||
center: center$2, | ||
aspectRatio: aspectRatio, | ||
area: area$1, | ||
fitToRatio: fitToRatio, | ||
@@ -670,0 +723,0 @@ toRectangle: toRectangle |
@@ -1,2 +0,2 @@ | ||
import{__spreadArrays as t}from"tslib";function n(t,n){return void 0===t&&(t=0),void 0===n&&(n=0),{x:t,y:n}}function r(t,n){return{x:t.x-n.x,y:t.y-n.y}}function i(t,n){return{x:t.x+n.x,y:t.y+n.y}}function e(t,n){return t.x===n.x&&t.y===n.y}var u=Object.freeze({__proto__:null,create:n,polar:function(t,r){var i=o(r);return n(Math.cos(c(i))*t,Math.sin(c(i))*t)},distance:function(t,n){var i=r(t,n);return Math.sqrt(i.x*i.x+i.y*i.y)},subtract:r,add:i,isEqual:e,negate:function(t){return n(-t.x,-t.y)},scale:function(t,n,r){return{x:t.x*n,y:t.y*r}}}),o=function(t){return(t+3600)%360},a=function(t){return t*(180/Math.PI)},c=function(t){return t*(Math.PI/180)},h=Object.freeze({__proto__:null,fromPoints:function(t,n){var i=r(n,t),e=Math.atan2(i.y,i.x);return o(a(e)-270)},normalize:o,toDegrees:a,toRadians:c});function f(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length?{x:t[0].x||0,y:t[0].y||0,z:t[0].z||0}:3===t.length?{x:t[0],y:t[1],z:t[2]}:{x:0,y:0,z:0}}var x=function(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)},y=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.reduce((function(t,n){return{x:t.x+n.x,y:t.y+n.y,z:t.z+n.z}}),t)},d=function(t,n){return{x:n.x*t,y:n.y*t,z:n.z*t}},s=function(t,n){return t.x*n.x+t.y*n.y+t.z*n.z},z=function(t,n){return f(Math.max(t.x,n.x),Math.max(t.y,n.y),Math.max(t.z,n.z))},l=function(t,n){return f(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.min(t.z,n.z))},g=Object.freeze({__proto__:null,create:f,isValid:function(t){return[t.x,t.y,t.z].every((function(t){return isFinite(t)&&!isNaN(t)}))},fromArray:function(t){return f(t[0],t[1],t[2])},toArray:function(t){return[t.x,t.y,t.z]},right:function(){return f(1,0,0)},up:function(){return f(0,1,0)},forward:function(){return f(0,0,-1)},left:function(){return f(-1,0,0)},down:function(){return f(0,-1,0)},back:function(){return f(0,0,1)},origin:function(){return f(0,0,0)},normalize:function(t){var n=x(t);return{x:t.x/n,y:t.y/n,z:t.z/n}},magnitude:x,cross:function(t,n){return{x:t.y*n.z-t.z*n.y,y:t.z*n.x-t.x*n.z,z:t.x*n.y-t.y*n.x}},add:y,subtract:function(t,n){return{x:t.x-n.x,y:t.y-n.y,z:t.z-n.z}},multiply:function(t,n){return{x:t.x*n.x,y:t.y*n.y,z:t.z*n.z}},scale:d,dot:s,angleTo:function(t,n){var r=s(t,n)/(x(t)*x(n));return Math.acos(r)},projection:function(t,n){return d(s(t,n)/x(t),t)},rotateAboutAxis:function(t,n,r,i){if(0!==t){var e=n.x,u=n.y,o=n.z,a=i.x,c=i.y,h=i.z,f=r.x,x=r.y,y=r.z;return{x:(a*(x*x+y*y)-f*(c*x+h*y-f*e-x*u-y*o))*(1-Math.cos(t))+e*Math.cos(t)+(-h*x+c*y-y*u+x*o)*Math.sin(t),y:(c*(f*f+y*y)-x*(a*f+h*y-f*e-x*u-y*o))*(1-Math.cos(t))+u*Math.cos(t)+(h*f-a*y+y*e-f*o)*Math.sin(t),z:(h*(f*f+x*x)-y*(a*f+c*x-f*e-x*u-y*o))*(1-Math.cos(t))+o*Math.cos(t)+(-c*f+a*x-x*e+f*u)*Math.sin(t)}}return n},distance:function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)+Math.pow(t.z-n.z,2))},isEqual:function(t,n){return t.x===n.x&&t.y===n.y&&t.z===n.z},max:z,min:l}),m=function(t,n){return{min:t,max:n}};function M(n){for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];var e=t([n],r);return e.reduce((function(t,n){return m(l(t.min,n.min),z(t.max,n.max))}))}var w=Object.freeze({__proto__:null,create:m,fromVectors:function(t){return M.apply(void 0,t.map((function(t){return m(t,t)})))},center:function(t){return d(.5,y(t.min,t.max))},union:M}),_=function(t,n,r,i){return{x:t,y:n,width:r,height:i}},v=function(t,n){return _(t.x,t.y,n.width,n.height)},p=function(t,n){var i=Math.min(t.width/n.width,t.height/n.height),e=E(i,n),u=r(j(t),F(e));return v(u,e)},b=function(t,n){var i=Math.max(t.width/n.width,t.height/n.height),e=E(i,n),u=r(j(t),F(e));return v(u,e)},j=function(t){return{x:t.x+t.width/2,y:t.y+t.height/2}},q=function(t){return n(t.x,t.y)},O=Object.freeze({__proto__:null,create:_,fromDimensions:function(t){return _(0,0,t.width,t.height)},fromPointAndDimensions:v,fromPoints:function(t,n){var r=Math.min(t.x,n.x),i=Math.min(t.y,n.y),e=Math.max(t.x,n.x),u=Math.max(t.y,n.y);return _(r,i,e-r,u-i)},containFit:p,cropFit:b,isEqual:function(t,n){return e(t,n)&&A(t,n)},offset:function(t,n){return v(i(q(n),t),n)},center:j,topLeft:q,bottomRight:function(t){return n(t.x+t.width,t.y+t.height)},isPortrait:function(t){return t.width<t.height},isLandscape:function(t){return t.width>t.height},isSquare:function(t){return t.width===t.height}}),P=function(t,n){return{width:t,height:n}},A=function(t,n){return t.width===n.width&&t.height===n.height},R=function(t,n,r){return{width:r.width*t,height:r.height*n}},E=function(t,n){return R(t,t,n)},F=function(t){return{x:t.width/2,y:t.height/2}};function V(t,r){return void 0===r&&(r=n()),v(r,t)}var D=Object.freeze({__proto__:null,create:P,square:function(t){return P(t,t)},isEqual:A,scale:R,proportionalScale:E,trim:function(t,n){return{width:Math.min(t.width,n.width),height:Math.min(t.height,n.height)}},containFit:function(t,n){var r=p(V(t),V(n));return{width:r.width,height:r.height}},cropFit:function(t,n){var r=b(V(t),V(n));return{width:r.width,height:r.height}},round:function(t){return{width:Math.round(t.width),height:Math.round(t.height)}},center:F,aspectRatio:function(t){return t.width/t.height},fitToRatio:function(t,n){return n.width>=n.height*t?P(n.height*t,n.height):P(n.width,n.width/t)},toRectangle:V}),B=function(t,n,r,i,e,u){return void 0===t&&(t=1),void 0===n&&(n=0),void 0===r&&(r=0),void 0===i&&(i=1),void 0===e&&(e=0),void 0===u&&(u=0),{a:t,b:n,c:r,d:i,tx:e,ty:u}},I=function(){return B()},L=function(t,n){var r=c(t),i=Math.cos(r),e=Math.sin(r),u=n.a*i+n.c*e,o=n.b*i+n.d*e,a=n.a*-e+n.c*i,h=n.b*-e+n.d*i;return B(u,o,a,h,n.tx,n.ty)},N=function(t,n,r){var i=r.a*t+r.c*n+r.tx,e=r.b*t+r.d*n+r.ty;return B(r.a,r.b,r.c,r.d,i,e)},S=Object.freeze({__proto__:null,create:B,identity:I,translation:function(t,n){return N(t,n,I())},rotation:function(t){return L(t,I())},rotate:L,translate:N,transformPoint:function(t,r){return n(t.a*r.x+t.c*r.y+t.tx,t.b*r.x+t.d*r.y+t.ty)}}),T=function(t,n,r,i){return{x:t,y:n,z:r,w:i}},k=Object.freeze({__proto__:null,create:T}),C=Object.freeze({__proto__:null,create:function(t){if(16!==t.length)throw new Error("Must have 16 items");return t},multiplyVector3:function(t,n){var r=n.x,i=n.y,e=n.z,u=t[0]*r+t[1]*i+t[2]*e+t[3],o=t[4]*r+t[5]*i+t[6]*e+t[7],a=t[8]*r+t[9]*i+t[10]*e+t[11],c=t[12]*r+t[13]*i+t[14]*e+t[15];return T(u,o,a,c)}});export{h as Angle,w as BoundingBox,D as Dimensions,S as Matrix,C as Matrix4,u as Point,O as Rectangle,g as Vector3,k as Vector4}; | ||
import{__spreadArrays as t}from"tslib";function n(t,n){return void 0===t&&(t=0),void 0===n&&(n=0),{x:t,y:n}}function r(t,n){return{x:t.x-n.x,y:t.y-n.y}}function i(t,n){return{x:t.x+n.x,y:t.y+n.y}}function e(t,n){return t.x===n.x&&t.y===n.y}var u=Object.freeze({__proto__:null,create:n,polar:function(t,r){var i=o(r);return n(Math.cos(h(i))*t,Math.sin(h(i))*t)},distance:function(t,n){var i=r(t,n);return Math.sqrt(i.x*i.x+i.y*i.y)},subtract:r,add:i,isEqual:e,negate:function(t){return n(-t.x,-t.y)},scale:function(t,n,r){return{x:t.x*n,y:t.y*r}}}),o=function(t){return(t+3600)%360},a=function(t){return t*(180/Math.PI)},h=function(t){return t*(Math.PI/180)},c=Object.freeze({__proto__:null,fromPoints:function(t,n){var i=r(n,t),e=Math.atan2(i.y,i.x);return o(a(e)-270)},normalize:o,toDegrees:a,toRadians:h});function f(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length?{x:t[0].x||0,y:t[0].y||0,z:t[0].z||0}:3===t.length?{x:t[0],y:t[1],z:t[2]}:{x:0,y:0,z:0}}var x=function(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)},y=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.reduce((function(t,n){return{x:t.x+n.x,y:t.y+n.y,z:t.z+n.z}}),t)},d=function(t,n){return{x:n.x*t,y:n.y*t,z:n.z*t}},s=function(t,n){return t.x*n.x+t.y*n.y+t.z*n.z},l=function(t,n){return f(Math.max(t.x,n.x),Math.max(t.y,n.y),Math.max(t.z,n.z))},g=function(t,n){return f(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.min(t.z,n.z))},z=Object.freeze({__proto__:null,create:f,isValid:function(t){return[t.x,t.y,t.z].every((function(t){return isFinite(t)&&!isNaN(t)}))},fromArray:function(t){return f(t[0],t[1],t[2])},toArray:function(t){return[t.x,t.y,t.z]},right:function(){return f(1,0,0)},up:function(){return f(0,1,0)},forward:function(){return f(0,0,-1)},left:function(){return f(-1,0,0)},down:function(){return f(0,-1,0)},back:function(){return f(0,0,1)},origin:function(){return f(0,0,0)},normalize:function(t){var n=x(t);return{x:t.x/n,y:t.y/n,z:t.z/n}},magnitude:x,cross:function(t,n){return{x:t.y*n.z-t.z*n.y,y:t.z*n.x-t.x*n.z,z:t.x*n.y-t.y*n.x}},add:y,subtract:function(t,n){return{x:t.x-n.x,y:t.y-n.y,z:t.z-n.z}},multiply:function(t,n){return{x:t.x*n.x,y:t.y*n.y,z:t.z*n.z}},scale:d,dot:s,angleTo:function(t,n){var r=s(t,n)/(x(t)*x(n));return Math.acos(r)},projection:function(t,n){return d(s(t,n)/x(t),t)},rotateAboutAxis:function(t,n,r,i){if(0!==t){var e=n.x,u=n.y,o=n.z,a=i.x,h=i.y,c=i.z,f=r.x,x=r.y,y=r.z;return{x:(a*(x*x+y*y)-f*(h*x+c*y-f*e-x*u-y*o))*(1-Math.cos(t))+e*Math.cos(t)+(-c*x+h*y-y*u+x*o)*Math.sin(t),y:(h*(f*f+y*y)-x*(a*f+c*y-f*e-x*u-y*o))*(1-Math.cos(t))+u*Math.cos(t)+(c*f-a*y+y*e-f*o)*Math.sin(t),z:(c*(f*f+x*x)-y*(a*f+h*x-f*e-x*u-y*o))*(1-Math.cos(t))+o*Math.cos(t)+(-h*f+a*x-x*e+f*u)*Math.sin(t)}}return n},distance:function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)+Math.pow(t.z-n.z,2))},isEqual:function(t,n){return t.x===n.x&&t.y===n.y&&t.z===n.z},max:l,min:g}),m=function(t,n){return{min:t,max:n}};function M(n){for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];var e=t([n],r);return e.reduce((function(t,n){return m(g(t.min,n.min),l(t.max,n.max))}))}var w=Object.freeze({__proto__:null,create:m,fromVectors:function(t){return M.apply(void 0,t.map((function(t){return m(t,t)})))},center:function(t){return d(.5,y(t.min,t.max))},union:M}),v=function(t,n,r,i){return{x:t,y:n,width:r,height:i}},_=function(t,n){return v(t.x,t.y,n.width,n.height)},p=function(t,n){var i=Math.min(t.width/n.width,t.height/n.height),e=V(i,n),u=r(O(t),B(e));return _(u,e)},b=function(t,n){var i=Math.max(t.width/n.width,t.height/n.height),e=V(i,n),u=r(O(t),B(e));return _(u,e)},j=function(t,n){var i=Math.min(Math.sqrt(t/q(n)),1),e=D(V(i,n)),u=r(O(n),B(e));return _(u,e)},q=function(t){return t.width*t.height},O=function(t){return{x:t.x+t.width/2,y:t.y+t.height/2}},P=function(t){return n(t.x,t.y)},F=Object.freeze({__proto__:null,create:v,fromDimensions:function(t){return v(0,0,t.width,t.height)},fromPointAndDimensions:_,fromPoints:function(t,n){var r=Math.min(t.x,n.x),i=Math.min(t.y,n.y),e=Math.max(t.x,n.x),u=Math.max(t.y,n.y);return v(r,i,e-r,u-i)},containFit:p,cropFit:b,scaleFit:j,isEqual:function(t,n){return e(t,n)&&R(t,n)},offset:function(t,n){return _(i(P(n),t),n)},area:q,center:O,topLeft:P,bottomRight:function(t){return n(t.x+t.width,t.y+t.height)},isPortrait:function(t){return t.width<t.height},isLandscape:function(t){return t.width>t.height},isSquare:function(t){return t.width===t.height}}),A=function(t,n){return{width:t,height:n}},R=function(t,n){return t.width===n.width&&t.height===n.height},E=function(t,n,r){return{width:r.width*t,height:r.height*n}},V=function(t,n){return E(t,t,n)},D=function(t){return{width:Math.floor(t.width),height:Math.floor(t.height)}},B=function(t){return{x:t.width/2,y:t.height/2}};function I(t,r){return void 0===r&&(r=n()),_(r,t)}var L=Object.freeze({__proto__:null,create:A,square:function(t){return A(t,t)},isEqual:R,scale:E,proportionalScale:V,trim:function(t,n){return{width:Math.min(t.width,n.width),height:Math.min(t.height,n.height)}},containFit:function(t,n){var r=p(I(t),I(n));return{width:r.width,height:r.height}},cropFit:function(t,n){var r=b(I(t),I(n));return{width:r.width,height:r.height}},scaleFit:function(t,n){var r=j(t,I(n));return{width:r.width,height:r.height}},round:function(t){return{width:Math.round(t.width),height:Math.round(t.height)}},floor:D,center:B,aspectRatio:function(t){return t.width/t.height},area:function(t){return t.width*t.height},fitToRatio:function(t,n){return n.width>=n.height*t?A(n.height*t,n.height):A(n.width,n.width/t)},toRectangle:I}),N=function(t,n,r,i,e,u){return void 0===t&&(t=1),void 0===n&&(n=0),void 0===r&&(r=0),void 0===i&&(i=1),void 0===e&&(e=0),void 0===u&&(u=0),{a:t,b:n,c:r,d:i,tx:e,ty:u}},S=function(){return N()},T=function(t,n){var r=h(t),i=Math.cos(r),e=Math.sin(r),u=n.a*i+n.c*e,o=n.b*i+n.d*e,a=n.a*-e+n.c*i,c=n.b*-e+n.d*i;return N(u,o,a,c,n.tx,n.ty)},k=function(t,n,r){var i=r.a*t+r.c*n+r.tx,e=r.b*t+r.d*n+r.ty;return N(r.a,r.b,r.c,r.d,i,e)},C=Object.freeze({__proto__:null,create:N,identity:S,translation:function(t,n){return k(t,n,S())},rotation:function(t){return T(t,S())},rotate:T,translate:k,transformPoint:function(t,r){return n(t.a*r.x+t.c*r.y+t.tx,t.b*r.x+t.d*r.y+t.ty)}}),G=function(t,n,r,i){return{x:t,y:n,z:r,w:i}},H=Object.freeze({__proto__:null,create:G}),J=Object.freeze({__proto__:null,create:function(t){if(16!==t.length)throw new Error("Must have 16 items");return t},multiplyVector3:function(t,n){var r=n.x,i=n.y,e=n.z,u=t[0]*r+t[1]*i+t[2]*e+t[3],o=t[4]*r+t[5]*i+t[6]*e+t[7],a=t[8]*r+t[9]*i+t[10]*e+t[11],h=t[12]*r+t[13]*i+t[14]*e+t[15];return G(u,o,a,h)}});export{c as Angle,w as BoundingBox,L as Dimensions,C as Matrix,J as Matrix4,u as Point,F as Rectangle,z as Vector3,H as Vector4}; | ||
//# sourceMappingURL=bundle.esm.min.js.map |
@@ -492,2 +492,16 @@ /** | ||
/** | ||
* Returns a rectangle where each side of `rect` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* rectangle will be centered within the original bounds of `rect`. | ||
* | ||
* @param to - the maximum area this rectangle can have | ||
* @param rect - the rectangle to scale to fit the specified area | ||
*/ | ||
var scaleFit = function (to, rect) { | ||
var scale = Math.min(Math.sqrt(to / area(rect)), 1); | ||
var dimensions$1 = floor(proportionalScale(scale, rect)); | ||
var position = subtract(center$1(rect), center$2(dimensions$1)); | ||
return fromPointAndDimensions(position, dimensions$1); | ||
}; | ||
/** | ||
* Returns true if two rectangles are equal in position and size. | ||
@@ -506,2 +520,8 @@ */ | ||
/** | ||
* Returns the area of the rectangle. | ||
*/ | ||
var area = function (rect) { | ||
return rect.width * rect.height; | ||
}; | ||
/** | ||
* Returns the center point of the rectangle. | ||
@@ -551,4 +571,6 @@ */ | ||
cropFit: cropFit, | ||
scaleFit: scaleFit, | ||
isEqual: isEqual$2, | ||
offset: offset, | ||
area: area, | ||
center: center$1, | ||
@@ -631,2 +653,14 @@ topLeft: topLeft, | ||
/** | ||
* Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* dimensions will be centered within the original bounds of `dimensions`. | ||
* | ||
* @param to - the maximum area this dimensions can have | ||
* @param dimensions - the dimensions to scale to fit the specified area | ||
*/ | ||
var scaleFit$1 = function (to, dimensions) { | ||
var _a = scaleFit(to, toRectangle(dimensions)), width = _a.width, height = _a.height; | ||
return { width: width, height: height }; | ||
}; | ||
/** | ||
* Returns a `Dimensions` with each length rounded. | ||
@@ -641,2 +675,11 @@ */ | ||
/** | ||
* Returns a `Dimensions` with each length rounded down. | ||
*/ | ||
var floor = function (dimensions) { | ||
return { | ||
width: Math.floor(dimensions.width), | ||
height: Math.floor(dimensions.height), | ||
}; | ||
}; | ||
/** | ||
* Returns the center point of the given `dimensions`. | ||
@@ -656,2 +699,9 @@ */ | ||
/** | ||
* Returns the area of the given `dimensions`. | ||
*/ | ||
var area$1 = function (_a) { | ||
var width = _a.width, height = _a.height; | ||
return width * height; | ||
}; | ||
/** | ||
* Returns a `Dimensions` fitted to the provided aspect ratio. | ||
@@ -686,5 +736,8 @@ * | ||
cropFit: cropFit$1, | ||
scaleFit: scaleFit$1, | ||
round: round, | ||
floor: floor, | ||
center: center$2, | ||
aspectRatio: aspectRatio, | ||
area: area$1, | ||
fitToRatio: fitToRatio, | ||
@@ -691,0 +744,0 @@ toRectangle: toRectangle |
@@ -16,3 +16,3 @@ function t(t,n){return void 0===t&&(t=0),void 0===n&&(n=0),{x:t,y:n}}function n(t,n){return{x:t.x-n.x,y:t.y-n.y}}function r(t,n){return{x:t.x+n.x,y:t.y+n.y}}function i(t,n){return t.x===n.x&&t.y===n.y}var e=Object.freeze({__proto__:null,create:t,polar:function(n,r){var i=u(r);return t(Math.cos(a(i))*n,Math.sin(a(i))*n)},distance:function(t,r){var i=n(t,r);return Math.sqrt(i.x*i.x+i.y*i.y)},subtract:n,add:r,isEqual:i,negate:function(n){return t(-n.x,-n.y)},scale:function(t,n,r){return{x:t.x*n,y:t.y*r}}}),u=function(t){return(t+3600)%360},o=function(t){return t*(180/Math.PI)},a=function(t){return t*(Math.PI/180)},h=Object.freeze({__proto__:null,fromPoints:function(t,r){var i=n(r,t),e=Math.atan2(i.y,i.x);return u(o(e)-270)},normalize:u,toDegrees:o,toRadians:a}); | ||
***************************************************************************** */ | ||
function c(){for(var t=0,n=0,r=arguments.length;n<r;n++)t+=arguments[n].length;var i=Array(t),e=0;for(n=0;n<r;n++)for(var u=arguments[n],o=0,a=u.length;o<a;o++,e++)i[e]=u[o];return i}function f(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length?{x:t[0].x||0,y:t[0].y||0,z:t[0].z||0}:3===t.length?{x:t[0],y:t[1],z:t[2]}:{x:0,y:0,z:0}}var x=function(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)},y=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.reduce((function(t,n){return{x:t.x+n.x,y:t.y+n.y,z:t.z+n.z}}),t)},d=function(t,n){return{x:n.x*t,y:n.y*t,z:n.z*t}},s=function(t,n){return t.x*n.x+t.y*n.y+t.z*n.z},z=function(t,n){return f(Math.max(t.x,n.x),Math.max(t.y,n.y),Math.max(t.z,n.z))},l=function(t,n){return f(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.min(t.z,n.z))},g=Object.freeze({__proto__:null,create:f,isValid:function(t){return[t.x,t.y,t.z].every((function(t){return isFinite(t)&&!isNaN(t)}))},fromArray:function(t){return f(t[0],t[1],t[2])},toArray:function(t){return[t.x,t.y,t.z]},right:function(){return f(1,0,0)},up:function(){return f(0,1,0)},forward:function(){return f(0,0,-1)},left:function(){return f(-1,0,0)},down:function(){return f(0,-1,0)},back:function(){return f(0,0,1)},origin:function(){return f(0,0,0)},normalize:function(t){var n=x(t);return{x:t.x/n,y:t.y/n,z:t.z/n}},magnitude:x,cross:function(t,n){return{x:t.y*n.z-t.z*n.y,y:t.z*n.x-t.x*n.z,z:t.x*n.y-t.y*n.x}},add:y,subtract:function(t,n){return{x:t.x-n.x,y:t.y-n.y,z:t.z-n.z}},multiply:function(t,n){return{x:t.x*n.x,y:t.y*n.y,z:t.z*n.z}},scale:d,dot:s,angleTo:function(t,n){var r=s(t,n)/(x(t)*x(n));return Math.acos(r)},projection:function(t,n){return d(s(t,n)/x(t),t)},rotateAboutAxis:function(t,n,r,i){if(0!==t){var e=n.x,u=n.y,o=n.z,a=i.x,h=i.y,c=i.z,f=r.x,x=r.y,y=r.z;return{x:(a*(x*x+y*y)-f*(h*x+c*y-f*e-x*u-y*o))*(1-Math.cos(t))+e*Math.cos(t)+(-c*x+h*y-y*u+x*o)*Math.sin(t),y:(h*(f*f+y*y)-x*(a*f+c*y-f*e-x*u-y*o))*(1-Math.cos(t))+u*Math.cos(t)+(c*f-a*y+y*e-f*o)*Math.sin(t),z:(c*(f*f+x*x)-y*(a*f+h*x-f*e-x*u-y*o))*(1-Math.cos(t))+o*Math.cos(t)+(-h*f+a*x-x*e+f*u)*Math.sin(t)}}return n},distance:function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)+Math.pow(t.z-n.z,2))},isEqual:function(t,n){return t.x===n.x&&t.y===n.y&&t.z===n.z},max:z,min:l}),m=function(t,n){return{min:t,max:n}};function M(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=c([t],n);return i.reduce((function(t,n){return m(l(t.min,n.min),z(t.max,n.max))}))}var w=Object.freeze({__proto__:null,create:m,fromVectors:function(t){return M.apply(void 0,t.map((function(t){return m(t,t)})))},center:function(t){return d(.5,y(t.min,t.max))},union:M}),v=function(t,n,r,i){return{x:t,y:n,width:r,height:i}},_=function(t,n){return v(t.x,t.y,n.width,n.height)},p=function(t,r){var i=Math.min(t.width/r.width,t.height/r.height),e=E(i,r),u=n(j(t),F(e));return _(u,e)},b=function(t,r){var i=Math.max(t.width/r.width,t.height/r.height),e=E(i,r),u=n(j(t),F(e));return _(u,e)},j=function(t){return{x:t.x+t.width/2,y:t.y+t.height/2}},q=function(n){return t(n.x,n.y)},O=Object.freeze({__proto__:null,create:v,fromDimensions:function(t){return v(0,0,t.width,t.height)},fromPointAndDimensions:_,fromPoints:function(t,n){var r=Math.min(t.x,n.x),i=Math.min(t.y,n.y),e=Math.max(t.x,n.x),u=Math.max(t.y,n.y);return v(r,i,e-r,u-i)},containFit:p,cropFit:b,isEqual:function(t,n){return i(t,n)&&A(t,n)},offset:function(t,n){return _(r(q(n),t),n)},center:j,topLeft:q,bottomRight:function(n){return t(n.x+n.width,n.y+n.height)},isPortrait:function(t){return t.width<t.height},isLandscape:function(t){return t.width>t.height},isSquare:function(t){return t.width===t.height}}),P=function(t,n){return{width:t,height:n}},A=function(t,n){return t.width===n.width&&t.height===n.height},R=function(t,n,r){return{width:r.width*t,height:r.height*n}},E=function(t,n){return R(t,t,n)},F=function(t){return{x:t.width/2,y:t.height/2}};function V(n,r){return void 0===r&&(r=t()),_(r,n)}var D=Object.freeze({__proto__:null,create:P,square:function(t){return P(t,t)},isEqual:A,scale:R,proportionalScale:E,trim:function(t,n){return{width:Math.min(t.width,n.width),height:Math.min(t.height,n.height)}},containFit:function(t,n){var r=p(V(t),V(n));return{width:r.width,height:r.height}},cropFit:function(t,n){var r=b(V(t),V(n));return{width:r.width,height:r.height}},round:function(t){return{width:Math.round(t.width),height:Math.round(t.height)}},center:F,aspectRatio:function(t){return t.width/t.height},fitToRatio:function(t,n){return n.width>=n.height*t?P(n.height*t,n.height):P(n.width,n.width/t)},toRectangle:V}),B=function(t,n,r,i,e,u){return void 0===t&&(t=1),void 0===n&&(n=0),void 0===r&&(r=0),void 0===i&&(i=1),void 0===e&&(e=0),void 0===u&&(u=0),{a:t,b:n,c:r,d:i,tx:e,ty:u}},I=function(){return B()},L=function(t,n){var r=a(t),i=Math.cos(r),e=Math.sin(r),u=n.a*i+n.c*e,o=n.b*i+n.d*e,h=n.a*-e+n.c*i,c=n.b*-e+n.d*i;return B(u,o,h,c,n.tx,n.ty)},N=function(t,n,r){var i=r.a*t+r.c*n+r.tx,e=r.b*t+r.d*n+r.ty;return B(r.a,r.b,r.c,r.d,i,e)},S=Object.freeze({__proto__:null,create:B,identity:I,translation:function(t,n){return N(t,n,I())},rotation:function(t){return L(t,I())},rotate:L,translate:N,transformPoint:function(n,r){return t(n.a*r.x+n.c*r.y+n.tx,n.b*r.x+n.d*r.y+n.ty)}}),T=function(t,n,r,i){return{x:t,y:n,z:r,w:i}},k=Object.freeze({__proto__:null,create:T}),C=Object.freeze({__proto__:null,create:function(t){if(16!==t.length)throw new Error("Must have 16 items");return t},multiplyVector3:function(t,n){var r=n.x,i=n.y,e=n.z,u=t[0]*r+t[1]*i+t[2]*e+t[3],o=t[4]*r+t[5]*i+t[6]*e+t[7],a=t[8]*r+t[9]*i+t[10]*e+t[11],h=t[12]*r+t[13]*i+t[14]*e+t[15];return T(u,o,a,h)}});export{h as Angle,w as BoundingBox,D as Dimensions,S as Matrix,C as Matrix4,e as Point,O as Rectangle,g as Vector3,k as Vector4}; | ||
function c(){for(var t=0,n=0,r=arguments.length;n<r;n++)t+=arguments[n].length;var i=Array(t),e=0;for(n=0;n<r;n++)for(var u=arguments[n],o=0,a=u.length;o<a;o++,e++)i[e]=u[o];return i}function f(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length?{x:t[0].x||0,y:t[0].y||0,z:t[0].z||0}:3===t.length?{x:t[0],y:t[1],z:t[2]}:{x:0,y:0,z:0}}var x=function(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)},y=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.reduce((function(t,n){return{x:t.x+n.x,y:t.y+n.y,z:t.z+n.z}}),t)},d=function(t,n){return{x:n.x*t,y:n.y*t,z:n.z*t}},s=function(t,n){return t.x*n.x+t.y*n.y+t.z*n.z},g=function(t,n){return f(Math.max(t.x,n.x),Math.max(t.y,n.y),Math.max(t.z,n.z))},l=function(t,n){return f(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.min(t.z,n.z))},z=Object.freeze({__proto__:null,create:f,isValid:function(t){return[t.x,t.y,t.z].every((function(t){return isFinite(t)&&!isNaN(t)}))},fromArray:function(t){return f(t[0],t[1],t[2])},toArray:function(t){return[t.x,t.y,t.z]},right:function(){return f(1,0,0)},up:function(){return f(0,1,0)},forward:function(){return f(0,0,-1)},left:function(){return f(-1,0,0)},down:function(){return f(0,-1,0)},back:function(){return f(0,0,1)},origin:function(){return f(0,0,0)},normalize:function(t){var n=x(t);return{x:t.x/n,y:t.y/n,z:t.z/n}},magnitude:x,cross:function(t,n){return{x:t.y*n.z-t.z*n.y,y:t.z*n.x-t.x*n.z,z:t.x*n.y-t.y*n.x}},add:y,subtract:function(t,n){return{x:t.x-n.x,y:t.y-n.y,z:t.z-n.z}},multiply:function(t,n){return{x:t.x*n.x,y:t.y*n.y,z:t.z*n.z}},scale:d,dot:s,angleTo:function(t,n){var r=s(t,n)/(x(t)*x(n));return Math.acos(r)},projection:function(t,n){return d(s(t,n)/x(t),t)},rotateAboutAxis:function(t,n,r,i){if(0!==t){var e=n.x,u=n.y,o=n.z,a=i.x,h=i.y,c=i.z,f=r.x,x=r.y,y=r.z;return{x:(a*(x*x+y*y)-f*(h*x+c*y-f*e-x*u-y*o))*(1-Math.cos(t))+e*Math.cos(t)+(-c*x+h*y-y*u+x*o)*Math.sin(t),y:(h*(f*f+y*y)-x*(a*f+c*y-f*e-x*u-y*o))*(1-Math.cos(t))+u*Math.cos(t)+(c*f-a*y+y*e-f*o)*Math.sin(t),z:(c*(f*f+x*x)-y*(a*f+h*x-f*e-x*u-y*o))*(1-Math.cos(t))+o*Math.cos(t)+(-h*f+a*x-x*e+f*u)*Math.sin(t)}}return n},distance:function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)+Math.pow(t.z-n.z,2))},isEqual:function(t,n){return t.x===n.x&&t.y===n.y&&t.z===n.z},max:g,min:l}),M=function(t,n){return{min:t,max:n}};function w(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=c([t],n);return i.reduce((function(t,n){return M(l(t.min,n.min),g(t.max,n.max))}))}var m=Object.freeze({__proto__:null,create:M,fromVectors:function(t){return w.apply(void 0,t.map((function(t){return M(t,t)})))},center:function(t){return d(.5,y(t.min,t.max))},union:w}),v=function(t,n,r,i){return{x:t,y:n,width:r,height:i}},_=function(t,n){return v(t.x,t.y,n.width,n.height)},p=function(t,r){var i=Math.min(t.width/r.width,t.height/r.height),e=V(i,r),u=n(O(t),B(e));return _(u,e)},b=function(t,r){var i=Math.max(t.width/r.width,t.height/r.height),e=V(i,r),u=n(O(t),B(e));return _(u,e)},j=function(t,r){var i=Math.min(Math.sqrt(t/q(r)),1),e=D(V(i,r)),u=n(O(r),B(e));return _(u,e)},q=function(t){return t.width*t.height},O=function(t){return{x:t.x+t.width/2,y:t.y+t.height/2}},P=function(n){return t(n.x,n.y)},A=Object.freeze({__proto__:null,create:v,fromDimensions:function(t){return v(0,0,t.width,t.height)},fromPointAndDimensions:_,fromPoints:function(t,n){var r=Math.min(t.x,n.x),i=Math.min(t.y,n.y),e=Math.max(t.x,n.x),u=Math.max(t.y,n.y);return v(r,i,e-r,u-i)},containFit:p,cropFit:b,scaleFit:j,isEqual:function(t,n){return i(t,n)&&R(t,n)},offset:function(t,n){return _(r(P(n),t),n)},area:q,center:O,topLeft:P,bottomRight:function(n){return t(n.x+n.width,n.y+n.height)},isPortrait:function(t){return t.width<t.height},isLandscape:function(t){return t.width>t.height},isSquare:function(t){return t.width===t.height}}),F=function(t,n){return{width:t,height:n}},R=function(t,n){return t.width===n.width&&t.height===n.height},E=function(t,n,r){return{width:r.width*t,height:r.height*n}},V=function(t,n){return E(t,t,n)},D=function(t){return{width:Math.floor(t.width),height:Math.floor(t.height)}},B=function(t){return{x:t.width/2,y:t.height/2}};function I(n,r){return void 0===r&&(r=t()),_(r,n)}var L=Object.freeze({__proto__:null,create:F,square:function(t){return F(t,t)},isEqual:R,scale:E,proportionalScale:V,trim:function(t,n){return{width:Math.min(t.width,n.width),height:Math.min(t.height,n.height)}},containFit:function(t,n){var r=p(I(t),I(n));return{width:r.width,height:r.height}},cropFit:function(t,n){var r=b(I(t),I(n));return{width:r.width,height:r.height}},scaleFit:function(t,n){var r=j(t,I(n));return{width:r.width,height:r.height}},round:function(t){return{width:Math.round(t.width),height:Math.round(t.height)}},floor:D,center:B,aspectRatio:function(t){return t.width/t.height},area:function(t){return t.width*t.height},fitToRatio:function(t,n){return n.width>=n.height*t?F(n.height*t,n.height):F(n.width,n.width/t)},toRectangle:I}),N=function(t,n,r,i,e,u){return void 0===t&&(t=1),void 0===n&&(n=0),void 0===r&&(r=0),void 0===i&&(i=1),void 0===e&&(e=0),void 0===u&&(u=0),{a:t,b:n,c:r,d:i,tx:e,ty:u}},S=function(){return N()},T=function(t,n){var r=a(t),i=Math.cos(r),e=Math.sin(r),u=n.a*i+n.c*e,o=n.b*i+n.d*e,h=n.a*-e+n.c*i,c=n.b*-e+n.d*i;return N(u,o,h,c,n.tx,n.ty)},k=function(t,n,r){var i=r.a*t+r.c*n+r.tx,e=r.b*t+r.d*n+r.ty;return N(r.a,r.b,r.c,r.d,i,e)},C=Object.freeze({__proto__:null,create:N,identity:S,translation:function(t,n){return k(t,n,S())},rotation:function(t){return T(t,S())},rotate:T,translate:k,transformPoint:function(n,r){return t(n.a*r.x+n.c*r.y+n.tx,n.b*r.x+n.d*r.y+n.ty)}}),G=function(t,n,r,i){return{x:t,y:n,z:r,w:i}},H=Object.freeze({__proto__:null,create:G}),J=Object.freeze({__proto__:null,create:function(t){if(16!==t.length)throw new Error("Must have 16 items");return t},multiplyVector3:function(t,n){var r=n.x,i=n.y,e=n.z,u=t[0]*r+t[1]*i+t[2]*e+t[3],o=t[4]*r+t[5]*i+t[6]*e+t[7],a=t[8]*r+t[9]*i+t[10]*e+t[11],h=t[12]*r+t[13]*i+t[14]*e+t[15];return G(u,o,a,h)}});export{h as Angle,m as BoundingBox,L as Dimensions,C as Matrix,J as Matrix4,e as Point,A as Rectangle,z as Vector3,H as Vector4}; | ||
//# sourceMappingURL=bundle.esm.min.js.map |
@@ -55,2 +55,11 @@ import * as Point from './point'; | ||
/** | ||
* Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* dimensions will be centered within the original bounds of `dimensions`. | ||
* | ||
* @param to - the maximum area this dimensions can have | ||
* @param dimensions - the dimensions to scale to fit the specified area | ||
*/ | ||
export declare const scaleFit: (to: number, dimensions: Dimensions) => Dimensions; | ||
/** | ||
* Returns a `Dimensions` with each length rounded. | ||
@@ -60,2 +69,6 @@ */ | ||
/** | ||
* Returns a `Dimensions` with each length rounded down. | ||
*/ | ||
export declare const floor: (dimensions: Dimensions) => Dimensions; | ||
/** | ||
* Returns the center point of the given `dimensions`. | ||
@@ -70,2 +83,6 @@ */ | ||
/** | ||
* Returns the area of the given `dimensions`. | ||
*/ | ||
export declare const area: ({ width, height }: Dimensions) => number; | ||
/** | ||
* Returns a `Dimensions` fitted to the provided aspect ratio. | ||
@@ -72,0 +89,0 @@ * |
@@ -48,2 +48,11 @@ import * as Dimensions from './dimensions'; | ||
/** | ||
* Returns a rectangle where each side of `rect` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* rectangle will be centered within the original bounds of `rect`. | ||
* | ||
* @param to - the maximum area this rectangle can have | ||
* @param rect - the rectangle to scale to fit the specified area | ||
*/ | ||
export declare const scaleFit: (to: number, rect: Rectangle) => Rectangle; | ||
/** | ||
* Returns true if two rectangles are equal in position and size. | ||
@@ -58,2 +67,6 @@ */ | ||
/** | ||
* Returns the area of the rectangle. | ||
*/ | ||
export declare const area: (rect: Rectangle) => number; | ||
/** | ||
* Returns the center point of the rectangle. | ||
@@ -60,0 +73,0 @@ */ |
@@ -55,2 +55,11 @@ import * as Point from './point'; | ||
/** | ||
* Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* dimensions will be centered within the original bounds of `dimensions`. | ||
* | ||
* @param to - the maximum area this dimensions can have | ||
* @param dimensions - the dimensions to scale to fit the specified area | ||
*/ | ||
export declare const scaleFit: (to: number, dimensions: Dimensions) => Dimensions; | ||
/** | ||
* Returns a `Dimensions` with each length rounded. | ||
@@ -60,2 +69,6 @@ */ | ||
/** | ||
* Returns a `Dimensions` with each length rounded down. | ||
*/ | ||
export declare const floor: (dimensions: Dimensions) => Dimensions; | ||
/** | ||
* Returns the center point of the given `dimensions`. | ||
@@ -70,2 +83,6 @@ */ | ||
/** | ||
* Returns the area of the given `dimensions`. | ||
*/ | ||
export declare const area: ({ width, height }: Dimensions) => number; | ||
/** | ||
* Returns a `Dimensions` fitted to the provided aspect ratio. | ||
@@ -72,0 +89,0 @@ * |
@@ -48,2 +48,11 @@ import * as Dimensions from './dimensions'; | ||
/** | ||
* Returns a rectangle where each side of `rect` will be reduced proportionally | ||
* to have an area less than or equal to the provided `to` value. The returned | ||
* rectangle will be centered within the original bounds of `rect`. | ||
* | ||
* @param to - the maximum area this rectangle can have | ||
* @param rect - the rectangle to scale to fit the specified area | ||
*/ | ||
export declare const scaleFit: (to: number, rect: Rectangle) => Rectangle; | ||
/** | ||
* Returns true if two rectangles are equal in position and size. | ||
@@ -58,2 +67,6 @@ */ | ||
/** | ||
* Returns the area of the rectangle. | ||
*/ | ||
export declare const area: (rect: Rectangle) => number; | ||
/** | ||
* Returns the center point of the rectangle. | ||
@@ -60,0 +73,0 @@ */ |
{ | ||
"name": "@vertexvis/geometry", | ||
"version": "0.9.22-canary.0", | ||
"version": "0.9.22-canary.1", | ||
"description": "Library for 2D and 3D geometric types.", | ||
@@ -42,3 +42,3 @@ "license": "MIT", | ||
"@vertexvis/jest-config-vertexvis": "0.4.4", | ||
"@vertexwebsdk/build": "^0.9.22-canary.0", | ||
"@vertexwebsdk/build": "^0.9.22-canary.1", | ||
"eslint": "^6.1.0", | ||
@@ -53,3 +53,3 @@ "jest": "^24.9.0", | ||
}, | ||
"gitHead": "3a1153f7a95ebed442ac4b40471c9d864e9dfbb5" | ||
"gitHead": "8b2b28baf679f814ccc89ecfd9ad8e7d888f5546" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
422111
6.35%3596
6.61%