OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 | 7 |
8 #include "SkIntersections.h" | 8 #include "SkIntersections.h" |
9 | 9 |
10 int SkIntersections::closestTo(double rangeStart, double rangeEnd, const SkDPoin
t& testPt, | 10 int SkIntersections::closestTo(double rangeStart, double rangeEnd, const SkDPoin
t& testPt, |
11 double* closestDist) const { | 11 double* closestDist) const { |
12 int closest = -1; | 12 int closest = -1; |
13 *closestDist = SK_ScalarMax; | 13 *closestDist = SK_ScalarMax; |
14 for (int index = 0; index < fUsed; ++index) { | 14 for (int index = 0; index < fUsed; ++index) { |
15 if (!between(rangeStart, fT[0][index], rangeEnd)) { | 15 if (!between(rangeStart, fT[0][index], rangeEnd)) { |
16 continue; | 16 continue; |
17 } | 17 } |
18 const SkDPoint& iPt = fPt[index]; | 18 const SkDPoint& iPt = fPt[index]; |
19 double dist = testPt.distanceSquared(iPt); | 19 double dist = testPt.distanceSquared(iPt); |
20 if (*closestDist > dist) { | 20 if (*closestDist > dist) { |
21 *closestDist = dist; | 21 *closestDist = dist; |
22 closest = index; | 22 closest = index; |
23 } | 23 } |
24 } | 24 } |
25 return closest; | 25 return closest; |
26 } | 26 } |
27 | 27 |
28 // called only by test code | |
29 int SkIntersections::coincidentUsed() const { | |
30 if (!fIsCoincident[0]) { | |
31 SkASSERT(!fIsCoincident[1]); | |
32 return 0; | |
33 } | |
34 int count = 0; | |
35 SkDEBUGCODE(int count2 = 0;) | |
36 for (int index = 0; index < fUsed; ++index) { | |
37 if (fIsCoincident[0] & (1 << index)) { | |
38 ++count; | |
39 } | |
40 #ifdef SK_DEBUG | |
41 if (fIsCoincident[1] & (1 << index)) { | |
42 ++count2; | |
43 } | |
44 #endif | |
45 } | |
46 SkASSERT(count == count2); | |
47 return count; | |
48 } | |
49 | |
50 int (SkIntersections::* const CurveVertical[])(const SkPoint[], SkScalar, | |
51 SkScalar, SkScalar, SkScalar, boo
l) = { | |
52 NULL, | |
53 &SkIntersections::verticalLine, | |
54 &SkIntersections::verticalQuad, | |
55 &SkIntersections::verticalConic, | |
56 &SkIntersections::verticalCubic | |
57 }; | |
58 | |
59 void SkIntersections::flip() { | 28 void SkIntersections::flip() { |
60 for (int index = 0; index < fUsed; ++index) { | 29 for (int index = 0; index < fUsed; ++index) { |
61 fT[1][index] = 1 - fT[1][index]; | 30 fT[1][index] = 1 - fT[1][index]; |
62 } | 31 } |
63 } | 32 } |
64 | 33 |
65 int SkIntersections::insert(double one, double two, const SkDPoint& pt) { | 34 int SkIntersections::insert(double one, double two, const SkDPoint& pt) { |
66 if (fIsCoincident[0] == 3 && between(fT[0][0], one, fT[0][1])) { | 35 if (fIsCoincident[0] == 3 && between(fT[0][0], one, fT[0][1])) { |
67 // For now, don't allow a mix of coincident and non-coincident intersect
ions | 36 // For now, don't allow a mix of coincident and non-coincident intersect
ions |
68 return -1; | 37 return -1; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 136 } |
168 SkDVector best = fPt[result] - origin; | 137 SkDVector best = fPt[result] - origin; |
169 SkDVector test = fPt[index] - origin; | 138 SkDVector test = fPt[index] - origin; |
170 if (test.crossCheck(best) < 0) { | 139 if (test.crossCheck(best) < 0) { |
171 result = index; | 140 result = index; |
172 } | 141 } |
173 } | 142 } |
174 return result; | 143 return result; |
175 } | 144 } |
176 | 145 |
177 void SkIntersections::quickRemoveOne(int index, int replace) { | |
178 if (index < replace) { | |
179 fT[0][index] = fT[0][replace]; | |
180 } | |
181 } | |
182 | |
183 void SkIntersections::removeOne(int index) { | 146 void SkIntersections::removeOne(int index) { |
184 int remaining = --fUsed - index; | 147 int remaining = --fUsed - index; |
185 if (remaining <= 0) { | 148 if (remaining <= 0) { |
186 return; | 149 return; |
187 } | 150 } |
188 memmove(&fPt[index], &fPt[index + 1], sizeof(fPt[0]) * remaining); | 151 memmove(&fPt[index], &fPt[index + 1], sizeof(fPt[0]) * remaining); |
189 memmove(&fT[0][index], &fT[0][index + 1], sizeof(fT[0][0]) * remaining); | 152 memmove(&fT[0][index], &fT[0][index + 1], sizeof(fT[0][0]) * remaining); |
190 memmove(&fT[1][index], &fT[1][index + 1], sizeof(fT[1][0]) * remaining); | 153 memmove(&fT[1][index], &fT[1][index + 1], sizeof(fT[1][0]) * remaining); |
191 // SkASSERT(fIsCoincident[0] == 0); | 154 // SkASSERT(fIsCoincident[0] == 0); |
192 int coBit = fIsCoincident[0] & (1 << index); | 155 int coBit = fIsCoincident[0] & (1 << index); |
193 fIsCoincident[0] -= ((fIsCoincident[0] >> 1) & ~((1 << index) - 1)) + coBit; | 156 fIsCoincident[0] -= ((fIsCoincident[0] >> 1) & ~((1 << index) - 1)) + coBit; |
194 SkASSERT(!(coBit ^ (fIsCoincident[1] & (1 << index)))); | 157 SkASSERT(!(coBit ^ (fIsCoincident[1] & (1 << index)))); |
195 fIsCoincident[1] -= ((fIsCoincident[1] >> 1) & ~((1 << index) - 1)) + coBit; | 158 fIsCoincident[1] -= ((fIsCoincident[1] >> 1) & ~((1 << index) - 1)) + coBit; |
196 } | 159 } |
197 | |
198 int SkIntersections::verticalConic(const SkPoint a[3], SkScalar weight, | |
199 SkScalar top, SkScalar bottom, SkScalar x, bool flipped) { | |
200 SkDConic conic; | |
201 conic.set(a, weight); | |
202 return vertical(conic, top, bottom, x, flipped); | |
203 } | |
204 | |
205 int SkIntersections::verticalCubic(const SkPoint a[4], SkScalar weight, | |
206 SkScalar top, SkScalar bottom, SkScalar x, bool flipped) { | |
207 SkDCubic cubic; | |
208 cubic.set(a); | |
209 return vertical(cubic, top, bottom, x, flipped); | |
210 } | |
211 | |
212 int SkIntersections::verticalLine(const SkPoint a[2], SkScalar weight, | |
213 SkScalar top, SkScalar bottom, SkScalar x, bool flipped) { | |
214 SkDLine line; | |
215 line.set(a); | |
216 return vertical(line, top, bottom, x, flipped); | |
217 } | |
218 | |
219 int SkIntersections::verticalQuad(const SkPoint a[3], SkScalar weight, | |
220 SkScalar top, SkScalar bottom, SkScalar x, bool flipped) { | |
221 SkDQuad quad; | |
222 quad.set(a); | |
223 return vertical(quad, top, bottom, x, flipped); | |
224 } | |
OLD | NEW |