path-intersection
Advanced tools
Comparing version 1.1.1 to 2.0.0
@@ -9,2 +9,6 @@ # Changelog | ||
## 2.0.0 | ||
* `CHORE`: remove intersection logic for non-standardized path descriptors ([`d6f07947`](https://github.com/bpmn-io/path-intersection/commit/d6f079474baf091914ee261efd98a88c4bf1990d)) | ||
## 1.1.1 | ||
@@ -11,0 +15,0 @@ |
170
intersect.js
@@ -96,3 +96,3 @@ 'use strict'; | ||
var paramCounts = { a: 7, c: 6, o: 2, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, u: 3, z: 0 }, | ||
var paramCounts = { a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0 }, | ||
data = []; | ||
@@ -120,9 +120,3 @@ | ||
if (name == 'o' && params.length == 1) { | ||
data.push([b, params[0]]); | ||
} | ||
if (name == 'r') { | ||
data.push([b].concat(params)); | ||
} else while (params.length >= paramCounts[name]) { | ||
while (params.length >= paramCounts[name]) { | ||
data.push([b].concat(params.splice(0, paramCounts[name]))); | ||
@@ -535,35 +529,2 @@ if (!paramCounts[name]) { | ||
function ellipsePath(x, y, rx, ry, a) { | ||
if (a == null && ry == null) { | ||
ry = rx; | ||
} | ||
x = +x; | ||
y = +y; | ||
rx = +rx; | ||
ry = +ry; | ||
if (a != null) { | ||
var rad = Math.PI / 180, | ||
x1 = x + rx * Math.cos(-ry * rad), | ||
x2 = x + rx * Math.cos(-a * rad), | ||
y1 = y + rx * Math.sin(-ry * rad), | ||
y2 = y + rx * Math.sin(-a * rad), | ||
res = [['M', x1, y1], ['A', rx, rx, 0, +(a - ry > 180), 0, x2, y2]]; | ||
} else { | ||
res = [ | ||
['M', x, y], | ||
['m', 0, -ry], | ||
['a', rx, ry, 0, 1, 1, 0, 2 * ry], | ||
['a', rx, ry, 0, 1, 1, 0, -2 * ry], | ||
['z'] | ||
]; | ||
} | ||
res.toString = pathToString; | ||
return res; | ||
} | ||
function pathToAbsolute(pathArray) { | ||
@@ -601,7 +562,2 @@ var pth = paths(pathArray); | ||
var crz = pathArray.length == 3 && | ||
pathArray[0][0] == 'M' && | ||
pathArray[1][0].toUpperCase() == 'R' && | ||
pathArray[2][0].toUpperCase() == 'Z'; | ||
for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) { | ||
@@ -631,24 +587,2 @@ res.push(r = []); | ||
break; | ||
case 'R': | ||
var dots = [x, y].concat(pa.slice(1)); | ||
for (var j = 2, jj = dots.length; j < jj; j++) { | ||
dots[j] = +dots[j] + x; | ||
dots[++j] = +dots[j] + y; | ||
} | ||
res.pop(); | ||
res = res.concat(catmulRomToBezier(dots, crz)); | ||
break; | ||
case 'O': | ||
res.pop(); | ||
dots = ellipsePath(x, y, pa[1], pa[2]); | ||
dots.push(dots[0]); | ||
res = res.concat(dots); | ||
break; | ||
case 'U': | ||
res.pop(); | ||
res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3])); | ||
r = ['U'].concat(res[res.length - 1].slice(-2)); | ||
break; | ||
case 'M': | ||
@@ -658,23 +592,7 @@ mx = +pa[1] + x; | ||
default: | ||
for (j = 1, jj = pa.length; j < jj; j++) { | ||
for (var j = 1, jj = pa.length; j < jj; j++) { | ||
r[j] = +pa[j] + ((j % 2) ? x : y); | ||
} | ||
} | ||
} else if (pa0 == 'R') { | ||
dots = [x, y].concat(pa.slice(1)); | ||
res.pop(); | ||
res = res.concat(catmulRomToBezier(dots, crz)); | ||
r = ['R'].concat(pa.slice(-2)); | ||
} else if (pa0 == 'O') { | ||
res.pop(); | ||
dots = ellipsePath(x, y, pa[1], pa[2]); | ||
dots.push(dots[0]); | ||
res = res.concat(dots); | ||
} else if (pa0 == 'U') { | ||
res.pop(); | ||
res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3])); | ||
r = ['U'].concat(res[res.length - 1].slice(-2)); | ||
} else { | ||
for (var k = 0, kk = pa.length; k < kk; k++) { | ||
@@ -686,21 +604,19 @@ r[k] = pa[k]; | ||
if (pa0 != 'O') { | ||
switch (r[0]) { | ||
case 'Z': | ||
x = +mx; | ||
y = +my; | ||
break; | ||
case 'H': | ||
x = r[1]; | ||
break; | ||
case 'V': | ||
y = r[1]; | ||
break; | ||
case 'M': | ||
mx = r[r.length - 2]; | ||
my = r[r.length - 1]; | ||
default: | ||
x = r[r.length - 2]; | ||
y = r[r.length - 1]; | ||
} | ||
switch (r[0]) { | ||
case 'Z': | ||
x = +mx; | ||
y = +my; | ||
break; | ||
case 'H': | ||
x = r[1]; | ||
break; | ||
case 'V': | ||
y = r[1]; | ||
break; | ||
case 'M': | ||
mx = r[r.length - 2]; | ||
my = r[r.length - 1]; | ||
default: | ||
x = r[r.length - 2]; | ||
y = r[r.length - 1]; | ||
} | ||
@@ -841,48 +757,2 @@ } | ||
// http://schepers.cc/getting-to-the-point | ||
function catmulRomToBezier(crp, z) { | ||
var d = []; | ||
for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) { | ||
var p = [ | ||
{ x: +crp[i - 2], y: +crp[i - 1] }, | ||
{ x: +crp[i], y: +crp[i + 1] }, | ||
{ x: +crp[i + 2], y: +crp[i + 3] }, | ||
{ x: +crp[i + 4], y: +crp[i + 5] } | ||
]; | ||
if (z) { | ||
if (!i) { | ||
p[0] = { x: +crp[iLen - 2], y: +crp[iLen - 1] }; | ||
} else if (iLen - 4 == i) { | ||
p[3] = { x: +crp[0], y: +crp[1] }; | ||
} else if (iLen - 2 == i) { | ||
p[2] = { x: +crp[0], y: +crp[1] }; | ||
p[3] = { x: +crp[2], y: +crp[3] }; | ||
} | ||
} else { | ||
if (iLen - 4 == i) { | ||
p[3] = p[2]; | ||
} else if (!i) { | ||
p[0] = { x: +crp[i], y: +crp[i + 1] }; | ||
} | ||
} | ||
d.push(['C', | ||
(-p[0].x + 6 * p[1].x + p[2].x) / 6, | ||
(-p[0].y + 6 * p[1].y + p[2].y) / 6, | ||
(p[1].x + 6 * p[2].x - p[3].x) / 6, | ||
(p[1].y + 6*p[2].y - p[3].y) / 6, | ||
p[2].x, | ||
p[2].y | ||
]); | ||
} | ||
return d; | ||
} | ||
// Returns bounding box of cubic bezier curve. | ||
@@ -889,0 +759,0 @@ // Source: http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html |
{ | ||
"name": "path-intersection", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "Computes the intersection between two SVG paths", | ||
@@ -5,0 +5,0 @@ "main": "intersect.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
31884
7
904
1