mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Some code clean-up in addCurveIntersections()
This commit is contained in:
parent
c8132584b9
commit
b3d45b6624
1 changed files with 11 additions and 12 deletions
|
@ -1448,12 +1448,10 @@ new function() { // Scope for intersection using bezier fat-line clipping
|
|||
factor = d1 * d2 > 0 ? 3 / 4 : 4 / 9,
|
||||
dMin = factor * Math.min(0, d1, d2),
|
||||
dMax = factor * Math.max(0, d1, d2),
|
||||
tMinNew, tMaxNew,
|
||||
tDiff;
|
||||
// Calculate non-parametric bezier curve D(ti, di(t)) - di(t) is the
|
||||
// distance of P from the baseline l of the fat-line, ti is equally
|
||||
// spaced in [0, 1]
|
||||
var dp0 = getSignedDistance(q0x, q0y, q3x, q3y, v1[0], v1[1]),
|
||||
// Calculate non-parametric bezier curve D(ti, di(t)) - di(t) is the
|
||||
// distance of P from the baseline l of the fat-line, ti is equally
|
||||
// spaced in [0, 1]
|
||||
dp0 = getSignedDistance(q0x, q0y, q3x, q3y, v1[0], v1[1]),
|
||||
dp1 = getSignedDistance(q0x, q0y, q3x, q3y, v1[2], v1[3]),
|
||||
dp2 = getSignedDistance(q0x, q0y, q3x, q3y, v1[4], v1[5]),
|
||||
dp3 = getSignedDistance(q0x, q0y, q3x, q3y, v1[6], v1[7]),
|
||||
|
@ -1461,7 +1459,8 @@ new function() { // Scope for intersection using bezier fat-line clipping
|
|||
hull = getConvexHull(dp0, dp1, dp2, dp3),
|
||||
top = hull[0],
|
||||
bottom = hull[1],
|
||||
tMinClip, tMaxClip;
|
||||
tMinClip,
|
||||
tMaxClip;
|
||||
// Clip the convex-hull with dMin and dMax, taking into account that
|
||||
// there will be no intersections if one of the tvalues are null.
|
||||
if ((tMinClip = clipConvexHull(top, bottom, dMin, dMax)) == null ||
|
||||
|
@ -1470,11 +1469,11 @@ new function() { // Scope for intersection using bezier fat-line clipping
|
|||
return;
|
||||
// Clip P with the fat-line for Q
|
||||
v1 = Curve.getPart(v1, tMinClip, tMaxClip);
|
||||
tDiff = tMaxClip - tMinClip;
|
||||
// tMin and tMax are within the range (0, 1). We need to project it to
|
||||
// the original parameter range for v2.
|
||||
tMinNew = tMax * tMinClip + tMin * (1 - tMinClip);
|
||||
tMaxNew = tMax * tMaxClip + tMin * (1 - tMaxClip);
|
||||
var tDiff = tMaxClip - tMinClip,
|
||||
// tMin and tMax are within the range (0, 1). We need to project it
|
||||
// to the original parameter range for v2.
|
||||
tMinNew = tMax * tMinClip + tMin * (1 - tMinClip),
|
||||
tMaxNew = tMax * tMaxClip + tMin * (1 - tMaxClip);
|
||||
// Check if we need to subdivide the curves
|
||||
if (oldTDiff > 0.5 && tDiff > 0.5) {
|
||||
// Subdivide the curve which has converged the least.
|
||||
|
|
Loading…
Reference in a new issue