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

overlap-area

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

overlap-area - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

20

dist/overlap-area.cjs.js

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/daybrush/overlap-area.git
version: 0.2.0
version: 0.3.0
*/

@@ -99,5 +99,11 @@ 'use strict';

var yPoints = getPointsOnLines(getIntersectionPointsByConstants(yLinearConstants, linearConstants), [yLine, line]);
intersectionXPoints.push.apply(intersectionXPoints, xPoints);
intersectionYPoints.push.apply(intersectionYPoints, yPoints);
if (xPoints.length === 1 ? line[0][1] !== y : true) {
intersectionXPoints.push.apply(intersectionXPoints, xPoints);
}
if (yPoints.length === 1 ? line[0][0] !== x : true) {
intersectionYPoints.push.apply(intersectionYPoints, yPoints);
}
if (!linearConstants[0]) {

@@ -177,4 +183,8 @@ intersectionXPoints.push.apply(intersectionXPoints, xPoints);

c2 = linearConstants2[2];
var isZeroA = a1 === 0 && a2 === 0;
var isZeroB = b1 === 0 && b2 === 0;
if (a1 === 0 && a2 === 0) {
if (isZeroA && isZeroB) {
return [];
} else if (isZeroA) {
// b1 * y + c1 = 0

@@ -190,3 +200,3 @@ // b2 * y + c2 = 0

}
} else if (b1 === 0 && b2 === 0) {
} else if (isZeroB) {
// a1 * x + c1 = 0

@@ -193,0 +203,0 @@ // a2 * x + c2 = 0

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/daybrush/overlap-area.git
version: 0.2.0
version: 0.3.0
*/

@@ -97,5 +97,11 @@ import { sum, findIndex, getShapeDirection, getDist } from '@daybrush/utils';

var yPoints = getPointsOnLines(getIntersectionPointsByConstants(yLinearConstants, linearConstants), [yLine, line]);
intersectionXPoints.push.apply(intersectionXPoints, xPoints);
intersectionYPoints.push.apply(intersectionYPoints, yPoints);
if (xPoints.length === 1 ? line[0][1] !== y : true) {
intersectionXPoints.push.apply(intersectionXPoints, xPoints);
}
if (yPoints.length === 1 ? line[0][0] !== x : true) {
intersectionYPoints.push.apply(intersectionYPoints, yPoints);
}
if (!linearConstants[0]) {

@@ -175,4 +181,8 @@ intersectionXPoints.push.apply(intersectionXPoints, xPoints);

c2 = linearConstants2[2];
var isZeroA = a1 === 0 && a2 === 0;
var isZeroB = b1 === 0 && b2 === 0;
if (a1 === 0 && a2 === 0) {
if (isZeroA && isZeroB) {
return [];
} else if (isZeroA) {
// b1 * y + c1 = 0

@@ -188,3 +198,3 @@ // b2 * y + c2 = 0

}
} else if (b1 === 0 && b2 === 0) {
} else if (isZeroB) {
// a1 * x + c1 = 0

@@ -191,0 +201,0 @@ // a2 * x + c2 = 0

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/daybrush/overlap-area.git
version: 0.2.0
version: 0.3.0
*/

@@ -216,5 +216,11 @@ (function (global, factory) {

var yPoints = getPointsOnLines(getIntersectionPointsByConstants(yLinearConstants, linearConstants), [yLine, line]);
intersectionXPoints.push.apply(intersectionXPoints, xPoints);
intersectionYPoints.push.apply(intersectionYPoints, yPoints);
if (xPoints.length === 1 ? line[0][1] !== y : true) {
intersectionXPoints.push.apply(intersectionXPoints, xPoints);
}
if (yPoints.length === 1 ? line[0][0] !== x : true) {
intersectionYPoints.push.apply(intersectionYPoints, yPoints);
}
if (!linearConstants[0]) {

@@ -294,4 +300,8 @@ intersectionXPoints.push.apply(intersectionXPoints, xPoints);

c2 = linearConstants2[2];
var isZeroA = a1 === 0 && a2 === 0;
var isZeroB = b1 === 0 && b2 === 0;
if (a1 === 0 && a2 === 0) {
if (isZeroA && isZeroB) {
return [];
} else if (isZeroA) {
// b1 * y + c1 = 0

@@ -307,3 +317,3 @@ // b2 * y + c2 = 0

}
} else if (b1 === 0 && b2 === 0) {
} else if (isZeroB) {
// a1 * x + c1 = 0

@@ -310,0 +320,0 @@ // a2 * x + c2 = 0

@@ -7,5 +7,5 @@ /*

repository: git+https://github.com/daybrush/overlap-area.git
version: 0.2.0
version: 0.3.0
*/
!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 s(n,t,r){void 0===r&&(r=-1);for(var u=n.length,e=0;e<u;++e)if(t(n[e],e,n))return e;return r}function l(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 m(n){return[0,1].map(function(t){return function(n){for(var t=n.length,r=0,u=t-1;0<=u;--u)r+=n[u];return t?r/t:0}(n.map(function(n){return n[t]}))})}function M(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 y(n,t,r){var u=n[0],e=n[1],a=v(t),i=a.minX,o=a.minY,n=a.maxX,a=a.maxY,f=[[i,e],[n,e]],p=[[u,o],[u,a]],c=g(f[0],f[1]),h=g(p[0],p[1]),t=P(t),l=[],m=[];return t.forEach(function(n){var t=g(n[0],n[1]),r=d(x(c,t),[f,n]),n=d(x(h,t),[p,n]);l.push.apply(l,r),m.push.apply(m,n),t[0]||l.push.apply(l,r),t[1]||m.push.apply(m,n)}),!r&&(-1<s(l,function(n){return n[0]===u})||-1<s(m,function(n){return n[1]===e}))||!!(l.filter(function(n){return n[0]>u}).length%2&&m.filter(function(n){return n[1]>e}).length%2)}function g(n,t){var r=n[0],u=n[1],n=t[0],t=t[1];if(r===n&&u===t)return[0,0,0];if(r===n)return[1,0,-r];if(u===t)return[0,1,-u];t=(n-r)/(u-t);return[1,t,-r-t*u]}function x(n,t){var r=n[0],u=n[1],e=n[2],a=t[0],i=t[1],n=t[2];if(0===r&&0===a){t=-e/u;return t!=-n/i?[]:[[-1/0,t],[1/0,t]]}if(0!==u||0!==i)return 0!==r?0!==a?0!==u?0!==i?[[o=(u*n-i*e)/(i*r-u*a),f=-(r*o+e)/u]]:[[o=-n/a,f=-(r*o+e)/u]]:[[o=-e/r,f=-(a*o+n)/i]]:[[o=-(u*(f=-n/i)+e)/r,f]]:[[o=-(i*(f=-e/u)+n)/a,f]];var o,f,r=-e/r;return r!=-n/a?[]:[[r,-1/0],[r,1/0]]}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 u=n[0],e=u[0],t=u[1];if(e===n[1][0]){var u=Math.max.apply(Math,r.map(function(n){return n[1][0]})),a=Math.min.apply(Math,r.map(function(n){return n[1][1]}));return a<u?[]:[[e,u],[e,a]]}if(t===n[1][1]){e=Math.max.apply(Math,r.map(function(n){return n[0][0]})),a=Math.min.apply(Math,r.map(function(n){return n[0][1]}));return a<e?[]:[[e,t],[a,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 P(r){return function(){for(var n=0,t=0,r=arguments.length;t<r;t++)n+=arguments[t].length;for(var u=Array(n),e=0,t=0;t<r;t++)for(var a=arguments[t],i=0,o=a.length;i<o;i++,e++)u[e]=a[i];return u}(r.slice(1),[r[0]]).map(function(n,t){return[r[t],n]})}function u(t,a){var n,r,u,i=P(t),o=P(a),e=i.map(function(n){return g(n[0],n[1])}),f=o.map(function(n){return g(n[0],n[1])}),p=[],c=(r=m(n=a),u=l(r,n[0]),n=l(r,n[1]),u<n&&n-u<Math.PI||n<u&&n-u<-Math.PI?1:-1);o.forEach(function(n){y(n[1],t)&&p[0<c?"push":"unshift"](n[1])}),e.forEach(function(r,n){var u=i[n],e=[];f.forEach(function(n,t){t=d(x(r,n),[u,o[t]]);e.push.apply(e,t)}),e.sort(function(n,t){return M(u[0],n)-M(u[0],t)}),p.push.apply(p,e),y(u[1],a)&&p.push(u[1])});var h={};return p.filter(function(n){n=n[0]+"x"+n[1];return!h[n]&&(h[n]=!0)})}return{__proto__:null,getAreaSize:r,getMinMaxs:v,isInside:y,getLinearConstants:g,getIntersectionPointsByConstants:x,getIntersectionPoints:function(n,t,r){var u=x(g(n[0],n[1]),g(t[0],t[1]));return r?d(u,[n,t]):u},getPointsOnLines:d,convertLines:P,getOverlapPoints:u,getOverlapSize:function(n,t){return r(u(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 s(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 l(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 m(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 M(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 y(n,t,r){var u=n[0],a=n[1],e=v(t),i=e.minX,f=e.minY,n=e.maxX,e=e.maxY,o=[[i,a],[n,a]],p=[[u,f],[u,e]],c=g(o[0],o[1]),h=g(p[0],p[1]),t=P(t),l=[],m=[];return t.forEach(function(n){var t=g(n[0],n[1]),r=d(x(c,t),[o,n]),e=d(x(h,t),[p,n]);1===r.length&&n[0][1]===a||l.push.apply(l,r),1===e.length&&n[0][0]===u||m.push.apply(m,e),t[0]||l.push.apply(l,r),t[1]||m.push.apply(m,e)}),!r&&(-1<s(l,function(n){return n[0]===u})||-1<s(m,function(n){return n[1]===a}))||!!(l.filter(function(n){return n[0]>u}).length%2&&m.filter(function(n){return n[1]>a}).length%2)}function g(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],a=n[1],i=n[2],f=t[0],o=t[1],p=t[2],n=0===u&&0===f,t=0===a&&0===o;if(n&&t)return[];if(n){n=-i/a;return n!=-p/o?[]:[[-1/0,n],[1/0,n]]}if(t){t=-i/u;return t!=-p/f?[]:[[t,-1/0],[t,1/0]]}return 0!==u?0!==f?0!==a?0!==o?[[r=(a*p-o*i)/(o*u-a*f),e=-(u*r+i)/a]]:[[r=-p/f,e=-(u*r+i)/a]]:[[r=-i/u,e=-(f*r+p)/o]]:[[r=-(a*(e=-p/o)+i)/u,e]]:[[r=-(o*(e=-i/a)+p)/f,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]})),a=Math.min.apply(Math,r.map(function(n){return n[1][1]}));return a<e?[]:[[u,e],[u,a]]}if(t===n[1][1]){u=Math.max.apply(Math,r.map(function(n){return n[0][0]})),a=Math.min.apply(Math,r.map(function(n){return n[0][1]}));return a<u?[]:[[u,t],[a,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 P(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 a=arguments[t],i=0,f=a.length;i<f;i++,u++)e[u]=a[i];return e}(r.slice(1),[r[0]]).map(function(n,t){return[r[t],n]})}function e(t,a){var n,r,e,i=P(t),f=P(a),u=i.map(function(n){return g(n[0],n[1])}),o=f.map(function(n){return g(n[0],n[1])}),p=[],c=(r=m(n=a),e=l(r,n[0]),n=l(r,n[1]),e<n&&n-e<Math.PI||n<e&&n-e<-Math.PI?1:-1);f.forEach(function(n){y(n[1],t)&&p[0<c?"push":"unshift"](n[1])}),u.forEach(function(r,n){var e=i[n],u=[];o.forEach(function(n,t){t=d(x(r,n),[e,f[t]]);u.push.apply(u,t)}),u.sort(function(n,t){return M(e[0],n)-M(e[0],t)}),p.push.apply(p,u),y(e[1],a)&&p.push(e[1])});var h={};return p.filter(function(n){n=n[0]+"x"+n[1];return!h[n]&&(h[n]=!0)})}return{__proto__:null,getAreaSize:r,getMinMaxs:v,isInside:y,getLinearConstants:g,getIntersectionPointsByConstants:x,getIntersectionPoints:function(n,t,r){var e=x(g(n[0],n[1]),g(t[0],t[1]));return r?d(e,[n,t]):e},getPointsOnLines:d,convertLines:P,getOverlapPoints:e,getOverlapSize:function(n,t){return r(e(n,t))}}});
//# sourceMappingURL=overlap-area.min.js.map
{
"name": "overlap-area",
"version": "0.2.0",
"description": "Find the overlap area.",
"version": "0.3.0",
"description": "Find the Overlap Area.",
"main": "./dist/overlap-area.cjs.js",

@@ -6,0 +6,0 @@ "module": "./dist/overlap-area.esm.js",

@@ -9,3 +9,3 @@

</p>
<p align="middle">Find the overlap area.</p>
<p align="middle">Find the Overlap Area.</p>

@@ -26,3 +26,27 @@ ## 📄 API Documents

```ts
import { getOverlapPoints, getOverlapSize } from "overlap-area";
import { isInside, getOverlapPoints, getOverlapSize } from "overlap-area";
const points1 = [
[0, 0],
[100, 0],
[120, 100],
[0, 100],
];
const points2 = [
[100, 0],
[150, 0],
[150, 100],
[100, 100],
];
// true
console.log(isInside([50, 50], points1));
// false
console.log(isInside([50, 50], points2));
// [100, 0], [120, 100], [100, 100]
console.log(getOverlapPoints(points1, points2));
// 1000
console.log(getOverlapSize(points1, points2));
```

@@ -29,0 +53,0 @@

@@ -62,4 +62,8 @@ import { sum, findIndex, getShapeDirection, getDist } from "@daybrush/utils";

intersectionXPoints.push(...xPoints);
intersectionYPoints.push(...yPoints);
if (xPoints.length === 1 ? line[0][1] !== y : true) {
intersectionXPoints.push(...xPoints);
}
if (yPoints.length === 1 ? line[0][0] !== x : true) {
intersectionYPoints.push(...yPoints);
}

@@ -136,3 +140,7 @@ if (!linearConstants[0]) {

if (a1 === 0 && a2 === 0) {
const isZeroA = a1 === 0 && a2 === 0;
const isZeroB = b1 === 0 && b2 === 0;
if (isZeroA && isZeroB) {
return [];
} else if (isZeroA) {
// b1 * y + c1 = 0

@@ -151,3 +159,3 @@ // b2 * y + c2 = 0

}
} else if (b1 === 0 && b2 === 0) {
} else if (isZeroB) {
// a1 * x + c1 = 0

@@ -154,0 +162,0 @@ // a2 * x + c2 = 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

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