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 #include "SkIntersections.h" | 7 #include "SkIntersections.h" |
8 #include "SkPathOpsLine.h" | 8 #include "SkPathOpsLine.h" |
9 | 9 |
10 /* Determine the intersection point of two lines. This assumes the lines are not
parallel, | 10 /* Determine the intersection point of two lines. This assumes the lines are not
parallel, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 bool aNotB[2] = {false, false}; | 166 bool aNotB[2] = {false, false}; |
167 bool bNotA[2] = {false, false}; | 167 bool bNotA[2] = {false, false}; |
168 int nearCount = 0; | 168 int nearCount = 0; |
169 for (int index = 0; index < 2; ++index) { | 169 for (int index = 0; index < 2; ++index) { |
170 aNearB[index] = t = b.nearPoint(a[index], &aNotB[index]); | 170 aNearB[index] = t = b.nearPoint(a[index], &aNotB[index]); |
171 nearCount += t >= 0; | 171 nearCount += t >= 0; |
172 bNearA[index] = t = a.nearPoint(b[index], &bNotA[index]); | 172 bNearA[index] = t = a.nearPoint(b[index], &bNotA[index]); |
173 nearCount += t >= 0; | 173 nearCount += t >= 0; |
174 } | 174 } |
175 if (nearCount > 0) { | 175 if (nearCount > 0) { |
176 for (int iA = 0; iA < 2; ++iA) { | 176 // Skip if each segment contributes to one end point. |
177 if (!aNotB[iA]) { | 177 if (nearCount != 2 || aNotB[0] == aNotB[1]) { |
178 continue; | 178 for (int iA = 0; iA < 2; ++iA) { |
| 179 if (!aNotB[iA]) { |
| 180 continue; |
| 181 } |
| 182 int nearer = aNearB[iA] > 0.5; |
| 183 if (!bNotA[nearer]) { |
| 184 continue; |
| 185 } |
| 186 SkASSERT(a[iA] != b[nearer]); |
| 187 SkASSERT(iA == (bNearA[nearer] > 0.5)); |
| 188 fNearlySame[iA] = true; |
| 189 insertNear(iA, nearer, a[iA], b[nearer]); |
| 190 aNearB[iA] = -1; |
| 191 bNearA[nearer] = -1; |
| 192 nearCount -= 2; |
179 } | 193 } |
180 int nearer = aNearB[iA] > 0.5; | |
181 if (!bNotA[nearer]) { | |
182 continue; | |
183 } | |
184 SkASSERT(a[iA] != b[nearer]); | |
185 SkASSERT(iA == (bNearA[nearer] > 0.5)); | |
186 fNearlySame[iA] = true; | |
187 insertNear(iA, nearer, a[iA], b[nearer]); | |
188 aNearB[iA] = -1; | |
189 bNearA[nearer] = -1; | |
190 nearCount -= 2; | |
191 } | 194 } |
192 if (nearCount > 0) { | 195 if (nearCount > 0) { |
193 for (int iA = 0; iA < 2; ++iA) { | 196 for (int iA = 0; iA < 2; ++iA) { |
194 if (aNearB[iA] >= 0) { | 197 if (aNearB[iA] >= 0) { |
195 insert(iA, aNearB[iA], a[iA]); | 198 insert(iA, aNearB[iA], a[iA]); |
196 } | 199 } |
197 } | 200 } |
198 for (int iB = 0; iB < 2; ++iB) { | 201 for (int iB = 0; iB < 2; ++iB) { |
199 if (bNearA[iB] >= 0) { | 202 if (bNearA[iB] >= 0) { |
200 insert(bNearA[iB], iB, b[iB]); | 203 insert(bNearA[iB], iB, b[iB]); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // 4 subs, 2 muls, 1 cmp | 392 // 4 subs, 2 muls, 1 cmp |
390 static bool ccw(const SkDPoint& A, const SkDPoint& B, const SkDPoint& C) { | 393 static bool ccw(const SkDPoint& A, const SkDPoint& B, const SkDPoint& C) { |
391 return (C.fY - A.fY) * (B.fX - A.fX) > (B.fY - A.fY) * (C.fX - A.fX); | 394 return (C.fY - A.fY) * (B.fX - A.fX) > (B.fY - A.fY) * (C.fX - A.fX); |
392 } | 395 } |
393 | 396 |
394 // 16 subs, 8 muls, 6 cmps | 397 // 16 subs, 8 muls, 6 cmps |
395 bool SkIntersections::Test(const SkDLine& a, const SkDLine& b) { | 398 bool SkIntersections::Test(const SkDLine& a, const SkDLine& b) { |
396 return ccw(a[0], b[0], b[1]) != ccw(a[1], b[0], b[1]) | 399 return ccw(a[0], b[0], b[1]) != ccw(a[1], b[0], b[1]) |
397 && ccw(a[0], a[1], b[0]) != ccw(a[0], a[1], b[1]); | 400 && ccw(a[0], a[1], b[0]) != ccw(a[0], a[1], b[1]); |
398 } | 401 } |
OLD | NEW |