mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Mono-curves: No need to filter out curves with no length any more.
This commit is contained in:
parent
b1037f89f1
commit
8513144ae1
1 changed files with 28 additions and 32 deletions
|
@ -635,43 +635,39 @@ statics: /** @lends Curve */{
|
||||||
* only containing its values are returned.
|
* only containing its values are returned.
|
||||||
*/
|
*/
|
||||||
getMonoCurves: function(v, dir) {
|
getMonoCurves: function(v, dir) {
|
||||||
var curves = [];
|
var curves = [],
|
||||||
// #getLength() is a rather expensive operation, therefore we test two
|
|
||||||
// cheap preconditions first.
|
|
||||||
if (v[0] !== v[6] || v[1] === v[7] || Curve.getLength(v) !== 0) {
|
|
||||||
// Determine the ordinate index in the curve values array.
|
// Determine the ordinate index in the curve values array.
|
||||||
var io = dir ? 0 : 1,
|
io = dir ? 0 : 1,
|
||||||
o0 = v[io],
|
o0 = v[io],
|
||||||
o1 = v[io + 2],
|
o1 = v[io + 2],
|
||||||
o2 = v[io + 4],
|
o2 = v[io + 4],
|
||||||
o3 = v[io + 6];
|
o3 = v[io + 6];
|
||||||
if ((o0 >= o1) === (o1 >= o2) && (o1 >= o2) === (o2 >= o3)
|
if ((o0 >= o1) === (o1 >= o2) && (o1 >= o2) === (o2 >= o3)
|
||||||
|| Curve.isStraight(v)) {
|
|| Curve.isStraight(v)) {
|
||||||
// Straight curves and curves with all involved points ordered
|
// Straight curves and curves with all involved points ordered
|
||||||
// in coordinate direction are guaranteed to be monotone.
|
// in coordinate direction are guaranteed to be monotone.
|
||||||
|
curves.push(v);
|
||||||
|
} else {
|
||||||
|
var a = 3 * (o1 - o2) - o0 + o3,
|
||||||
|
b = 2 * (o0 + o2) - 4 * o1,
|
||||||
|
c = o1 - o0,
|
||||||
|
tMin = 4e-7,
|
||||||
|
tMax = 1 - tMin,
|
||||||
|
roots = [],
|
||||||
|
n = Numerical.solveQuadratic(a, b, c, roots, tMin, tMax);
|
||||||
|
if (n === 0) {
|
||||||
curves.push(v);
|
curves.push(v);
|
||||||
} else {
|
} else {
|
||||||
var a = 3 * (o1 - o2) - o0 + o3,
|
roots.sort();
|
||||||
b = 2 * (o0 + o2) - 4 * o1,
|
var t = roots[0],
|
||||||
c = o1 - o0,
|
parts = Curve.subdivide(v, t);
|
||||||
tMin = 4e-7,
|
curves.push(parts[0]);
|
||||||
tMax = 1 - tMin,
|
if (n > 1) {
|
||||||
roots = [],
|
t = (roots[1] - t) / (1 - t);
|
||||||
n = Numerical.solveQuadratic(a, b, c, roots, tMin, tMax);
|
parts = Curve.subdivide(parts[1], t);
|
||||||
if (n === 0) {
|
|
||||||
curves.push(v);
|
|
||||||
} else {
|
|
||||||
roots.sort();
|
|
||||||
var t = roots[0],
|
|
||||||
parts = Curve.subdivide(v, t);
|
|
||||||
curves.push(parts[0]);
|
curves.push(parts[0]);
|
||||||
if (n > 1) {
|
|
||||||
t = (roots[1] - t) / (1 - t);
|
|
||||||
parts = Curve.subdivide(parts[1], t);
|
|
||||||
curves.push(parts[0]);
|
|
||||||
}
|
|
||||||
curves.push(parts[1]);
|
|
||||||
}
|
}
|
||||||
|
curves.push(parts[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return curves;
|
return curves;
|
||||||
|
|
Loading…
Reference in a new issue