path-intersection
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
/** | ||
@@ -67,3 +65,3 @@ * This file contains source code adapted from Snap.svg (licensed Apache-2.0). | ||
count.push(args); | ||
cache[args] = f.apply(0, arg); | ||
cache[args] = f(...arguments); | ||
@@ -105,3 +103,3 @@ return cache[args]; | ||
if (name == 'm' && params.length > 2) { | ||
data.push([b].concat(params.splice(0, 2))); | ||
data.push([ b, ...params.splice(0, 2) ]); | ||
name = 'l'; | ||
@@ -112,3 +110,3 @@ b = b == 'm' ? 'l' : 'L'; | ||
while (params.length >= paramCounts[name]) { | ||
data.push([b].concat(params.splice(0, paramCounts[name]))); | ||
data.push([ b, ...params.splice(0, paramCounts[name]) ]); | ||
if (!paramCounts[name]) { | ||
@@ -196,3 +194,3 @@ break; | ||
var bbox = curveBBox.apply(null, points); | ||
var bbox = curveBBox(...points); | ||
@@ -247,4 +245,4 @@ return rectBBox( | ||
n = 12, | ||
Tvalues = [-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816], | ||
Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472], | ||
Tvalues = [ -.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816 ], | ||
Cvalues = [ 0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472 ], | ||
sum = 0; | ||
@@ -319,4 +317,4 @@ | ||
var l1 = bezlen.apply(0, bez1), | ||
l2 = bezlen.apply(0, bez2), | ||
var l1 = bezlen(...bez1), | ||
l2 = bezlen(...bez2), | ||
n1 = isLine(bez1) ? 1 : ~~(l1 / 5) || 1, | ||
@@ -330,3 +328,3 @@ n2 = isLine(bez2) ? 1 : ~~(l2 / 5) || 1, | ||
for (var i = 0; i < n1 + 1; i++) { | ||
var p = findDotsAtSegment.apply(0, bez1.concat(i / n1)); | ||
var p = findDotsAtSegment(...bez1, i / n1); | ||
dots1.push({ x: p.x, y: p.y, t: i / n1 }); | ||
@@ -336,3 +334,3 @@ } | ||
for (i = 0; i < n2 + 1; i++) { | ||
p = findDotsAtSegment.apply(0, bez2.concat(i / n2)); | ||
p = findDotsAtSegment(...bez2, i / n2); | ||
dots2.push({ x: p.x, y: p.y, t: i / n2 }); | ||
@@ -416,3 +414,3 @@ } | ||
*/ | ||
function findPathIntersections(path1, path2, justCount) { | ||
export default function findPathIntersections(path1, path2, justCount) { | ||
path1 = pathToCurve(path1); | ||
@@ -433,7 +431,7 @@ path2 = pathToCurve(path2); | ||
if (pi[0] == 'C') { | ||
bez1 = [x1, y1].concat(pi.slice(1)); | ||
bez1 = [ x1, y1, ...pi.slice(1) ]; | ||
x1 = bez1[6]; | ||
y1 = bez1[7]; | ||
} else { | ||
bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m]; | ||
bez1 = [ x1, y1, x1, y1, x1m, y1m, x1m, y1m ]; | ||
x1 = x1m; | ||
@@ -452,7 +450,7 @@ y1 = y1m; | ||
if (pj[0] == 'C') { | ||
bez2 = [x2, y2].concat(pj.slice(1)); | ||
bez2 = [ x2, y2, ...pj.slice(1) ]; | ||
x2 = bez2[6]; | ||
y2 = bez2[7]; | ||
} else { | ||
bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m]; | ||
bez2 = [ x2, y2, x2, y2, x2m, y2m, x2m, y2m ]; | ||
x2 = x2m; | ||
@@ -498,3 +496,3 @@ y2 = y2m; | ||
if (!pathArray || !pathArray.length) { | ||
return [['M', 0, 0]]; | ||
return [ [ 'M', 0, 0 ] ]; | ||
} | ||
@@ -516,3 +514,3 @@ | ||
start++; | ||
res[0] = ['M', x, y]; | ||
res[0] = [ 'M', x, y ]; | ||
} | ||
@@ -686,3 +684,3 @@ | ||
y2 = cy + ry * math.sin(f2); | ||
res = arcToCurve(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]); | ||
res = arcToCurve(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [ f2, f2old, cx, cy ]); | ||
} | ||
@@ -699,6 +697,6 @@ | ||
hy = 4 / 3 * ry * t, | ||
m1 = [x1, y1], | ||
m2 = [x1 + hx * s1, y1 - hy * c1], | ||
m3 = [x2 + hx * s2, y2 - hy * c2], | ||
m4 = [x2, y2]; | ||
m1 = [ x1, y1 ], | ||
m2 = [ x1 + hx * s1, y1 - hy * c1 ], | ||
m3 = [ x2 + hx * s2, y2 - hy * c2 ], | ||
m4 = [ x2, y2 ]; | ||
@@ -709,5 +707,5 @@ m2[0] = 2 * m1[0] - m2[0]; | ||
if (recursive) { | ||
return [m2, m3, m4].concat(res); | ||
return [ m2, m3, m4 ].concat(res); | ||
} else { | ||
res = [m2, m3, m4].concat(res).join().split(','); | ||
res = [ m2, m3, m4 ].concat(res).join().split(','); | ||
var newres = []; | ||
@@ -729,3 +727,3 @@ | ||
var tvalues = [], | ||
bounds = [[], []], | ||
bounds = [ [], [] ], | ||
a, b, c, t, t1, t2, b2ac, sqrtb2ac; | ||
@@ -798,6 +796,6 @@ | ||
return { | ||
x0: mmin.apply(0, bounds[0]), | ||
y0: mmin.apply(0, bounds[1]), | ||
x1: mmax.apply(0, bounds[0]), | ||
y1: mmax.apply(0, bounds[1]) | ||
x0: mmin(...bounds[0]), | ||
y0: mmin(...bounds[1]), | ||
x1: mmax(...bounds[0]), | ||
y1: mmax(...bounds[1]) | ||
}; | ||
@@ -821,3 +819,3 @@ } | ||
if (!path) { | ||
return ['C', d.x, d.y, d.x, d.y, d.x, d.y]; | ||
return [ 'C', d.x, d.y, d.x, d.y, d.x, d.y ]; | ||
} | ||
@@ -833,3 +831,3 @@ | ||
case 'A': | ||
path = ['C'].concat(arcToCurve.apply(0, [d.x, d.y].concat(path.slice(1)))); | ||
path = [ 'C', ...arcToCurve(d.x, d.y, ...path.slice(1)) ]; | ||
break; | ||
@@ -853,3 +851,3 @@ case 'S': | ||
} | ||
path = ['C', nx, ny].concat(path.slice(1)); | ||
path = [ 'C', nx, ny, ...path.slice(1) ]; | ||
break; | ||
@@ -873,3 +871,3 @@ case 'T': | ||
} | ||
path = ['C'].concat(qubicToCurve(d.x, d.y, d.qx, d.qy, path[1], path[2])); | ||
path = [ 'C', ...qubicToCurve(d.x, d.y, d.qx, d.qy, path[1], path[2]) ]; | ||
break; | ||
@@ -879,15 +877,15 @@ case 'Q': | ||
d.qy = path[2]; | ||
path = ['C'].concat(qubicToCurve(d.x, d.y, path[1], path[2], path[3], path[4])); | ||
path = [ 'C', ...qubicToCurve(d.x, d.y, path[1], path[2], path[3], path[4]) ]; | ||
break; | ||
case 'L': | ||
path = ['C'].concat(lineToCurve(d.x, d.y, path[1], path[2])); | ||
path = [ 'C', ...lineToCurve(d.x, d.y, path[1], path[2]) ]; | ||
break; | ||
case 'H': | ||
path = ['C'].concat(lineToCurve(d.x, d.y, path[1], d.y)); | ||
path = [ 'C', ...lineToCurve(d.x, d.y, path[1], d.y) ]; | ||
break; | ||
case 'V': | ||
path = ['C'].concat(lineToCurve(d.x, d.y, d.x, path[1])); | ||
path = [ 'C', ...lineToCurve(d.x, d.y, d.x, path[1]) ]; | ||
break; | ||
case 'Z': | ||
path = ['C'].concat(lineToCurve(d.x, d.y, d.X, d.Y)); | ||
path = [ 'C', ...lineToCurve(d.x, d.y, d.X, d.Y) ]; | ||
break; | ||
@@ -907,3 +905,3 @@ } | ||
pathCommands[i] = 'A'; // if created multiple C:s, their original seg is saved | ||
pp.splice(i++, 0, ['C'].concat(pi.splice(0, 6))); | ||
pp.splice(i++, 0, [ 'C', ...pi.splice(0, 6) ]); | ||
} | ||
@@ -949,4 +947,2 @@ | ||
return curvedPath; | ||
} | ||
module.exports = findPathIntersections; | ||
} |
{ | ||
"name": "path-intersection", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "Computes the intersection between two SVG paths", | ||
"main": "intersect.js", | ||
"types": "intersect.d.ts", | ||
"type": "module", | ||
"scripts": { | ||
@@ -11,4 +12,7 @@ "all": "run-s lint test", | ||
"dev": "npm test -- --auto-watch --no-single-run", | ||
"test": "karma start" | ||
"test": "karma start karma.conf.cjs" | ||
}, | ||
"engines": { | ||
"node": ">= 14.20" | ||
}, | ||
"repository": { | ||
@@ -29,20 +33,24 @@ "type": "git", | ||
"devDependencies": { | ||
"chai": "^4.3.4", | ||
"domify": "^1.4.0", | ||
"eslint": "^7.22.0", | ||
"eslint-plugin-bpmn-io": "^0.12.0", | ||
"karma": "^6.2.0", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-firefox-launcher": "^2.1.0", | ||
"chai": "^4.3.10", | ||
"domify": "^2.0.0", | ||
"eslint": "^8.55.0", | ||
"eslint-plugin-bpmn-io": "^1.0.0", | ||
"karma": "^6.4.2", | ||
"karma-chrome-launcher": "^3.2.0", | ||
"karma-firefox-launcher": "^2.1.2", | ||
"karma-mocha": "^2.0.1", | ||
"karma-phantomjs-launcher": "^1.0.4", | ||
"karma-sinon-chai": "^2.0.2", | ||
"karma-webpack": "^5.0.0", | ||
"mocha": "^8.3.2", | ||
"mocha": "^10.2.0", | ||
"npm-run-all": "^4.1.2", | ||
"puppeteer": "^8.0.0", | ||
"sinon": "^9.2.4", | ||
"sinon-chai": "^3.5.0", | ||
"webpack": "^5.25.1" | ||
} | ||
"puppeteer": "^21.6.1", | ||
"sinon": "^17.0.1", | ||
"sinon-chai": "^3.7.0", | ||
"webpack": "^5.89.0" | ||
}, | ||
"files": [ | ||
"intersect.js", | ||
"intersect.d.ts", | ||
"NOTICE" | ||
] | ||
} |
@@ -18,8 +18,8 @@ # path-intersection | ||
```javascript | ||
var intersect = require('path-intersection'); | ||
import intersect from 'path-intersection'; | ||
var path0 = 'M30,100L270,20'; | ||
var path1 = 'M150,150m0,-18a18,18,0,1,1,0,36a18,18,0,1,1,0,-36z'; | ||
const path0 = 'M30,100L270,20'; | ||
const path1 = 'M150,150m0,-18a18,18,0,1,1,0,36a18,18,0,1,1,0,-36z'; | ||
var intersection = intersect(path0, path1); | ||
const intersection = intersect(path0, path1); | ||
// [ { x: ..., y: ..., segment1: ..., segment2: ... }, ... ] | ||
@@ -33,5 +33,7 @@ ``` | ||
Perform a full build of the library (lint + test) via | ||
``` | ||
# install dependencies | ||
npm install | ||
``` | ||
# build and test the library | ||
npm run all | ||
@@ -38,0 +40,0 @@ ``` |
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
16
49
Yes
28696
6
830