mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -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,
|
||||
bx * cx + by * cy,
|
||||
roots, 0, 1);
|
||||
// Select extremum with highest curvature. This is always on
|
||||
// the loop in case of a self intersection.
|
||||
for (var i = 0, maxCurvature = 0; i < count; i++) {
|
||||
var curvature = Math.abs(
|
||||
c1.getCurvatureAt(roots[i], true));
|
||||
if (curvature > maxCurvature) {
|
||||
maxCurvature = curvature;
|
||||
tSplit = roots[i];
|
||||
if (count > 0) {
|
||||
// Select extremum with highest curvature. This is
|
||||
// always on the loop in case of a self intersection.
|
||||
for (var i = 0, maxCurvature = 0; i < count; i++) {
|
||||
var curvature = Math.abs(
|
||||
c1.getCurvatureAt(roots[i], true));
|
||||
if (curvature > maxCurvature) {
|
||||
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.
|
||||
return locations;
|
||||
|
|
Loading…
Reference in a new issue