mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Reformat code of #895 a bit.
- Respect 80 chars line-width - Indent comments with current indentation level - Use punctuation in comments
This commit is contained in:
parent
18e00f6312
commit
d186c2d356
1 changed files with 20 additions and 17 deletions
|
@ -353,9 +353,9 @@ PathItem.inject(new function() {
|
||||||
// Retrieve and use it here (See _getMonoCurve()).
|
// Retrieve and use it here (See _getMonoCurve()).
|
||||||
var curve = curves[start],
|
var curve = curves[start],
|
||||||
last = curve.last,
|
last = curve.last,
|
||||||
// Get the values of to the end x coordinate and winding of
|
// Get the values of to the end x coordinate and winding of
|
||||||
// the last non-horizontal curve, which will be the previous
|
// the last non-horizontal curve, which will be the previous
|
||||||
// non-horizontal curve for the first curve of the loop.
|
// non-horizontal curve for the first curve of the loop.
|
||||||
prevWinding = last.winding,
|
prevWinding = last.winding,
|
||||||
prevXEnd = last.values[6];
|
prevXEnd = last.values[6];
|
||||||
end = start + curve.length;
|
end = start + curve.length;
|
||||||
|
@ -369,35 +369,38 @@ PathItem.inject(new function() {
|
||||||
// compare the endpoints of the curve to determine if the
|
// compare the endpoints of the curve to determine if the
|
||||||
// ray from query point along +-x direction will intersect
|
// ray from query point along +-x direction will intersect
|
||||||
// the monotone curve.
|
// the monotone curve.
|
||||||
// horizontal curves with winding == 0 will be completely
|
// Horizontal curves with winding == 0 will be completely
|
||||||
// ignored
|
// ignored.
|
||||||
if (winding && (py >= yStart && py <= yEnd
|
if (winding && (py >= yStart && py <= yEnd
|
||||||
|| py >= yEnd && py <= yStart)) {
|
|| py >= yEnd && py <= yStart)) {
|
||||||
// calculate the x value for the ray's intersection
|
// Calculate the x value for the ray's intersection.
|
||||||
var x;
|
var x;
|
||||||
if (py === yStart) {
|
if (py === yStart) {
|
||||||
x = values[0];
|
x = values[0];
|
||||||
} else if (py === yEnd) {
|
} else if (py === yEnd) {
|
||||||
x = values[6];
|
x = values[6];
|
||||||
} else if (Curve.solveCubic(values, 1, py, roots, 0, 1) === 1) {
|
} else if (Curve.solveCubic(values, 1, py, roots, 0, 1)
|
||||||
|
=== 1) {
|
||||||
x = Curve.getPoint(values, roots[0]).x;
|
x = Curve.getPoint(values, roots[0]).x;
|
||||||
}
|
}
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
// count the intersection of the ray with the monotonic curve if
|
// Count the intersection of the ray with the
|
||||||
// - the crossing is not at the start of the curve
|
// monotonic curve if:
|
||||||
// - or the windings are opposite (intersect at a vertical extremum)
|
// - the crossing is not at the start of the curve
|
||||||
// - or the start of the current curve and the end of the prev
|
// - or the windings are opposite (intersect at a
|
||||||
// curve are on opposite sides of px
|
// vertical extremum)
|
||||||
var isWindingChange = winding === -prevWinding,
|
// - or the start of the current curve and the end
|
||||||
countIntersection = py !== yStart || isWindingChange ||
|
// of the prev curve are on opposite sides of px
|
||||||
(x - px) * (prevXEnd - px) < 0;
|
var isWindingChange = winding === -prevWinding;
|
||||||
if (countIntersection) {
|
if (py !== yStart || isWindingChange ||
|
||||||
|
(x - px) * (prevXEnd - px) < 0) {
|
||||||
if (x < xBefore) {
|
if (x < xBefore) {
|
||||||
windLeft += winding;
|
windLeft += winding;
|
||||||
} else if (x > xAfter) {
|
} else if (x > xAfter) {
|
||||||
windRight += winding;
|
windRight += winding;
|
||||||
} else if (py === yStart && isWindingChange) {
|
} else if (py === yStart && isWindingChange) {
|
||||||
// intersection is at a vertical extremum
|
// The point is a vertical extremum of the
|
||||||
|
// path.
|
||||||
++windLeft;
|
++windLeft;
|
||||||
++windRight;
|
++windRight;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue