mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Ony split potentially self-intersecting curves if there are actual canditates.
This commit is contained in:
parent
45040abc53
commit
9bcf369e6a
1 changed files with 22 additions and 20 deletions
|
@ -1809,28 +1809,30 @@ new function() { // Scope for intersection using bezier fat-line clipping
|
||||||
2 * (bx * bx + by * by) + ax * cx + ay * cy,
|
2 * (bx * bx + by * by) + ax * cx + ay * cy,
|
||||||
bx * cx + by * cy,
|
bx * cx + by * cy,
|
||||||
roots, 0, 1);
|
roots, 0, 1);
|
||||||
// Select extremum with highest curvature. This is always on
|
if (count > 0) {
|
||||||
// the loop in case of a self intersection.
|
// Select extremum with highest curvature. This is
|
||||||
for (var i = 0, maxCurvature = 0; i < count; i++) {
|
// always on the loop in case of a self intersection.
|
||||||
var curvature = Math.abs(
|
for (var i = 0, maxCurvature = 0; i < count; i++) {
|
||||||
c1.getCurvatureAt(roots[i], true));
|
var curvature = Math.abs(
|
||||||
if (curvature > maxCurvature) {
|
c1.getCurvatureAt(roots[i], true));
|
||||||
maxCurvature = curvature;
|
if (curvature > maxCurvature) {
|
||||||
tSplit = roots[i];
|
maxCurvature = curvature;
|
||||||
|
tSplit = roots[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Divide the curve in two and then apply the normal
|
||||||
|
// curve intersection code.
|
||||||
|
var parts = Curve.subdivide(v1, tSplit);
|
||||||
|
// After splitting, the end is always connected:
|
||||||
|
param.endConnected = true;
|
||||||
|
// Since the curve was split above, we need to adjust
|
||||||
|
// the parameters for both locations.
|
||||||
|
param.renormalize = function(t1, t2) {
|
||||||
|
return [t1 * tSplit, t2 * (1 - tSplit) + tSplit];
|
||||||
|
};
|
||||||
|
Curve.getIntersections(parts[0], parts[1], c1, c1,
|
||||||
|
locations, param);
|
||||||
}
|
}
|
||||||
// Divide the curve in two and then apply the normal curve
|
|
||||||
// intersection code.
|
|
||||||
var parts = Curve.subdivide(v1, tSplit);
|
|
||||||
// After splitting, the end is always connected:
|
|
||||||
param.endConnected = true;
|
|
||||||
// Since the curve was split above, we need to adjust the
|
|
||||||
// parameters for both locations.
|
|
||||||
param.renormalize = function(t1, t2) {
|
|
||||||
return [t1 * tSplit, t2 * (1 - tSplit) + tSplit];
|
|
||||||
};
|
|
||||||
Curve.getIntersections(parts[0], parts[1], c1, c1,
|
|
||||||
locations, param);
|
|
||||||
}
|
}
|
||||||
// We're done handling self-intersection, let's jump out.
|
// We're done handling self-intersection, let's jump out.
|
||||||
return locations;
|
return locations;
|
||||||
|
|
Loading…
Reference in a new issue