mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -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);
|
||||
}
|
||||
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
|
||||
// happen with lines, in which case we should not be here.
|
||||
for (var i = 0; i < count; i++) {
|
||||
var t = roots[i];
|
||||
if (t >= 0 && t <= 1) {
|
||||
var point = Curve.evaluate(vcr, t, 0);
|
||||
// We do have a point on the infinite line. Check if it falls on
|
||||
// the line *segment*.
|
||||
if (point.x >= 0 && point.x <= rl2x){
|
||||
var tl = Curve.getParameterOf(vl, point.x, point.y);
|
||||
// Interpolate the parameter for the intersection on line.
|
||||
var t1 = flip ? tl : t,
|
||||
t2 = flip ? t : tl;
|
||||
addLocation(locations,
|
||||
curve1, t1, Curve.evaluate(v1, t1, 0),
|
||||
curve2, t2, Curve.evaluate(v2, t2, 0));
|
||||
}
|
||||
var tc = roots[i],
|
||||
point = Curve.evaluate(vcr, tc, 0);
|
||||
// We do have a point on the infinite line. Check if it falls on
|
||||
// the line *segment*.
|
||||
if (point.x >= 0 && point.x <= rl2x){
|
||||
var tl = Curve.getParameterOf(vl, point.x, point.y);
|
||||
// Interpolate the parameter for the intersection on line.
|
||||
var t1 = flip ? tl : tc,
|
||||
t2 = flip ? tc : tl;
|
||||
addLocation(locations,
|
||||
curve1, t1, Curve.evaluate(v1, t1, 0),
|
||||
curve2, t2, Curve.evaluate(v2, t2, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue