Skip to content

Commit dc3bd30

Browse files
committed
Rename some variables and clean up code a bit more.
1 parent de01ef1 commit dc3bd30

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

src/path/Curve.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,38 +1429,40 @@ new function() { // Scope for methods that require numerical integration
14291429
var flip = Curve.isLinear(v1),
14301430
vc = flip ? v2 : v1,
14311431
vl = flip ? v1 : v2,
1432-
l1x = vl[0], l1y = vl[1],
1433-
l2x = vl[6], l2y = vl[7],
1432+
lx1 = vl[0], ly1 = vl[1],
1433+
lx2 = vl[6], ly2 = vl[7],
14341434
// Rotate both curve and line around l1 so that line is on x axis
1435-
lvx = l2x - l1x,
1436-
lvy = l2y - l1y,
1435+
ldx = lx2 - lx1,
1436+
ldy = ly2 - ly1,
14371437
// Angle with x axis (1, 0)
1438-
angle = Math.atan2(-lvy, lvx),
1438+
angle = Math.atan2(-ldy, ldx),
14391439
sin = Math.sin(angle),
14401440
cos = Math.cos(angle),
1441-
// (rl1x, rl1y) = (0, 0)
1442-
rl2x = lvx * cos - lvy * sin,
1443-
vcr = [];
1444-
1441+
// (rlx1, rly1) = (0, 0)
1442+
rlx2 = ldx * cos - ldy * sin,
1443+
// The curve values for the rotated line
1444+
rvl = [0, 0, 0, 0, rlx2, 0, rlx2, 0],
1445+
// Now calculate the rotated curve
1446+
rvc = [];
14451447
for(var i = 0; i < 8; i += 2) {
1446-
var x = vc[i] - l1x,
1447-
y = vc[i + 1] - l1y;
1448-
vcr.push(
1448+
var x = vc[i] - lx1,
1449+
y = vc[i + 1] - ly1;
1450+
rvc.push(
14491451
x * cos - y * sin,
14501452
y * cos + x * sin);
14511453
}
14521454
var roots = [],
1453-
count = Curve.solveCubic(vcr, 1, 0, roots, 0, 1);
1455+
count = Curve.solveCubic(rvc, 1, 0, roots, 0, 1);
14541456
// NOTE: count could be -1 for inifnite solutions, but that should only
14551457
// happen with lines, in which case we should not be here.
14561458
for (var i = 0; i < count; i++) {
14571459
var tc = roots[i],
1458-
x = Curve.evaluate(vcr, tc, 0).x;
1460+
x = Curve.evaluate(rvc, tc, 0).x;
14591461
// We do have a point on the infinite line. Check if it falls on
14601462
// the line *segment*.
1461-
if (x >= 0 && x <= rl2x) {
1462-
var tl = Curve.getParameterOf([0, 0, 0, 0, rl2x, 0, rl2x, 0],
1463-
x, 0),
1463+
if (x >= 0 && x <= rlx2) {
1464+
// Find the parameter of the intersection on the rotated line
1465+
var tl = Curve.getParameterOf(rvl, x, 0),
14641466
t1 = flip ? tl : tc,
14651467
t2 = flip ? tc : tl;
14661468
addLocation(locations,

0 commit comments

Comments
 (0)