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

svg-intersections

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-intersections - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

13

lib/intersect.js

@@ -11,3 +11,3 @@ /**

*/
var Point2D = require('kld-affine').Point2D;

@@ -138,3 +138,3 @@ var Vector2D = require('kld-affine').Vector2D;

var intersectionFunctions = {
/**

@@ -596,5 +596,5 @@ intersectPathShape

d2 = m1.inverse().multiply(m2).getDecompositionTRSR();
m1_ = d2.R.inverse().multiply(d2.T.inverse());
m2_ = d2.S;
d2 = m1.inverse().multiply(m2).getDecomposition();
m1_ = d2.rotation.inverse().multiply(d2.translation.inverse());
m2_ = d2.scale;

@@ -705,4 +705,1 @@ rx2 = m2_.a;

module.exports = intersect;

@@ -58,3 +58,2 @@ var Point2D = require('kld-affine').Point2D;

var vcr1 = new Vector2D(1, 0);
var theta1 = radian(1.0, 0.0, xcr1, ycr1);

@@ -563,40 +562,12 @@

AbsoluteArcPath.prototype.getIntersectionParams = function() {
return new IntersectionParams("Ellipse", [this.getCenter(), this.rx, this.ry]);
return IntersectionParams.newArc(this.previous.getLastPoint(),
this.points[0],
this.rx,
this.ry,
this.angle,
this.arcFlag,
this.sweepFlag);
};
AbsoluteArcPath.prototype.getCenter = function() {
var startPoint = this.previous.getLastPoint();
var endPoint = this.points[0];
var rx = this.rx;
var ry = this.ry;
var angle = this.angle * Math.PI / 180;
var c = Math.cos(angle);
var s = Math.sin(angle);
var TOLERANCE = 1e-6;
var halfDiff = startPoint.subtract(endPoint).divide(2);
var x1p = halfDiff.x * c + halfDiff.y * s;
var y1p = halfDiff.x * -s + halfDiff.y * c;
var x1px1p = x1p * x1p;
var y1py1p = y1p * y1p;
var lambda = (x1px1p / (rx * rx)) + (y1py1p / (ry * ry));
if (lambda > 1) {
var factor = Math.sqrt(lambda);
rx *= factor;
ry *= factor;
}
var rxrx = rx * rx;
var ryry = ry * ry;
var rxy1 = rxrx * y1py1p;
var ryx1 = ryry * x1px1p;
var factor = (rxrx * ryry - rxy1 - ryx1) / (rxy1 + ryx1);
if (Math.abs(factor) < TOLERANCE) factor = 0;
var sq = Math.sqrt(factor);
if (this.arcFlag == this.sweepFlag) sq = -sq;
var mid = startPoint.add(endPoint).divide(2);
var cxp = sq * rx * y1p / ry;
var cyp = sq * -ry * x1p / rx;
return new Point2D(cxp * c - cyp * s + mid.x, cxp * s + cyp * c + mid.y);
};
function AbsoluteCurveto2(params, previous) {

@@ -612,3 +583,3 @@ if (arguments.length > 0) {

AbsoluteCurveto2.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier2", [this.previous.getLastPoint(), this.points[0], this.points[1]]);
return IntersectionParams.newBezier2(this.previous.getLastPoint(), this.points[0], this.points[1]);
};

@@ -631,3 +602,3 @@

AbsoluteCurveto3.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier3", [this.previous.getLastPoint(), this.points[0], this.points[1], this.points[2]]);
return IntersectionParams.newBezier3(this.previous.getLastPoint(), this.points[0], this.points[1], this.points[2]);
};

@@ -663,3 +634,3 @@

AbsoluteLineto.prototype.getIntersectionParams = function() {
return new IntersectionParams("Line", [this.previous.getLastPoint(), this.points[0]]);
return IntersectionParams.newLine(this.previous.getLastPoint(), this.points[0]);
};

@@ -701,3 +672,3 @@

AbsoluteSmoothCurveto2.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier2", [this.previous.getLastPoint(), this.getControlPoint(), this.points[0]]);
return IntersectionParams.newBezier2(this.previous.getLastPoint(), this.getControlPoint(), this.points[0]);
};

@@ -731,3 +702,3 @@

AbsoluteSmoothCurveto3.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier3", [this.previous.getLastPoint(), this.getFirstControlPoint(), this.points[0], this.points[1]]);
return IntersectionParams.newBezier3(this.previous.getLastPoint(), this.getFirstControlPoint(), this.points[0], this.points[1]);
};

@@ -779,3 +750,3 @@

RelativeClosePath.prototype.getIntersectionParams = function() {
return new IntersectionParams("Line", [this.previous.getLastPoint(), this.getLastPoint()]);
return IntersectionParams.newLine(this.previous.getLastPoint(), this.getLastPoint());
};

@@ -797,3 +768,3 @@

RelativeCurveto2.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier2", [this.previous.getLastPoint(), this.points[0], this.points[1]]);
return IntersectionParams.newBezier2(this.previous.getLastPoint(), this.points[0], this.points[1]);
};

@@ -815,3 +786,3 @@

RelativeCurveto3.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier3", [this.previous.getLastPoint(), this.points[0], this.points[1], this.points[2]]);
return IntersectionParams.newBezier3(this.previous.getLastPoint(), this.points[0], this.points[1], this.points[2]);
};

@@ -842,3 +813,3 @@

RelativeLineto.prototype.getIntersectionParams = function() {
return new IntersectionParams("Line", [this.previous.getLastPoint(), this.points[0]]);
return IntersectionParams.newLine(this.previous.getLastPoint(), this.points[0]);
};

@@ -881,3 +852,3 @@

RelativeSmoothCurveto2.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier2", [this.previous.getLastPoint(), this.getControlPoint(), this.points[0]]);
return IntersectionParams.newBezier2(this.previous.getLastPoint(), this.getControlPoint(), this.points[0]);
};

@@ -912,3 +883,3 @@

RelativeSmoothCurveto3.prototype.getIntersectionParams = function() {
return new IntersectionParams("Bezier3", [this.previous.getLastPoint(), this.getFirstControlPoint(), this.points[0], this.points[1]]);
return IntersectionParams.newBezier3(this.previous.getLastPoint(), this.getFirstControlPoint(), this.points[0], this.points[1]);
};

@@ -915,0 +886,0 @@

{
"name": "svg-intersections",
"version": "0.2.5",
"version": "0.3.0",
"description": "A library of intersection algorithms covering all SVG shape types",

@@ -35,4 +35,4 @@ "author": {

"dependencies": {
"kld-affine": "^0.1.0",
"kld-polynomial": "^0.1.0"
"kld-affine": "2.0.0",
"kld-polynomial": "0.1.1"
},

@@ -39,0 +39,0 @@ "devDependencies": {

@@ -44,5 +44,5 @@ var bezier = require('../lib/functions/bezier');

exports.testIntersectArcLine = function(beforeExit, assert) {
var arc = shape("path", {d: "M0 20 A 20 20, 0, 0, 0, 20 0"});
var line = shape("line", {x1: 0, y1:0, x2:20, y2:20});
exports.testIntersectSmallArcLine = function(beforeExit, assert) {
var arc = shape("path", {d: "M0 20 A 20 20, 0, 0, 0, 20 0"}); // Quarter circle around origin
var line = shape("line", {x1: 0, y1:0, x2:20, y2:20}); // Diagonal right-down
var result = intersect(arc, line);

@@ -54,1 +54,49 @@

}
exports.testNoIntersectSmallArcLine = function(beforeExit, assert) {
var arc = shape("path", {d: "M0 20 A 20 20, 0, 0, 0, 20 0"}); // Quarter circle around origin
var line = shape("line", {x1: 0, y1:0, x2:20, y2:-20}); // Diagonal right-up
var result = intersect(arc, line);
assert.equal(0, result.points.length);
}
exports.testIntersectLargeArcLine = function(beforeExit, assert) {
var arc = shape("path", {d: "M0 20 A 20 20, 0, 1, 0, 20 0"}); // Three-quarter circle around 20,20
var line = shape("line", {x1: 0, y1:0, x2:40, y2:40}); // Diagonal right-down
var result = intersect(arc, line);
assert.equal(1, result.points.length);
assert.equal(result.points[0].distanceFrom(new Point2D(20, 20)), 20);
assert.equal(result.points[0].x, result.points[0].y);
}
exports.testNoIntersectLargeArcLine = function(beforeExit, assert) {
var arc = shape("path", {d: "M0 20 A 20 20, 0, 1, 0, 20 0"}); // Three-quarter circle around 20,20
var line = shape("line", {x1: 0, y1:0, x2:20, y2:20}); // Diagonal right-down
var result = intersect(arc, line);
assert.equal(0, result.points.length);
}
exports.testIntersectCircleCircle = function(beforeExit, assert) {
var circle1 = shape("circle", {cx:0, cy:0, r:1});
var circle2 = shape("circle", {cx:1, cy:1, r:1});
var result = intersect(circle1, circle2);
assert.equal(2, result.points.length);
assert.equal(result.points[0].x, 1);
assert.equal(result.points[0].y, 0);
assert.equal(result.points[1].x, 0);
assert.equal(result.points[1].y, 1);
}
exports.testIntersectArcArc = function(beforeExit, assert) {
var arc1 = shape("path", {d: "M0 20 A 20 20, 0, 0, 0, 20 0"}); // Quarter circle around origin
var arc2 = shape("path", {d: "M0 0 A 20 20, 0, 0, 0, 20 20"}); // Quarter circle around 20,0
var result = intersect(arc1, arc2);
assert.equal(1, result.points.length);
assert.ok(Math.abs(result.points[0].x - 10) <= Number.EPSILON * 10);
assert.ok(Math.abs(result.points[0].y - 17) <= 1);
}
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