mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Switch to new and improved Line.getSignedDistance() in fat-line clipping code as well.
This commit is contained in:
parent
920469426e
commit
1c758a415a
1 changed files with 2 additions and 11 deletions
|
@ -1073,6 +1073,7 @@ new function() { // Scope for methods that require numerical integration
|
|||
// Let P be the first curve and Q be the second
|
||||
var q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7],
|
||||
tolerance = /*#=*/Numerical.TOLERANCE,
|
||||
getSignedDistance = Line.getSignedDistance,
|
||||
// Calculate the fat-line L for Q is the baseline l and two
|
||||
// offsets which completely encloses the curve P.
|
||||
d1 = getSignedDistance(q0x, q0y, q3x, q3y, v2[2], v2[3]) || 0,
|
||||
|
@ -1185,17 +1186,6 @@ new function() { // Scope for methods that require numerical integration
|
|||
}
|
||||
|
||||
/*#*/ if (__options.fatlineClipping) {
|
||||
function getSignedDistance(l1x, l1y, l2x, l2y, x, y) {
|
||||
var vx = l2x - l1x,
|
||||
vy = l2y - l1y;
|
||||
if (Numerical.isZero(vx))
|
||||
return vy >= 0 ? l1x - x : x - l1x;
|
||||
var m = vy / vx, // slope
|
||||
b = l1y - m * l1x; // y offset
|
||||
// Distance to the linear equation
|
||||
return (y - (m * x) - b) / Math.sqrt(m * m + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the convex hull for the non-parametric bezier curve D(ti, di(t))
|
||||
* The ti is equally spaced across [0..1] — [0, 1/3, 2/3, 1] for
|
||||
|
@ -1216,6 +1206,7 @@ new function() { // Scope for methods that require numerical integration
|
|||
p2 = [ 2 / 3, dq2 ],
|
||||
p3 = [ 1, dq3 ],
|
||||
// Find signed distance of p1 and p2 from line [ p0, p3 ]
|
||||
getSignedDistance = Line.getSignedDistance,
|
||||
dist1 = getSignedDistance(0, dq0, 1, dq3, 1 / 3, dq1),
|
||||
dist2 = getSignedDistance(0, dq0, 1, dq3, 2 / 3, dq2),
|
||||
flip = false,
|
||||
|
|
Loading…
Reference in a new issue