overlap-area
Advanced tools
Comparing version 0.3.1 to 0.3.3
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/overlap-area.git | ||
version: 0.3.1 | ||
version: 0.3.3 | ||
*/ | ||
@@ -46,2 +46,6 @@ 'use strict'; | ||
function getAreaSize(points) { | ||
if (points.length < 3) { | ||
return 0; | ||
} | ||
return Math.abs(utils.sum(points.map(function (point, i) { | ||
@@ -48,0 +52,0 @@ var nextPoint = points[i + 1] || points[0]; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/overlap-area.git | ||
version: 0.3.1 | ||
version: 0.3.3 | ||
*/ | ||
@@ -44,2 +44,6 @@ import { sum, findIndex, getShapeDirection, getDist } from '@daybrush/utils'; | ||
function getAreaSize(points) { | ||
if (points.length < 3) { | ||
return 0; | ||
} | ||
return Math.abs(sum(points.map(function (point, i) { | ||
@@ -46,0 +50,0 @@ var nextPoint = points[i + 1] || points[0]; |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/overlap-area.git | ||
version: 0.3.1 | ||
version: 0.3.3 | ||
*/ | ||
@@ -163,2 +163,6 @@ (function (global, factory) { | ||
function getAreaSize(points) { | ||
if (points.length < 3) { | ||
return 0; | ||
} | ||
return Math.abs(sum(points.map(function (point, i) { | ||
@@ -165,0 +169,0 @@ var nextPoint = points[i + 1] || points[0]; |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/overlap-area.git | ||
version: 0.3.1 | ||
version: 0.3.3 | ||
*/ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n=n||self).OverlapArea=t()}(this,function(){"use strict";function m(n,t,r){void 0===r&&(r=-1);for(var e=n.length,u=0;u<e;++u)if(t(n[u],u,n))return u;return r}function e(n,t){var r=t[0]-n[0],n=t[1]-n[1],r=Math.atan2(n,r);return 0<=r?r:r+2*Math.PI}function u(n){return[0,1].map(function(t){return function(n){for(var t=n.length,r=0,e=t-1;0<=e;--e)r+=n[e];return t?r/t:0}(n.map(function(n){return n[t]}))})}function i(n){var t=u(n),r=e(t,n[0]),n=e(t,n[1]);return r<n&&n-r<Math.PI||n<r&&n-r<-Math.PI?1:-1}function h(n,t){return Math.sqrt(Math.pow((t?t[0]:0)-n[0],2)+Math.pow((t?t[1]:0)-n[1],2))}function r(r){return Math.abs(function(n){for(var t=0,r=n.length-1;0<=r;--r)t+=n[r];return t}(r.map(function(n,t){t=r[t+1]||r[0];return n[0]*t[1]-t[0]*n[1]})))/2}function v(n){var t=n.map(function(n){return n[0]}),n=n.map(function(n){return n[1]});return{minX:Math.min.apply(Math,t),minY:Math.min.apply(Math,n),maxX:Math.max.apply(Math,t),maxY:Math.max.apply(Math,n)}}function s(n,t,r){var u=n[0],i=n[1],e=v(t),a=e.minX,o=e.minY,n=e.maxX,e=e.maxY,f=[[a,i],[n,i]],p=[[u,o],[u,e]],c=M(f[0],f[1]),h=M(p[0],p[1]),t=y(t),s=[],l=[];return t.forEach(function(n){var t=M(n[0],n[1]),r=d(x(c,t),[f,n]),e=d(x(h,t),[p,n]);1===r.length&&n[0][1]===i||s.push.apply(s,r),1===e.length&&n[0][0]===u||l.push.apply(l,e),t[0]||s.push.apply(s,r),t[1]||l.push.apply(l,e)}),!r&&(-1<m(s,function(n){return n[0]===u})||-1<m(l,function(n){return n[1]===i}))||!!(s.filter(function(n){return n[0]>u}).length%2&&l.filter(function(n){return n[1]>i}).length%2)}function M(n,t){var r=n[0],e=n[1],n=t[0],t=t[1];if(r===n&&e===t)return[0,0,0];if(r===n)return[1,0,-r];if(e===t)return[0,1,-e];t=(n-r)/(e-t);return[1,t,-r-t*e]}function x(n,t){var r,e,u=n[0],i=n[1],a=n[2],o=t[0],f=t[1],p=t[2],n=0===u&&0===o,t=0===i&&0===f;if(n&&t)return[];if(n){n=-a/i;return n!=-p/f?[]:[[-1/0,n],[1/0,n]]}if(t){t=-a/u;return t!=-p/o?[]:[[t,-1/0],[t,1/0]]}return 0!==u?0!==o?0!==i?0!==f?[[r=(i*p-f*a)/(f*u-i*o),e=-(u*r+a)/i]]:[[r=-p/o,e=-(u*r+a)/i]]:[[r=-a/u,e=-(o*r+p)/f]]:[[r=-(i*(e=-p/f)+a)/u,e]]:[[r=-(f*(e=-a/i)+p)/o,e]]}function d(n,t){var r=t.map(function(t){return[0,1].map(function(n){return[Math.min(t[0][n],t[1][n]),Math.max(t[0][n],t[1][n])]})});if(2===n.length){var e=n[0],u=e[0],t=e[1];if(u===n[1][0]){var e=Math.max.apply(Math,r.map(function(n){return n[1][0]})),i=Math.min.apply(Math,r.map(function(n){return n[1][1]}));return i<e?[]:[[u,e],[u,i]]}if(t===n[1][1]){u=Math.max.apply(Math,r.map(function(n){return n[0][0]})),i=Math.min.apply(Math,r.map(function(n){return n[0][1]}));return i<u?[]:[[u,t],[i,t]]}}return n.filter(function(t){return r.every(function(n){return n[0][0]<=t[0]&&t[0]<=n[0][1]&&n[1][0]<=t[1]&&t[1]<=n[1][1]})})}function y(r){return function(){for(var n=0,t=0,r=arguments.length;t<r;t++)n+=arguments[t].length;for(var e=Array(n),u=0,t=0;t<r;t++)for(var i=arguments[t],a=0,o=i.length;a<o;a++,u++)e[u]=i[a];return e}(r.slice(1),[r[0]]).map(function(n,t){return[r[t],n]})}function a(n,t){var u=n.slice(),a=t.slice();-1===i(u)&&u.reverse(),-1===i(a)&&a.reverse();var o=y(u),f=y(a),t=o.map(function(n){return M(n[0],n[1])}),p=f.map(function(n){return M(n[0],n[1])}),c=[];t.forEach(function(r,e){var u=o[e],i=[];p.forEach(function(n,t){n=d(x(r,n),[u,f[t]]);i.push.apply(i,n.map(function(n){return{index1:e,index2:t,pos:n}}))}),i.sort(function(n,t){return h(u[0],n.pos)-h(u[0],t.pos)}),c.push.apply(c,i),s(u[1],a)&&c.push({index1:e,index2:-1,pos:u[1]})}),f.forEach(function(n,r){var e,t;s(n[1],u)&&(e=!1,-1===(t=m(c,function(n){return n.index2!==r?!!e:void(e=!0)}))&&(e=!1,t=m(c,function(n){var t=n.index1,n=n.index2;if(-1!==t||n+1!==r)return!!e;e=!0})),-1===t?c.push({index1:-1,index2:r,pos:n[1]}):c.splice(t,0,{index1:-1,index2:r,pos:n[1]}))});var t=c.map(function(n){return n.pos}),r={};return t.filter(function(n){n=n[0]+"x"+n[1];return!r[n]&&(r[n]=!0)})}return{__proto__:null,getAreaSize:r,getMinMaxs:v,isInside:s,getLinearConstants:M,getIntersectionPointsByConstants:x,getIntersectionPoints:function(n,t,r){var e=x(M(n[0],n[1]),M(t[0],t[1]));return r?d(e,[n,t]):e},getPointsOnLines:d,convertLines:y,getOverlapPoints:a,getOverlapSize:function(n,t){return r(a(n,t))}}}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n=n||self).OverlapArea=t()}(this,function(){"use strict";function m(n,t,r){void 0===r&&(r=-1);for(var e=n.length,u=0;u<e;++u)if(t(n[u],u,n))return u;return r}function e(n,t){var r=t[0]-n[0],n=t[1]-n[1],r=Math.atan2(n,r);return 0<=r?r:r+2*Math.PI}function u(n){return[0,1].map(function(t){return function(n){for(var t=n.length,r=0,e=t-1;0<=e;--e)r+=n[e];return t?r/t:0}(n.map(function(n){return n[t]}))})}function i(n){var t=u(n),r=e(t,n[0]),n=e(t,n[1]);return r<n&&n-r<Math.PI||n<r&&n-r<-Math.PI?1:-1}function h(n,t){return Math.sqrt(Math.pow((t?t[0]:0)-n[0],2)+Math.pow((t?t[1]:0)-n[1],2))}function r(r){return r.length<3?0:Math.abs(function(n){for(var t=0,r=n.length-1;0<=r;--r)t+=n[r];return t}(r.map(function(n,t){t=r[t+1]||r[0];return n[0]*t[1]-t[0]*n[1]})))/2}function v(n){var t=n.map(function(n){return n[0]}),n=n.map(function(n){return n[1]});return{minX:Math.min.apply(Math,t),minY:Math.min.apply(Math,n),maxX:Math.max.apply(Math,t),maxY:Math.max.apply(Math,n)}}function s(n,t,r){var u=n[0],i=n[1],e=v(t),a=e.minX,o=e.minY,n=e.maxX,e=e.maxY,f=[[a,i],[n,i]],p=[[u,o],[u,e]],c=M(f[0],f[1]),h=M(p[0],p[1]),t=g(t),s=[],l=[];return t.forEach(function(n){var t=M(n[0],n[1]),r=d(x(c,t),[f,n]),e=d(x(h,t),[p,n]);1===r.length&&n[0][1]===i||s.push.apply(s,r),1===e.length&&n[0][0]===u||l.push.apply(l,e),t[0]||s.push.apply(s,r),t[1]||l.push.apply(l,e)}),!r&&(-1<m(s,function(n){return n[0]===u})||-1<m(l,function(n){return n[1]===i}))||!!(s.filter(function(n){return n[0]>u}).length%2&&l.filter(function(n){return n[1]>i}).length%2)}function M(n,t){var r=n[0],e=n[1],n=t[0],t=t[1];if(r===n&&e===t)return[0,0,0];if(r===n)return[1,0,-r];if(e===t)return[0,1,-e];t=(n-r)/(e-t);return[1,t,-r-t*e]}function x(n,t){var r,e,u=n[0],i=n[1],a=n[2],o=t[0],f=t[1],p=t[2],n=0===u&&0===o,t=0===i&&0===f;if(n&&t)return[];if(n){n=-a/i;return n!=-p/f?[]:[[-1/0,n],[1/0,n]]}if(t){t=-a/u;return t!=-p/o?[]:[[t,-1/0],[t,1/0]]}return 0!==u?0!==o?0!==i?0!==f?[[r=(i*p-f*a)/(f*u-i*o),e=-(u*r+a)/i]]:[[r=-p/o,e=-(u*r+a)/i]]:[[r=-a/u,e=-(o*r+p)/f]]:[[r=-(i*(e=-p/f)+a)/u,e]]:[[r=-(f*(e=-a/i)+p)/o,e]]}function d(n,t){var r=t.map(function(t){return[0,1].map(function(n){return[Math.min(t[0][n],t[1][n]),Math.max(t[0][n],t[1][n])]})});if(2===n.length){var e=n[0],u=e[0],t=e[1];if(u===n[1][0]){var e=Math.max.apply(Math,r.map(function(n){return n[1][0]})),i=Math.min.apply(Math,r.map(function(n){return n[1][1]}));return i<e?[]:[[u,e],[u,i]]}if(t===n[1][1]){u=Math.max.apply(Math,r.map(function(n){return n[0][0]})),i=Math.min.apply(Math,r.map(function(n){return n[0][1]}));return i<u?[]:[[u,t],[i,t]]}}return n.filter(function(t){return r.every(function(n){return n[0][0]<=t[0]&&t[0]<=n[0][1]&&n[1][0]<=t[1]&&t[1]<=n[1][1]})})}function g(r){return function(){for(var n=0,t=0,r=arguments.length;t<r;t++)n+=arguments[t].length;for(var e=Array(n),u=0,t=0;t<r;t++)for(var i=arguments[t],a=0,o=i.length;a<o;a++,u++)e[u]=i[a];return e}(r.slice(1),[r[0]]).map(function(n,t){return[r[t],n]})}function a(n,t){var u=n.slice(),a=t.slice();-1===i(u)&&u.reverse(),-1===i(a)&&a.reverse();var o=g(u),f=g(a),t=o.map(function(n){return M(n[0],n[1])}),p=f.map(function(n){return M(n[0],n[1])}),c=[];t.forEach(function(r,e){var u=o[e],i=[];p.forEach(function(n,t){n=d(x(r,n),[u,f[t]]);i.push.apply(i,n.map(function(n){return{index1:e,index2:t,pos:n}}))}),i.sort(function(n,t){return h(u[0],n.pos)-h(u[0],t.pos)}),c.push.apply(c,i),s(u[1],a)&&c.push({index1:e,index2:-1,pos:u[1]})}),f.forEach(function(n,r){var e,t;s(n[1],u)&&(e=!1,-1===(t=m(c,function(n){return n.index2!==r?!!e:void(e=!0)}))&&(e=!1,t=m(c,function(n){var t=n.index1,n=n.index2;if(-1!==t||n+1!==r)return!!e;e=!0})),-1===t?c.push({index1:-1,index2:r,pos:n[1]}):c.splice(t,0,{index1:-1,index2:r,pos:n[1]}))});var t=c.map(function(n){return n.pos}),r={};return t.filter(function(n){n=n[0]+"x"+n[1];return!r[n]&&(r[n]=!0)})}return{__proto__:null,getAreaSize:r,getMinMaxs:v,isInside:s,getLinearConstants:M,getIntersectionPointsByConstants:x,getIntersectionPoints:function(n,t,r){var e=x(M(n[0],n[1]),M(t[0],t[1]));return r?d(e,[n,t]):e},getPointsOnLines:d,convertLines:g,getOverlapPoints:a,getOverlapSize:function(n,t){return r(a(n,t))}}}); | ||
//# sourceMappingURL=overlap-area.min.js.map |
{ | ||
"name": "overlap-area", | ||
"version": "0.3.1", | ||
"version": "0.3.3", | ||
"description": "Find the Overlap Area.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/overlap-area.cjs.js", |
@@ -13,2 +13,5 @@ import { sum, findIndex, getShapeDirection, getDist } from "@daybrush/utils"; | ||
export function getAreaSize(points: number[][]) { | ||
if (points.length < 3) { | ||
return 0; | ||
} | ||
return Math.abs(sum(points.map((point, i) => { | ||
@@ -15,0 +18,0 @@ const nextPoint = points[i + 1] || points[0]; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165411
1947