OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "SkPathOpsBounds.h" | 7 #include "SkPathOpsBounds.h" |
8 #include "SkPathOpsRect.h" | 8 #include "SkPathOpsRect.h" |
9 #include "SkPathOpsCurve.h" | 9 #include "SkPathOpsCurve.h" |
10 | 10 |
11 // this cheats and assumes that the perpendicular to the point is the closest r
ay to the curve | 11 // this cheats and assumes that the perpendicular to the point is the closest r
ay to the curve |
12 // this case (where the line and the curve are nearly coincident) may be the on
ly case that counts | 12 // this case (where the line and the curve are nearly coincident) may be the on
ly case that counts |
13 double SkDCurve::nearPoint(SkPath::Verb verb, const SkDPoint& xy, const SkDPoint
& opp) const { | 13 double SkDCurve::nearPoint(SkPath::Verb verb, const SkDPoint& xy, const SkDPoint
& opp) const { |
14 int count = SkPathOpsVerbToPoints(verb); | 14 int count = SkPathOpsVerbToPoints(verb); |
15 double minX = fCubic.fPts[0].fX; | 15 double minX = fCubic.fPts[0].fX; |
16 double maxX = minX; | 16 double maxX = minX; |
17 for (int index = 0; index < count; ++index) { | 17 for (int index = 1; index <= count; ++index) { |
18 minX = SkTMin(minX, fCubic.fPts[index].fX); | 18 minX = SkTMin(minX, fCubic.fPts[index].fX); |
19 maxX = SkTMax(maxX, fCubic.fPts[index].fX); | 19 maxX = SkTMax(maxX, fCubic.fPts[index].fX); |
20 } | 20 } |
21 if (!AlmostBetweenUlps(minX, xy.fX, maxX)) { | 21 if (!AlmostBetweenUlps(minX, xy.fX, maxX)) { |
22 return -1; | 22 return -1; |
23 } | 23 } |
24 double minY = fCubic.fPts[0].fY; | 24 double minY = fCubic.fPts[0].fY; |
25 double maxY = minY; | 25 double maxY = minY; |
26 for (int index = 0; index < count; ++index) { | 26 for (int index = 1; index <= count; ++index) { |
27 minY = SkTMin(minY, fCubic.fPts[index].fY); | 27 minY = SkTMin(minY, fCubic.fPts[index].fY); |
28 maxY = SkTMax(maxY, fCubic.fPts[index].fY); | 28 maxY = SkTMax(maxY, fCubic.fPts[index].fY); |
29 } | 29 } |
30 if (!AlmostBetweenUlps(minY, xy.fY, maxY)) { | 30 if (!AlmostBetweenUlps(minY, xy.fY, maxY)) { |
31 return -1; | 31 return -1; |
32 } | 32 } |
33 SkIntersections i; | 33 SkIntersections i; |
34 SkDLine perp = {{ xy, { xy.fX + opp.fY - xy.fY, xy.fY + xy.fX - opp.fX }}}; | 34 SkDLine perp = {{ xy, { xy.fX + opp.fY - xy.fY, xy.fY + xy.fX - opp.fX }}}; |
35 (*CurveDIntersectRay[verb])(*this, perp, &i); | 35 (*CurveDIntersectRay[verb])(*this, perp, &i); |
36 int minIndex = -1; | 36 int minIndex = -1; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (s3x2 * s2x1 < 0) { | 136 if (s3x2 * s2x1 < 0) { |
137 SkASSERT(s2x1 * s1x3 > 0); | 137 SkASSERT(s2x1 * s1x3 > 0); |
138 fSweep[0] = fSweep[1]; | 138 fSweep[0] = fSweep[1]; |
139 fOrdered = false; | 139 fOrdered = false; |
140 } | 140 } |
141 fSweep[1] = thirdSweep; | 141 fSweep[1] = thirdSweep; |
142 } | 142 } |
143 setIsCurve: | 143 setIsCurve: |
144 fIsCurve = fSweep[0].crossCheck(fSweep[1]) != 0; | 144 fIsCurve = fSweep[0].crossCheck(fSweep[1]) != 0; |
145 } | 145 } |
OLD | NEW |