path-intersection
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -34,6 +34,6 @@ 'use strict'; | ||
return (type == 'null' && o === null) || | ||
(type == typeof o && o !== null) || | ||
(type == 'object' && o === Object(o)) || | ||
Object.prototype.toString.call(o).slice(8, -1).toLowerCase() == type; | ||
return (type == 'null' && o === null) || | ||
(type == typeof o && o !== null) || | ||
(type == 'object' && o === Object(o)) || | ||
Object.prototype.toString.call(o).slice(8, -1).toLowerCase() == type; | ||
} | ||
@@ -415,2 +415,32 @@ | ||
/** | ||
* Find or counts the intersections between two SVG paths. | ||
* | ||
* Returns a number in counting mode and a list of intersections otherwise. | ||
* | ||
* A single intersection entry contains the intersection coordinates (x, y) | ||
* as well as additional information regarding the intersecting segments | ||
* on each path (segment1, segment2) and the relative location of the | ||
* intersection on these segments (t1, t2). | ||
* | ||
* The path may be an SVG path string or a list of path components | ||
* such as `[ [ 'M', 0, 10 ], [ 'L', 20, 0 ] ]`. | ||
* | ||
* @example | ||
* | ||
* var intersections = findPathIntersections( | ||
* 'M0,0L100,100', | ||
* [ [ 'M', 0, 100 ], [ 'L', 100, 0 ] ] | ||
* ); | ||
* | ||
* // intersections = [ | ||
* // { x: 50, y: 50, segment1: 1, segment2: 1, t1: 0.5, t2: 0.5 } | ||
* // | ||
* | ||
* @param {String|Array<PathDef>} path1 | ||
* @param {String|Array<PathDef>} path2 | ||
* @param {Boolean} [justCount=false] | ||
* | ||
* @return {Array<Intersection>|Number} | ||
*/ | ||
function findPathIntersections(path1, path2, justCount) { | ||
@@ -813,3 +843,3 @@ path1 = pathToCurve(path1); | ||
{ x: +crp[i - 2], y: +crp[i - 1] }, | ||
{ x: +crp[i], y: +crp[i + 1] }, | ||
{ x: +crp[i], y: +crp[i + 1] }, | ||
{ x: +crp[i + 2], y: +crp[i + 3] }, | ||
@@ -961,7 +991,11 @@ { x: +crp[i + 4], y: +crp[i + 5] } | ||
case 'S': | ||
if (pcom == 'C' || pcom == 'S') { // In 'S' case we have to take into account, if the previous command is C/S. | ||
nx = d.x * 2 - d.bx; // And reflect the previous | ||
ny = d.y * 2 - d.by; // command's control point relative to the current point. | ||
if (pcom == 'C' || pcom == 'S') { | ||
// In 'S' case we have to take into account, if the previous command is C/S. | ||
nx = d.x * 2 - d.bx; | ||
// And reflect the previous | ||
ny = d.y * 2 - d.by; | ||
// command's control point relative to the current point. | ||
} | ||
else { // or some else or nothing | ||
else { | ||
// or some else or nothing | ||
nx = d.x; | ||
@@ -973,7 +1007,11 @@ ny = d.y; | ||
case 'T': | ||
if (pcom == 'Q' || pcom == 'T') { // In 'T' case we have to take into account, if the previous command is Q/T. | ||
d.qx = d.x * 2 - d.qx; // And make a reflection similar | ||
d.qy = d.y * 2 - d.qy; // to case 'S'. | ||
if (pcom == 'Q' || pcom == 'T') { | ||
// In 'T' case we have to take into account, if the previous command is Q/T. | ||
d.qx = d.x * 2 - d.qx; | ||
// And make a reflection similar | ||
d.qy = d.y * 2 - d.qy; | ||
// to case 'S'. | ||
} | ||
else { // or something else or nothing | ||
else { | ||
// or something else or nothing | ||
d.qx = d.x; | ||
@@ -1046,3 +1084,3 @@ d.qy = d.y; | ||
pcoms1[i] = pfirst; // Save current path command | ||
i && ( pcom = pcoms1[i - 1]); // Get previous path command pcom | ||
i && (pcom = pcoms1[i - 1]); // Get previous path command pcom | ||
} | ||
@@ -1049,0 +1087,0 @@ p[i] = processPath(p[i], attrs, pcom); // Previous path command is inputted to processPath |
{ | ||
"name": "path-intersection", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Computes the intersection between two SVG paths", | ||
"main": "intersect.js", | ||
"types": "intersect.d.ts", | ||
"scripts": { | ||
@@ -27,9 +28,9 @@ "all": "run-s lint test", | ||
"devDependencies": { | ||
"browserify": "^14.5.0", | ||
"browserify": "^16.2.0", | ||
"chai": "^4.1.2", | ||
"domify": "^1.4.0", | ||
"eslint": "^4.13.1", | ||
"eslint-plugin-mocha": "^4.11.0", | ||
"eslint": "^4.19.1", | ||
"eslint-plugin-bpmn-io": "^0.5.2", | ||
"karma": "^1.7.1", | ||
"karma-browserify": "^5.1.2", | ||
"karma-browserify": "^5.2.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
@@ -39,11 +40,11 @@ "karma-firefox-launcher": "^1.1.0", | ||
"karma-phantomjs-launcher": "^1.0.4", | ||
"karma-sinon-chai": "^1.3.3", | ||
"karma-sinon-chai": "^1.3.4", | ||
"karma-spec-reporter": "0.0.31", | ||
"mocha": "^4.0.1", | ||
"mocha": "^5.1.1", | ||
"npm-run-all": "^4.1.2", | ||
"puppeteer": "^0.13.0", | ||
"sinon": "^4.1.3", | ||
"sinon-chai": "^2.14.0", | ||
"watchify": "^3.9.0" | ||
"puppeteer": "^1.3.0", | ||
"sinon": "^4.5.0", | ||
"sinon-chai": "^3.0.0", | ||
"watchify": "^3.11.0" | ||
} | ||
} |
@@ -27,3 +27,5 @@ # path-intersection | ||
Results are approximate, as we use [bezier clipping](https://math.stackexchange.com/questions/118937) to find intersections. | ||
## Building the Project | ||
@@ -45,2 +47,2 @@ | ||
Use under the terms of the [MIT license](http://opensource.org/licenses/MIT). | ||
Use under the terms of the [MIT license](http://opensource.org/licenses/MIT). |
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
63217
8
1012
47