Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@benningfield-group/amc-graphics

Package Overview
Dependencies
Maintainers
6
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@benningfield-group/amc-graphics - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

4

AMC.Graphics.js

@@ -1,2 +0,4 @@

angular.module('AMC.Graphics', []);
angular
.module('AMC.Graphics', [])
.constant('EPSILON', 1e-4);

@@ -1,1 +0,1 @@

"use strict";function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};angular.module("AMC.Graphics",[]),angular.module("AMC.Graphics").directive("amcMapGraphic",["$parse",function(a){return{restrict:"A",link:function(b,c,d){function e(){var a=g();a&&f.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a)}var f=c[0],g=a(d.amcMapGraphic).bind(this,b);b.$watch(g,e),e()}}}]),angular.module("AMC.Graphics").directive("amcSvgSize",["$parse",function(a){return{restrict:"A",link:function(b,c,d){function e(){var a=i();a&&(h.setAttributeNS(null,"width",a.getWidth()),h.setAttributeNS(null,"height",a.getHeight()))}function f(){var a=i();return a?a.getWidth():null}function g(){var a=i();return a?a.getHeight():null}var h=c[0],i=a(d.amcSvgSize).bind(this,b);b.$watch(f,e),b.$watch(g,e),e()}}}]),angular.module("AMC.Graphics").directive("amcTransform",["$parse","matrixHelper",function(a,b){return{restrict:"A",link:function(c,d,e){function f(){var a=h();a&&g.setAttributeNS(null,"transform",b.matrixToString(a))}var g=d[0],h=a(e.amcTransform).bind(this,c);c.$watch(h,f),f()}}}]),angular.module("AMC.Graphics").factory("linearMath",["vectorMath","pointMath",function(a,b){function c(){}var d=1e-6;return c.prototype.getIntersections=function(c,d,e,f){if(b.lessThan(d,c)){var g=[c,d];d=g[0],c=g[1]}if(b.lessThan(f,e)){var h=[e,f];f=h[0],e=h[1]}var i=a.subtract(d,c),j=a.subtract(f,e),k=a.cross(a.subtract(e,c),i),l=a.cross(i,j);if(0===k&&0===l)return e.x>=c.x&&e.x<=d.x&&f.x>=c.x&&f.x<=d.x&&e.y>=c.y&&e.y<=d.y&&f.y>=c.y&&f.y<=d.y?[e,f]:c.x>=e.x&&c.x<=f.x&&d.x>=e.x&&d.x<=f.x&&c.y>=e.y&&c.y<=f.y&&d.y>=e.y&&d.y<=f.y?[c,d]:e.x>=c.x&&e.x<=d.x&&e.y>=c.y&&e.y<=d.y?[e]:f.x>=c.x&&f.x<=d.x&&f.y>=c.y&&f.y<=d.y?[f]:[];if(0===l)return[];var m=k/l,n=a.cross(a.subtract(e,c),j)/l;return n>=0&&n<=1&&m>=0&&m<=1?[a.add(c,a.multiplyScalar(i,n))]:[]},c.prototype.getScaledIntercepts=function(b,c,d,e){var f=a.subtract(c,b),g=a.subtract(e,d),h=a.cross(f,g),i=a.cross(a.subtract(d,b),f);if(0===h&&0===i)return[d,e];if(0===h)return[];var j=i/h;if(j<0||j>1)return[];var k=a.cross(a.subtract(d,b),g)/h;return[a.add(b,a.multiplyScalar(f,k))]},c.prototype.pointOnLineSegment=function(a,c,e){var f=b.distance(a,c),g=b.distance(a,e),h=b.distance(c,e);return Math.abs(f+g-h)<d},c.prototype.areLineSegmentsParallel=function(b,c,e,f){var g=a.subtract(c,b),h=a.subtract(f,e);return Math.abs(a.cross(g,h))<d},c.prototype.areLineSegmentsCollinear=function(b,c,e,f){if(!this.areLineSegmentsParallel(b,c,e,f))return!1;var g=a.subtract(c,b),h=a.subtract(e,b);return Math.abs(a.cross(g,h))<d},new c}]),angular.module("AMC.Graphics").factory("matrixHelper",["$window",function(a){function b(){this._svg=a.document.createElementNS("http://www.w3.org/2000/svg","svg")}return b.prototype.verticesToString=function(a){return a.map(function(a){return a.x+","+a.y}).join(" ")},b.prototype.matrixToArray=function(a){return[a.a,a.b,a.c,a.d,a.e,a.f]},b.prototype.matrixToString=function(a,b){var c=this.matrixToArray(a).join(" ");return b?c:"matrix("+c+")"},b.prototype.createSVGMatrix=function(a,b,c,d,e,f){var g=this._svg.createSVGMatrix();return void 0!==a&&(g.a=a),void 0!==b&&(g.b=b),void 0!==c&&(g.c=c),void 0!==d&&(g.d=d),void 0!==e&&(g.e=e),void 0!==f&&(g.f=f),g},b.prototype.createSVGPoint=function(a,b){var c=this._svg.createSVGPoint();return void 0!==a&&(c.x=a),void 0!==b&&(c.y=b),c},b.prototype.cloneMatrix=function(a){return this.createSVGMatrix(a.a,a.b,a.c,a.d,a.e,a.f)},b.prototype.getScale=function(a){var b=this.createSVGMatrix();return b.a=a.a,b.d=a.d,b},b.prototype.getTranslation=function(a){var b=this.createSVGMatrix();return b.e=a.e,b.f=a.f,b},new b}]),angular.module("AMC.Graphics").factory("pointMath",[function(){function a(){}return a.prototype.distance=function(a,b){return Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2))},a.prototype.pointsEqual=function(a,b){return a.x===b.x&&a.y===b.y},a.prototype.lessThan=function(a,b){return a.x===b.x?a.y<b.y:a.x<b.x},a.prototype.greaterThan=function(a,b){return a.x===b.x?a.y>b.y:a.x>b.x},new a}]),angular.module("AMC.Graphics").factory("polygonMath",["vectorMath","pointMath","linearMath",function(a,b,c){function d(){}return d.prototype.calculateArea=function(a){var b,c,d=0;for(b=0;b<a.length;++b)c=(b+1)%a.length,d+=a[b].x*a[c].y-a[c].x*a[b].y;return d/=2,d<0&&(d*=-1),d},d.prototype.calculateCentroid=function(a){var b,c,d=0,e=0,f=this.calculateArea(a),g={};for(b=0;b<a.length;++b)c=(b+1)%a.length,d+=(a[b].x+a[c].x)*(a[b].x*a[c].y-a[c].x*a[b].y),e+=(a[b].y+a[c].y)*(a[b].x*a[c].y-a[c].x*a[b].y);return d*=1/(6*f),e*=1/(6*f),g.x=d,g.y=e,g},d.prototype.makeVerticesClockwise=function(a){var b,c,d=0;for(b=0;b<a.length;++b)c=(b+1)%a.length,d+=a[b].x*a[c].y-a[c].x*a[b].y;d<0&&a.reverse()},d.prototype.makeVerticesStartWithMin=function(a){var b,c,d=[],e=a.length;for(c=0,b=1;b<e;++b)a[b].x<a[c].x?c=b:a[b].x===a[c].x&&a[b].y<a[c].y&&(c=b);for(b=0;b<e;++b)d.push(a[(b+c)%a.length]);for(a.length=0,b=0;b<e;++b)a.push(d[b])},d.prototype.arePolygonsAdjacent=function(){function b(a,b){return[a,b].some(function(e){for(var f=0;f<e.length;++f){var g=c(e[f],e[(f+1)%e.length]);if(!d(k.project(a,g),k.project(b,g)))return!0}return!1})}function c(b,c){var d=a.subtract(b,c),e=a.transpose(d);return e.y*=-1,a.normalize(e)}function d(a,b){return b.max>=a.min&&a.max>=b.min}function e(a){return f(a,0).size===a.length}function f(a,b){var c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Set;if(!c.has(b)){var d=a[b];c.add(b);for(var e=0;e<d.length;++e)f(a,d[e],c)}return c}for(var g=this,h=arguments.length,i=Array(h),j=0;j<h;j++)i[j]=arguments[j];var k=this;return 1===i.length||(this.sortPolygons(i),i=i.map(function(a){return g.triangulate(a)}).reduce(function(a,b){return a.concat(b)},[]),e(i.map(function(a){return i.reduce(function(c,d,e){return a===d||b(a,d)?c:c.concat(e)},[])})))},d.prototype.project=function(b,c){return b.map(function(b){return a.dot(b,c)}).reduce(function(a,b){return(null===a.min||b<a.min)&&(a.min=b),(null===a.max||b>a.max)&&(a.max=b),a},{min:null,max:null})},d.prototype.arePolygonsCombinable=function(){if(this.arePolygonsAdjacent.apply(this,arguments))return!0;if(2!==arguments.length)return!1;var a=this.getOverlaps(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);return a.x.length+a.y.length>=2},d.prototype.combinePolygons=function(){if(this.arePolygonsAdjacent.apply(this,arguments))return this.combineAdjacentPolygons.apply(this,arguments);if(2!==arguments.length)throw new Error("Combining more than two nonadjacent polygons is not supported.");return this.combineNonadjacentPolygons.apply(this,arguments)},d.prototype.combineAdjacentPolygons=function(){for(var d=this,e=[],f=0,g=0,h=0,i=void 0,j=arguments.length,k=Array(j),l=0;l<j;l++)k[l]=arguments[l];if(k.forEach(function(a){d.makeVerticesUnique(a),d.makeVerticesClockwise(a),d.makeVerticesStartWithMin(a)}),this.sortPolygons(k),i=k[0],!this.arePolygonsAdjacent.apply(this,k))throw new Error("Cannot combine polygons because they are not adjacent.");do{if(-1!==this.indexOf(i[g],e))throw new Error("Cater-cornered polygons cannot be combined.");e.push(i[g]);for(var m={dist:null,angle:null,intPoint:null,polyInd:null,vertInd:null},n=0;n<k.length;++n)if(n!==f)for(var o=k[n],p=0;p<o.length;++p)for(var q=[i[g],i[(g+1)%i.length]],r=[o[p],o[(p+1)%o.length]],s=c.getIntersections.apply(c,q.concat(r)),t=0;t<s.length;++t)if(-1===this.indexOf(s[t],e)){var u=b.distance(i[g],s[t]),v=a.normalize(a.subtract(r[1],q[0])),w=Math.atan2(-v.y,v.x);(null===m.dist||u<m.dist||u===m.dist&&w>m.angle)&&(m.dist=u,m.angle=w,m.intPoint=s[t],m.polyInd=n,m.vertInd=p)}if(null!==m.dist){f=m.polyInd,i=k[f],g=m.vertInd;var x=b.pointsEqual(m.intPoint,i[g]),y=b.pointsEqual(m.intPoint,i[(g+1)%i.length]);x||(g=(g+1)%i.length),x||y||e.push(m.intPoint),++h}else g=(g+1)%i.length}while(!b.pointsEqual(i[g],k[0][0]));if(0===h)throw new Error("Polygons could not be combined because no intersections were found.");return this.removeExtraneousVertices(e),e},d.prototype.combineNonadjacentPolygons=function(d,e){function f(d,e,f,h,j){var k=null,l=[d,a.add(d,e)],m=c.getScaledIntercepts.apply(c,l.concat(_toConsumableArray(f))),n=a.subtract(f[1],f[0]);if(!m.length)return null;for(var o=0;o<h.length;++o)for(var p=[h[o],h[(o+1)%h.length]],q=c.getScaledIntercepts.apply(c,l.concat(p)),r=0;r<m.length;++r)for(var s=0;s<q.length;++s)if(-1===i.indexOf(q[s],j)){var t=b.distance(f[0],m[r]),u=b.distance(m[r],q[s]),v=a.getAngleBetween(n,a.subtract(q[s],m[r]));if(!(v>=0&&v<=Math.PI)){var w={distToInt:t,distToPoly:u,angle:v,fromPt:m[r],toPt:q[s],polygon:h,vertInd:o};k=g(k,w)}}return k}function g(a,b){return null===a?b:null===b?a:a.distToInt<b.distToInt?a:b.distToInt<a.distToInt?b:a.angle>b.angle?a:b.angle>a.angle?b:a.distToPoly<=b.distToPoly?a:b}var h=this,i=this,j={x:1,y:0},k={x:0,y:1},l=[d,e];l.forEach(function(a){h.makeVerticesUnique(a),h.makeVerticesClockwise(a),h.makeVerticesStartWithMin(a)}),this.sortPolygons(l);var m=this.getOverlaps(l[0],l[1]);if(m.x.length+m.y.length<2)throw new Error("Polygons cannot be combined because there are fewer than two overlaping parts.");var n=[],o=0,p=0,q=0,r=l[0],s=1e4,t=0,u=function(){if(++t,-1!==h.indexOf(r[p],n))throw new Error("Cannot combine polygons: duplicate vertex encountered.");n.push(r[p]);for(var a=[r[p],r[(p+1)%r.length]],c=[],d=null,e=function(b){if(b===o)return"continue";var d=l[b],e=m.x.map(function(b){return f({x:b,y:0},k,a,d,n)}).filter(function(a){return null!==a}),g=m.y.map(function(b){return f({x:0,y:b},j,a,d,n)}).filter(function(a){return null!==a});c.push.apply(c,_toConsumableArray(e)),c.push.apply(c,_toConsumableArray(g))},i=0;i<l.length;++i){e(i)}if(d=c.reduce(function(a,b){return g(a,b)},null)){b.pointsEqual(d.fromPt,r[p])||n.push(d.fromPt),o=l.indexOf(d.polygon),r=d.polygon,p=d.vertInd;var s=b.pointsEqual(d.toPt,r[p]),u=b.pointsEqual(d.toPt,r[(p+1)%r.length]);s||(p=(p+1)%r.length),s||u||n.push(d.toPt),++q}else p=(p+1)%r.length};do{u()}while(!b.pointsEqual(r[p],l[0][0])&&t<s);if(!q)throw new Error("Polygons could not be combined because no switches occured.");return this.removeExtraneousVertices(n),n},d.prototype.indexOf=function(a,c){for(var d=0;d<c.length;++d)if(b.pointsEqual(a,c[d]))return d;return-1},d.prototype.makeVerticesUnique=function(a){var b=a.filter(function(a,b,c){return this.indexOf(a,c)===b}.bind(this));a.length=0,b.forEach(function(b){a.push(b)})},d.prototype.removeExtraneousVertices=function(a){if(a.length<3)return a;for(var b=0;b<a.length;++b){var d=a[b],e=a[(b+1)%a.length],f=a[(b+2)%a.length];if(c.pointOnLineSegment(e,d,f))return a.splice((b+1)%a.length,1),this.removeExtraneousVertices(a)}return a},d.prototype.sortPolygons=function(a){return a.sort(function(a,b){var c=Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.x}))),d=Math.min.apply(Math,_toConsumableArray(b.map(function(a){return a.x})));return c!==d?c-d:Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.y})))-Math.min.apply(Math,_toConsumableArray(b.map(function(a){return a.y})))})},d.prototype.getCircumference=function(a){return a.reduce(function(a,c,d,e){return a+b.distance(c,e[(d+1)%e.length])},0)},d.prototype.triangulate=function(b){function c(b){if(3===b.length){var c=[b[0],b[1],b[2]];return d.makeVerticesStartWithMin(c),b.splice(0,1),c}for(var e=function(c){var e=[b[0===c?b.length-1:c-1],b[c],b[(c+1)%b.length]],f=a.subtract(e[0],e[1]),g=a.subtract(e[2],e[1]);if(a.cross(f,g)<0&&!b.some(function(a){return-1===d.indexOf(a,e)&&d.polygonContainsPoint(e,a)}))return d.makeVerticesStartWithMin(e),b.splice(c,1),{v:e}},f=0;f<b.length;++f){var g=e(f);if("object"===(void 0===g?"undefined":_typeof(g)))return g.v}throw new Error("Failed to clip ear.")}var d=this,e=[];if(b.length<3)throw new Error("Polygon cannot be clipped because it has fewer than three vertices.");b=b.slice();do{e.push(c(b))}while(b.length>=3);return e},d.prototype.polygonContainsPoint=function(a,b){var d=Math.max.apply(Math,_toConsumableArray(a.map(function(a){return a.x}))),e=Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.x}))),f=Math.max.apply(Math,_toConsumableArray(a.map(function(a){return a.y}))),g=Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.y})));if(b.x<e)return!1;if(b.x>d)return!1;if(b.y<g)return!1;if(b.y>f)return!1;for(var h=[b,{x:d,y:b.y}],i=[],j=0;j<a.length;++j){var k=[a[j],a[(j+1)%a.length]];if(c.pointOnLineSegment(b,k[0],k[1]))return!0;var l=c.getIntersections(h[0],h[1],k[0],k[1]);l.length&&-1===this.indexOf(l[0],i)&&i.push(l[0])}return i.length%2!=0},d.prototype.getParallelEdges=function(a){for(var b=[],d=0;d<a.length;++d)for(var e=[a[d],a[(d+1)%a.length]],f=d+2;f<a.length;++f){var g=[a[f],a[(f+1)%a.length]];c.areLineSegmentsParallel.apply(c,e.concat(g))&&!c.areLineSegmentsCollinear.apply(c,e.concat(g))&&b.push([e,g])}return b},d.prototype.getOverlaps=function(a,b){function c(a,b){var c=[];return a.min>=b.min&&a.min<=b.max&&c.push(a.min),a.max>=b.min&&a.max<=b.max&&c.push(a.max),b.min>=a.min&&b.min<=a.max&&c.push(b.min),b.max>=a.min&&b.max<=a.max&&c.push(b.max),c.filter(function(a,b,c){return c.indexOf(a)===b}).sort()}var d=this,e={x:1,y:0},f={x:0,y:1},g=[a,b].map(function(a){return d.project(a,e)}),h=[a,b].map(function(a){return d.project(a,f)});return{x:c(g[0],g[1]),y:c(h[0],h[1])}},new d}]),angular.module("AMC.Graphics").factory("vectorMath",[function(){function a(){}return a.prototype.subtract=function(a,b){return{x:a.x-b.x,y:a.y-b.y}},a.prototype.add=function(a,b){return{x:a.x+b.x,y:a.y+b.y}},a.prototype.multiplyScalar=function(a,b){return{x:a.x*b,y:a.y*b}},a.prototype.transpose=function(a){return{x:a.y,y:a.x}},a.prototype.dot=function(a,b){return a.x*b.x+a.y*b.y},a.prototype.cross=function(a,b){return a.x*b.y-a.y*b.x},a.prototype.length=function(a){return Math.sqrt(Math.pow(a.x,2)+Math.pow(a.y,2))},a.prototype.normalize=function(a){var b=this.length(a);if(0===b)throw new Error("Cannot normalize a vector of length 0.");return this.multiplyScalar(a,1/b)},a.prototype.getAngleBetween=function(a,b){var c=Math.atan2(a.y,a.x),d=Math.atan2(b.y,b.x),e=d-c;return e<0&&(e+=2*Math.PI),e},new a}]),angular.module("AMC.Graphics").factory("ViewingTransformer",["matrixHelper",function(a){function b(b,c){this._vtm=a.createSVGMatrix(),this._wndWidth=b,this._wndHeight=c,this._aspectRatio=b/c}return b.prototype.getScale=function(){return a.getScale(this._vtm)},b.prototype.getTranslate=function(){return a.getTranslation(this._vtm)},b.prototype.getVTM=function(){return this._vtm},b.prototype.getInverseVTM=function(){return this.getVTM().inverse()},b.prototype.zoom=function(a,b,c){null!==b&&void 0!==b||(b=1/this._aspectRatio*a);var d=(this._wndWidth+a)/this._wndWidth,e=(this._wndHeight+b)/this._wndHeight;return this.scale(d,e,c)},b.prototype.scale=function(b,c,d){return d=d||{x:this._wndWidth/2,y:this._wndHeight/2},this._vtm=a.createSVGMatrix().translate(d.x,d.y).scaleNonUniform(b,c).translate(-d.x,-d.y).multiply(this._vtm),this.getVTM()},b.prototype.pan=function(b,c){return this._vtm=a.createSVGMatrix().translate(-b,-c).multiply(this._vtm),this.getVTM()},b.prototype.panUp=function(a){return this.pan(0,-a)},b.prototype.panDown=function(a){return this.pan(0,a)},b.prototype.panLeft=function(a){return this.pan(-a,0)},b.prototype.panRight=function(a){return this.pan(a,0)},b.prototype.worldToWindowUnits=function(a){return a.matrixTransform(this.getInverseVTM())},b.prototype.clone=function(){var b=JSON.parse(JSON.stringify(this));return b._vtm=a.cloneMatrix(this._vtm),b},b.prototype.restore=function(b){for(var c in b)this[c]=b[c];this._vtm=a.cloneMatrix(b._vtm)},b}]);
"use strict";function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};angular.module("AMC.Graphics",[]).constant("EPSILON",1e-4),angular.module("AMC.Graphics").directive("amcMapGraphic",["$parse",function(a){return{restrict:"A",link:function(b,c,d){function e(){var a=g();a&&f.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a)}var f=c[0],g=a(d.amcMapGraphic).bind(this,b);b.$watch(g,e),e()}}}]),angular.module("AMC.Graphics").directive("amcSvgSize",["$parse",function(a){return{restrict:"A",link:function(b,c,d){function e(){var a=i();a&&(h.setAttributeNS(null,"width",a.getWidth()),h.setAttributeNS(null,"height",a.getHeight()))}function f(){var a=i();return a?a.getWidth():null}function g(){var a=i();return a?a.getHeight():null}var h=c[0],i=a(d.amcSvgSize).bind(this,b);b.$watch(f,e),b.$watch(g,e),e()}}}]),angular.module("AMC.Graphics").directive("amcTransform",["$parse","matrixHelper",function(a,b){return{restrict:"A",link:function(c,d,e){function f(){var a=h();a&&g.setAttributeNS(null,"transform",b.matrixToString(a))}var g=d[0],h=a(e.amcTransform).bind(this,c);c.$watch(h,f),f()}}}]),angular.module("AMC.Graphics").factory("linearMath",["vectorMath","pointMath","EPSILON",function(a,b,c){function d(){}return d.prototype.getIntersections=function(c,d,e,f){if(b.lessThan(d,c)){var g=[c,d];d=g[0],c=g[1]}if(b.lessThan(f,e)){var h=[e,f];f=h[0],e=h[1]}var i=a.subtract(d,c),j=a.subtract(f,e),k=a.cross(a.subtract(e,c),i),l=a.cross(i,j);if(0===k&&0===l)return e.x>=c.x&&e.x<=d.x&&f.x>=c.x&&f.x<=d.x&&e.y>=c.y&&e.y<=d.y&&f.y>=c.y&&f.y<=d.y?[e,f]:c.x>=e.x&&c.x<=f.x&&d.x>=e.x&&d.x<=f.x&&c.y>=e.y&&c.y<=f.y&&d.y>=e.y&&d.y<=f.y?[c,d]:e.x>=c.x&&e.x<=d.x&&e.y>=c.y&&e.y<=d.y?[e]:f.x>=c.x&&f.x<=d.x&&f.y>=c.y&&f.y<=d.y?[f]:[];if(0===l)return[];var m=k/l,n=a.cross(a.subtract(e,c),j)/l;return n>=0&&n<=1&&m>=0&&m<=1?[a.add(c,a.multiplyScalar(i,n))]:[]},d.prototype.getScaledIntercepts=function(b,c,d,e){var f=a.subtract(c,b),g=a.subtract(e,d),h=a.cross(f,g),i=a.cross(a.subtract(d,b),f);if(0===h&&0===i)return[d,e];if(0===h)return[];var j=i/h;if(j<0||j>1)return[];var k=a.cross(a.subtract(d,b),g)/h;return[a.add(b,a.multiplyScalar(f,k))]},d.prototype.pointOnLineSegment=function(a,d,e){var f=b.distance(a,d),g=b.distance(a,e),h=b.distance(d,e);return Math.abs(f+g-h)<c},d.prototype.areLineSegmentsParallel=function(b,d,e,f){var g=a.subtract(d,b),h=a.subtract(f,e);return Math.abs(a.cross(g,h))<c},d.prototype.areLineSegmentsCollinear=function(b,d,e,f){if(!this.areLineSegmentsParallel(b,d,e,f))return!1;var g=a.subtract(d,b),h=a.subtract(e,b);return Math.abs(a.cross(g,h))<c},new d}]),angular.module("AMC.Graphics").factory("matrixHelper",["$window",function(a){function b(){this._svg=a.document.createElementNS("http://www.w3.org/2000/svg","svg")}return b.prototype.verticesToString=function(a){return a.map(function(a){return a.x+","+a.y}).join(" ")},b.prototype.matrixToArray=function(a){return[a.a,a.b,a.c,a.d,a.e,a.f]},b.prototype.matrixToString=function(a,b){var c=this.matrixToArray(a).join(" ");return b?c:"matrix("+c+")"},b.prototype.createSVGMatrix=function(a,b,c,d,e,f){var g=this._svg.createSVGMatrix();return void 0!==a&&(g.a=a),void 0!==b&&(g.b=b),void 0!==c&&(g.c=c),void 0!==d&&(g.d=d),void 0!==e&&(g.e=e),void 0!==f&&(g.f=f),g},b.prototype.createSVGPoint=function(a,b){var c=this._svg.createSVGPoint();return void 0!==a&&(c.x=a),void 0!==b&&(c.y=b),c},b.prototype.cloneMatrix=function(a){return this.createSVGMatrix(a.a,a.b,a.c,a.d,a.e,a.f)},b.prototype.getScale=function(a){var b=this.createSVGMatrix();return b.a=a.a,b.d=a.d,b},b.prototype.getTranslation=function(a){var b=this.createSVGMatrix();return b.e=a.e,b.f=a.f,b},new b}]),angular.module("AMC.Graphics").factory("pointMath",["EPSILON",function(a){function b(){}return b.prototype.distance=function(a,b){return Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2))},b.prototype.pointsEqual=function(b,c){return Math.abs(b.x-c.x)<a&&Math.abs(b.y-c.y)<a},b.prototype.lessThan=function(b,c){var d=Math.abs(b.x-c.x),e=Math.abs(b.y-c.y);return d<a?e>a&&b.y<c.y:b.x<c.x},b.prototype.greaterThan=function(b,c){var d=Math.abs(b.x-c.x),e=Math.abs(b.y-c.y);return d<a?e>a&&b.y>c.y:b.x>c.x},new b}]),angular.module("AMC.Graphics").factory("polygonMath",["vectorMath","pointMath","linearMath",function(a,b,c){function d(){}return d.prototype.calculateArea=function(a){var b,c,d=0;for(b=0;b<a.length;++b)c=(b+1)%a.length,d+=a[b].x*a[c].y-a[c].x*a[b].y;return d/=2,d<0&&(d*=-1),d},d.prototype.calculateCentroid=function(a){var b,c,d=0,e=0,f=this.calculateArea(a),g={};for(b=0;b<a.length;++b)c=(b+1)%a.length,d+=(a[b].x+a[c].x)*(a[b].x*a[c].y-a[c].x*a[b].y),e+=(a[b].y+a[c].y)*(a[b].x*a[c].y-a[c].x*a[b].y);return d*=1/(6*f),e*=1/(6*f),g.x=d,g.y=e,g},d.prototype.makeVerticesClockwise=function(a){var b,c,d=0;for(b=0;b<a.length;++b)c=(b+1)%a.length,d+=a[b].x*a[c].y-a[c].x*a[b].y;d<0&&a.reverse()},d.prototype.makeVerticesStartWithMin=function(a){var b,c,d=[],e=a.length;for(c=0,b=1;b<e;++b)a[b].x<a[c].x?c=b:a[b].x===a[c].x&&a[b].y<a[c].y&&(c=b);for(b=0;b<e;++b)d.push(a[(b+c)%a.length]);for(a.length=0,b=0;b<e;++b)a.push(d[b])},d.prototype.arePolygonsAdjacent=function(){function b(a,b){return[a,b].some(function(e){for(var f=0;f<e.length;++f){var g=c(e[f],e[(f+1)%e.length]);if(!d(k.project(a,g),k.project(b,g)))return!0}return!1})}function c(b,c){var d=a.subtract(b,c),e=a.transpose(d);return e.y*=-1,a.normalize(e)}function d(a,b){return b.max>=a.min&&a.max>=b.min}function e(a){return f(a,0).size===a.length}function f(a,b){var c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Set;if(!c.has(b)){var d=a[b];c.add(b);for(var e=0;e<d.length;++e)f(a,d[e],c)}return c}for(var g=this,h=arguments.length,i=Array(h),j=0;j<h;j++)i[j]=arguments[j];var k=this;return 1===i.length||(this.sortPolygons(i),i=i.map(function(a){return g.triangulate(a)}).reduce(function(a,b){return a.concat(b)},[]),e(i.map(function(a){return i.reduce(function(c,d,e){return a===d||b(a,d)?c:c.concat(e)},[])})))},d.prototype.project=function(b,c){return b.map(function(b){return a.dot(b,c)}).reduce(function(a,b){return(null===a.min||b<a.min)&&(a.min=b),(null===a.max||b>a.max)&&(a.max=b),a},{min:null,max:null})},d.prototype.arePolygonsCombinable=function(){if(this.arePolygonsAdjacent.apply(this,arguments))return!0;if(2!==arguments.length)return!1;var a=this.getOverlaps(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);return a.x.length+a.y.length>=2},d.prototype.combinePolygons=function(){if(this.arePolygonsAdjacent.apply(this,arguments))return this.combineAdjacentPolygons.apply(this,arguments);if(2!==arguments.length)throw new Error("Combining more than two nonadjacent polygons is not supported.");return this.combineNonadjacentPolygons.apply(this,arguments)},d.prototype.combineAdjacentPolygons=function(){for(var d=this,e=[],f=0,g=0,h=0,i=void 0,j=arguments.length,k=Array(j),l=0;l<j;l++)k[l]=arguments[l];if(k.forEach(function(a){d.makeVerticesUnique(a),d.makeVerticesClockwise(a),d.makeVerticesStartWithMin(a)}),this.sortPolygons(k),i=k[0],!this.arePolygonsAdjacent.apply(this,k))throw new Error("Cannot combine polygons because they are not adjacent.");do{if(-1!==this.indexOf(i[g],e))throw new Error("Cater-cornered polygons cannot be combined.");e.push(i[g]);for(var m={dist:null,angle:null,intPoint:null,polyInd:null,vertInd:null},n=0;n<k.length;++n)if(n!==f)for(var o=k[n],p=0;p<o.length;++p)for(var q=[i[g],i[(g+1)%i.length]],r=[o[p],o[(p+1)%o.length]],s=c.getIntersections.apply(c,q.concat(r)),t=0;t<s.length;++t)if(-1===this.indexOf(s[t],e)){var u=b.distance(i[g],s[t]),v=a.normalize(a.subtract(r[1],q[0])),w=Math.atan2(-v.y,v.x);(null===m.dist||u<m.dist||u===m.dist&&w>m.angle)&&(m.dist=u,m.angle=w,m.intPoint=s[t],m.polyInd=n,m.vertInd=p)}if(null!==m.dist){f=m.polyInd,i=k[f],g=m.vertInd;var x=b.pointsEqual(m.intPoint,i[g]),y=b.pointsEqual(m.intPoint,i[(g+1)%i.length]);x||(g=(g+1)%i.length),x||y||e.push(m.intPoint),++h}else g=(g+1)%i.length}while(!b.pointsEqual(i[g],k[0][0]));if(0===h)throw new Error("Polygons could not be combined because no intersections were found.");return this.removeExtraneousVertices(e),e},d.prototype.combineNonadjacentPolygons=function(d,e){function f(d,e,f,h,j){var k=null,l=[d,a.add(d,e)],m=c.getScaledIntercepts.apply(c,l.concat(_toConsumableArray(f))),n=a.subtract(f[1],f[0]);if(!m.length)return null;for(var o=0;o<h.length;++o)for(var p=[h[o],h[(o+1)%h.length]],q=c.getScaledIntercepts.apply(c,l.concat(p)),r=0;r<m.length;++r)for(var s=0;s<q.length;++s)if(-1===i.indexOf(q[s],j)){var t=b.distance(f[0],m[r]),u=b.distance(m[r],q[s]),v=a.getAngleBetween(n,a.subtract(q[s],m[r]));if(!(v>=0&&v<=Math.PI)){var w={distToInt:t,distToPoly:u,angle:v,fromPt:m[r],toPt:q[s],polygon:h,vertInd:o};k=g(k,w)}}return k}function g(a,b){return null===a?b:null===b?a:a.distToInt<b.distToInt?a:b.distToInt<a.distToInt?b:a.angle>b.angle?a:b.angle>a.angle?b:a.distToPoly<=b.distToPoly?a:b}var h=this,i=this,j={x:1,y:0},k={x:0,y:1},l=[d,e];l.forEach(function(a){h.makeVerticesUnique(a),h.makeVerticesClockwise(a),h.makeVerticesStartWithMin(a)}),this.sortPolygons(l);var m=this.getOverlaps(l[0],l[1]);if(m.x.length+m.y.length<2)throw new Error("Polygons cannot be combined because there are fewer than two overlaping parts.");var n=[],o=0,p=0,q=0,r=l[0],s=1e4,t=0,u=function(){if(++t,-1!==h.indexOf(r[p],n))throw new Error("Cannot combine polygons: duplicate vertex encountered.");n.push(r[p]);for(var a=[r[p],r[(p+1)%r.length]],c=[],d=null,e=function(b){if(b===o)return"continue";var d=l[b],e=m.x.map(function(b){return f({x:b,y:0},k,a,d,n)}).filter(function(a){return null!==a}),g=m.y.map(function(b){return f({x:0,y:b},j,a,d,n)}).filter(function(a){return null!==a});c.push.apply(c,_toConsumableArray(e)),c.push.apply(c,_toConsumableArray(g))},i=0;i<l.length;++i){e(i)}if(d=c.reduce(function(a,b){return g(a,b)},null)){b.pointsEqual(d.fromPt,r[p])||n.push(d.fromPt),o=l.indexOf(d.polygon),r=d.polygon,p=d.vertInd;var s=b.pointsEqual(d.toPt,r[p]),u=b.pointsEqual(d.toPt,r[(p+1)%r.length]);s||(p=(p+1)%r.length),s||u||n.push(d.toPt),++q}else p=(p+1)%r.length};do{u()}while(!b.pointsEqual(r[p],l[0][0])&&t<s);if(!q)throw new Error("Polygons could not be combined because no switches occured.");return this.removeExtraneousVertices(n),n},d.prototype.indexOf=function(a,c){for(var d=0;d<c.length;++d)if(b.pointsEqual(a,c[d]))return d;return-1},d.prototype.makeVerticesUnique=function(a){var b=a.filter(function(a,b,c){return this.indexOf(a,c)===b}.bind(this));a.length=0,b.forEach(function(b){a.push(b)})},d.prototype.removeExtraneousVertices=function(a){if(a.length<3)return a;for(var b=0;b<a.length;++b){var d=a[b],e=a[(b+1)%a.length],f=a[(b+2)%a.length];if(c.pointOnLineSegment(e,d,f))return a.splice((b+1)%a.length,1),this.removeExtraneousVertices(a)}return a},d.prototype.sortPolygons=function(a){return a.sort(function(a,b){var c=Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.x}))),d=Math.min.apply(Math,_toConsumableArray(b.map(function(a){return a.x})));return c!==d?c-d:Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.y})))-Math.min.apply(Math,_toConsumableArray(b.map(function(a){return a.y})))})},d.prototype.getCircumference=function(a){return a.reduce(function(a,c,d,e){return a+b.distance(c,e[(d+1)%e.length])},0)},d.prototype.triangulate=function(b){function c(b){if(3===b.length){var c=[b[0],b[1],b[2]];return d.makeVerticesStartWithMin(c),b.splice(0,1),c}for(var e=function(c){var e=[b[0===c?b.length-1:c-1],b[c],b[(c+1)%b.length]],f=a.subtract(e[0],e[1]),g=a.subtract(e[2],e[1]);if(a.cross(f,g)<0&&!b.some(function(a){return-1===d.indexOf(a,e)&&d.polygonContainsPoint(e,a)}))return d.makeVerticesStartWithMin(e),b.splice(c,1),{v:e}},f=0;f<b.length;++f){var g=e(f);if("object"===(void 0===g?"undefined":_typeof(g)))return g.v}throw new Error("Failed to clip ear.")}var d=this,e=[];if(b.length<3)throw new Error("Polygon cannot be clipped because it has fewer than three vertices.");b=b.slice();do{e.push(c(b))}while(b.length>=3);return e},d.prototype.polygonContainsPoint=function(a,b){var d=Math.max.apply(Math,_toConsumableArray(a.map(function(a){return a.x}))),e=Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.x}))),f=Math.max.apply(Math,_toConsumableArray(a.map(function(a){return a.y}))),g=Math.min.apply(Math,_toConsumableArray(a.map(function(a){return a.y})));if(b.x<e)return!1;if(b.x>d)return!1;if(b.y<g)return!1;if(b.y>f)return!1;for(var h=[b,{x:d,y:b.y}],i=[],j=0;j<a.length;++j){var k=[a[j],a[(j+1)%a.length]];if(c.pointOnLineSegment(b,k[0],k[1]))return!0;var l=c.getIntersections(h[0],h[1],k[0],k[1]);l.length&&-1===this.indexOf(l[0],i)&&i.push(l[0])}return i.length%2!=0},d.prototype.getParallelEdges=function(a){for(var b=[],d=0;d<a.length;++d)for(var e=[a[d],a[(d+1)%a.length]],f=d+2;f<a.length;++f){var g=[a[f],a[(f+1)%a.length]];c.areLineSegmentsParallel.apply(c,e.concat(g))&&!c.areLineSegmentsCollinear.apply(c,e.concat(g))&&b.push([e,g])}return b},d.prototype.getOverlaps=function(a,b){function c(a,b){var c=[];return a.min>=b.min&&a.min<=b.max&&c.push(a.min),a.max>=b.min&&a.max<=b.max&&c.push(a.max),b.min>=a.min&&b.min<=a.max&&c.push(b.min),b.max>=a.min&&b.max<=a.max&&c.push(b.max),c.filter(function(a,b,c){return c.indexOf(a)===b}).sort()}var d=this,e={x:1,y:0},f={x:0,y:1},g=[a,b].map(function(a){return d.project(a,e)}),h=[a,b].map(function(a){return d.project(a,f)});return{x:c(g[0],g[1]),y:c(h[0],h[1])}},new d}]),angular.module("AMC.Graphics").factory("vectorMath",[function(){function a(){}return a.prototype.subtract=function(a,b){return{x:a.x-b.x,y:a.y-b.y}},a.prototype.add=function(a,b){return{x:a.x+b.x,y:a.y+b.y}},a.prototype.multiplyScalar=function(a,b){return{x:a.x*b,y:a.y*b}},a.prototype.transpose=function(a){return{x:a.y,y:a.x}},a.prototype.dot=function(a,b){return a.x*b.x+a.y*b.y},a.prototype.cross=function(a,b){return a.x*b.y-a.y*b.x},a.prototype.length=function(a){return Math.sqrt(Math.pow(a.x,2)+Math.pow(a.y,2))},a.prototype.normalize=function(a){var b=this.length(a);if(0===b)throw new Error("Cannot normalize a vector of length 0.");return this.multiplyScalar(a,1/b)},a.prototype.getAngleBetween=function(a,b){var c=Math.atan2(a.y,a.x),d=Math.atan2(b.y,b.x),e=d-c;return e<0&&(e+=2*Math.PI),e},new a}]),angular.module("AMC.Graphics").factory("ViewingTransformer",["matrixHelper",function(a){function b(b,c){this._vtm=a.createSVGMatrix(),this._wndWidth=b,this._wndHeight=c,this._aspectRatio=b/c}return b.prototype.getScale=function(){return a.getScale(this._vtm)},b.prototype.getTranslate=function(){return a.getTranslation(this._vtm)},b.prototype.getVTM=function(){return this._vtm},b.prototype.getInverseVTM=function(){return this.getVTM().inverse()},b.prototype.zoom=function(a,b,c){null!==b&&void 0!==b||(b=1/this._aspectRatio*a);var d=(this._wndWidth+a)/this._wndWidth,e=(this._wndHeight+b)/this._wndHeight;return this.scale(d,e,c)},b.prototype.scale=function(b,c,d){return d=d||{x:this._wndWidth/2,y:this._wndHeight/2},this._vtm=a.createSVGMatrix().translate(d.x,d.y).scaleNonUniform(b,c).translate(-d.x,-d.y).multiply(this._vtm),this.getVTM()},b.prototype.pan=function(b,c){return this._vtm=a.createSVGMatrix().translate(-b,-c).multiply(this._vtm),this.getVTM()},b.prototype.panUp=function(a){return this.pan(0,-a)},b.prototype.panDown=function(a){return this.pan(0,a)},b.prototype.panLeft=function(a){return this.pan(-a,0)},b.prototype.panRight=function(a){return this.pan(a,0)},b.prototype.worldToWindowUnits=function(a){return a.matrixTransform(this.getInverseVTM())},b.prototype.clone=function(){var b=JSON.parse(JSON.stringify(this));return b._vtm=a.cloneMatrix(this._vtm),b},b.prototype.restore=function(b){for(var c in b)this[c]=b[c];this._vtm=a.cloneMatrix(b._vtm)},b}]);
{
"name": "@benningfield-group/amc-graphics",
"version": "1.3.2",
"version": "1.3.3",
"description": "Graphics math for AMC.",

@@ -5,0 +5,0 @@ "main": "AMC.Graphics.js",

@@ -6,9 +6,7 @@ /**

.factory('linearMath',
['vectorMath', 'pointMath',
function(vectorMath, pointMath)
['vectorMath', 'pointMath', 'EPSILON',
function(vectorMath, pointMath, EPSILON)
{
'use strict';
const EPSILON = 1e-6;
/**

@@ -15,0 +13,0 @@ * This class is a service - no state.

/**
* Class for performing math on 2D points.
*/
angular.module('AMC.Graphics').factory('pointMath', [function()
angular.module('AMC.Graphics').factory('pointMath', ['EPSILON', function(EPSILON)
{

@@ -30,3 +30,3 @@ 'use strict';

{
return p1.x === p2.x && p1.y === p2.y;
return Math.abs(p1.x - p2.x) < EPSILON && Math.abs(p1.y - p2.y) < EPSILON;
};

@@ -41,5 +41,8 @@

{
if (p1.x === p2.x)
return p1.y < p2.y;
const xDif = Math.abs(p1.x - p2.x);
const yDif = Math.abs(p1.y - p2.y);
if (xDif < EPSILON)
return yDif > EPSILON && p1.y < p2.y;
return p1.x < p2.x;

@@ -55,5 +58,8 @@ };

{
if (p1.x === p2.x)
return p1.y > p2.y;
const xDif = Math.abs(p1.x - p2.x);
const yDif = Math.abs(p1.y - p2.y);
if (xDif < EPSILON)
return yDif > EPSILON && p1.y > p2.y;
return p1.x > p2.x;

@@ -60,0 +66,0 @@ };

@@ -440,2 +440,30 @@ describe('polygonMath', function() {

});
it('combines polygons that are very nearly touching..', function() {
// These are taken from a live floor plan, and the y points are very
// close but not quite touching.
const polygons = [
[
{x: 1.375999927520752, y: 382.878997802734380},
{x: 22.128000259399414, y: 382.878997802734380},
{x: 22.128000259399414, y: 394.680999755859380},
{x: 0.375999927520752, y: 394.680999755859380},
],
[
{x: 0.375999927520752, y: 394.680969238281250},
{x: 22.128000259399414, y: 394.680969238281250},
{x: 22.128000259399414, y: 409.433471679687500},
{x: 0.375999927520752, y: 409.433471679687500},
],
[
{x: 0.375999927520752, y: 409.433410644531250},
{x: 22.128000259399414, y: 409.433410644531250},
{x: 22.128000259399414, y: 421.234985351562500},
{x: 7.375999927520752, y: 421.234985351562500},
],
];
expect(() => polygonMath.combineAdjacentPolygons(...polygons))
.not.toThrow();
});
});

@@ -442,0 +470,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc