Skip to content

Commit

Permalink
- License: Fix warning about unrecognized SPX identifier in `package.…
Browse files Browse the repository at this point in the history
…json`: "BSD" -> "BSD-3-Clause"

- Linting: Add recommended ESLInt rules (to catch bugs); 1. Fix: reference to `Point` instead of `Point2D`; 2. Avoid globals (`roots`, `cmd`); 3. unnecessary semi-colons; 4. unused variables; 5. Avoid redeclarations; 6. Markup assignment within conditional with extra parentheses
- npm: Add `eslint` script
- Git: Ignore `package-lock.json`
  • Loading branch information
brettz9 committed Apr 28, 2019
1 parent 383b7ab commit 24fd7a0
Show file tree
Hide file tree
Showing 9 changed files with 1,016 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
18 changes: 18 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
}
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// expose module classes

exports.intersect = require('./lib/intersect');
exports.shape = require('./lib/IntersectionParams').newShape;
exports.shape = require('./lib/IntersectionParams').newShape;
9 changes: 4 additions & 5 deletions lib/IntersectionParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ IntersectionParams.newPath = function(d) {
break;
default:
throw new Error("Unsupported segment type: " + mode);
};
}
segments.push(segment);
index += param_length;
token = tokens[index];
Expand All @@ -519,7 +519,7 @@ IntersectionParams.newPath = function(d) {

function AbsolutePathSegment(command, params, previous) {
if (arguments.length > 0) this.init(command, params, previous);
};
}
AbsolutePathSegment.prototype.init = function(command, params, previous) {
this.command = command;
this.previous = previous;
Expand Down Expand Up @@ -807,12 +807,11 @@ RelativeLineto.prototype.constructor = RelativeLineto;
RelativeLineto.superclass = RelativePathSegment.prototype;

RelativeLineto.prototype.toString = function() {
var points = new Array();
var command = "";
var lastPoint;
var point;
var cmd;
if (this.previous) lastPoint = this.previous.getLastPoint();
else lastPoint = new Point(0, 0);
else lastPoint = new Point2D(0, 0);
point = this.points[0].subtract(lastPoint);
if (this.previous.constructor != this.constuctor)
if (this.previous.constructor != RelativeMoveto) cmd = this.command;
Expand Down
5 changes: 2 additions & 3 deletions lib/functions/bezier.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ module.exports.intersectBezier2Line = function(p1, p2, p3, a1, a2) {

// Transform cubic coefficients to line's coordinate system and find roots
// of cubic
roots = new Polynomial(
var roots = new Polynomial(
n.dot(c2),
n.dot(c1),
n.dot(c0) + cl
Expand Down Expand Up @@ -824,7 +824,7 @@ module.exports.intersectBezier3Line = function(p1, p2, p3, p4, a1, a2) {

// ?Rotate each cubic coefficient using line for new coordinate system?
// Find roots of rotated cubic
roots = new Polynomial(
var roots = new Polynomial(
n.dot(c3),
n.dot(c2),
n.dot(c1),
Expand Down Expand Up @@ -868,4 +868,3 @@ module.exports.intersectBezier3Line = function(p1, p2, p3, p4, a1, a2) {

return result;
};

18 changes: 11 additions & 7 deletions lib/intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function removePointsNotInArc(intersection, c, rx, ry, phi, th1, dth, m) {
}
intersection.points = np;
return intersection;
};
}

/**
points1 will be modified, points close (almost identical) to any point in points2 will be removed
Expand Down Expand Up @@ -360,7 +360,6 @@ var intersectionFunctions = {
}
}

var poly = yPoly;
var ZEROepsilon = yPoly.zeroErrorEstimate();
ZEROepsilon *= 100 * Math.SQRT2;
for (i = 0; i < pts.length - 1;) {
Expand Down Expand Up @@ -399,7 +398,7 @@ var intersectionFunctions = {

var a = dir.dot(mDir);
var b = dir.dot(mDiff);
var c = diff.dot(mDiff) - 1.0;
c = diff.dot(mDiff) - 1.0;
var d = b*b - a*c;

var ERRF = 1e-15;
Expand Down Expand Up @@ -541,10 +540,10 @@ function intersect(shape1, shape2, m1, m2) {

if (ip1 !== null && ip2 !== null) {
var method;
if (method = composedShapeMethods[ip1.type]) {
if ((method = composedShapeMethods[ip1.type])) {
result = method(ip1, ip2, m1, m2);
}
else if (method = composedShapeMethods[ip2.type]) {
else if ((method = composedShapeMethods[ip2.type])) {
result = method(ip2, ip1, m2, m1);
}
else {
Expand Down Expand Up @@ -575,10 +574,13 @@ function intersect(shape1, shape2, m1, m2) {
var itm;
var useCTM = (m1 instanceof Matrix2D && m2 instanceof Matrix2D);// && (!m1.isIdentity() || !m2.isIdentity()));
if (useCTM) {
var rx1, ry1, c1;
if (type1 === IPTYPE.ELLIPSE && type2 === IPTYPE.ELLIPSE) {
var m1_, m2_;
var d2;
var c1 = params1[0], rx1 = params1[1], ry1 = params1[2];
c1 = params1[0];
rx1 = params1[1];
ry1 = params1[2];
var c2 = params2[0], rx2 = params2[1], ry2 = params2[2];

m1 = m1.multiply(Matrix2D.IDENTITY.translate(c1.x, c1.y).scaleNonUniform(rx1 / SMF, ry1 / SMF));
Expand Down Expand Up @@ -639,7 +641,9 @@ function intersect(shape1, shape2, m1, m2) {
}

if (type1 === IPTYPE.ELLIPSE) {
var c1 = params1[0], rx1 = params1[1], ry1 = params1[2];
c1 = params1[0];
rx1 = params1[1];
ry1 = params1[2];

m1 = m1.multiply(Matrix2D.IDENTITY.translate(c1.x, c1.y).scaleNonUniform(rx1 / SMF, ry1 / SMF));
c1 = new Point2D(0, 0);
Expand Down
Loading

0 comments on commit 24fd7a0

Please sign in to comment.