mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Use new range feature of solveCubic()
This commit is contained in:
parent
979428b6dc
commit
f20e8240cd
1 changed files with 13 additions and 15 deletions
|
@ -1450,24 +1450,22 @@ new function() { // Scope for methods that require numerical integration
|
||||||
y * cos + x * sin);
|
y * cos + x * sin);
|
||||||
}
|
}
|
||||||
var roots = [],
|
var roots = [],
|
||||||
count = Curve.solveCubic(vcr, 1, 0, roots);
|
count = Curve.solveCubic(vcr, 1, 0, roots, 0, 1);
|
||||||
// NOTE: count could be -1 for inifnite solutions, but that should only
|
// NOTE: count could be -1 for inifnite solutions, but that should only
|
||||||
// happen with lines, in which case we should not be here.
|
// happen with lines, in which case we should not be here.
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var t = roots[i];
|
var tc = roots[i],
|
||||||
if (t >= 0 && t <= 1) {
|
point = Curve.evaluate(vcr, tc, 0);
|
||||||
var point = Curve.evaluate(vcr, t, 0);
|
// We do have a point on the infinite line. Check if it falls on
|
||||||
// We do have a point on the infinite line. Check if it falls on
|
// the line *segment*.
|
||||||
// the line *segment*.
|
if (point.x >= 0 && point.x <= rl2x){
|
||||||
if (point.x >= 0 && point.x <= rl2x){
|
var tl = Curve.getParameterOf(vl, point.x, point.y);
|
||||||
var tl = Curve.getParameterOf(vl, point.x, point.y);
|
// Interpolate the parameter for the intersection on line.
|
||||||
// Interpolate the parameter for the intersection on line.
|
var t1 = flip ? tl : tc,
|
||||||
var t1 = flip ? tl : t,
|
t2 = flip ? tc : tl;
|
||||||
t2 = flip ? t : tl;
|
addLocation(locations,
|
||||||
addLocation(locations,
|
curve1, t1, Curve.evaluate(v1, t1, 0),
|
||||||
curve1, t1, Curve.evaluate(v1, t1, 0),
|
curve2, t2, Curve.evaluate(v2, t2, 0));
|
||||||
curve2, t2, Curve.evaluate(v2, t2, 0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue