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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (min > y || max < y) { | 174 if (min > y || max < y) { |
175 return 0; | 175 return 0; |
176 } | 176 } |
177 if (AlmostEqualUlps(min, max) && max - min < fabs(line[0].fX - line[1].fX))
{ | 177 if (AlmostEqualUlps(min, max) && max - min < fabs(line[0].fX - line[1].fX))
{ |
178 return 2; | 178 return 2; |
179 } | 179 } |
180 return 1; | 180 return 1; |
181 } | 181 } |
182 | 182 |
183 static double horizontal_intercept(const SkDLine& line, double y) { | 183 static double horizontal_intercept(const SkDLine& line, double y) { |
184 return (y - line[0].fY) / (line[1].fY - line[0].fY); | 184 return SkPinT((y - line[0].fY) / (line[1].fY - line[0].fY)); |
185 } | 185 } |
186 | 186 |
187 int SkIntersections::horizontal(const SkDLine& line, double y) { | 187 int SkIntersections::horizontal(const SkDLine& line, double y) { |
188 fMax = 2; | 188 fMax = 2; |
189 int horizontalType = horizontal_coincident(line, y); | 189 int horizontalType = horizontal_coincident(line, y); |
190 if (horizontalType == 1) { | 190 if (horizontalType == 1) { |
191 fT[0][0] = horizontal_intercept(line, y); | 191 fT[0][0] = horizontal_intercept(line, y); |
192 } else if (horizontalType == 2) { | 192 } else if (horizontalType == 2) { |
193 fT[0][0] = 0; | 193 fT[0][0] = 0; |
194 fT[0][1] = 1; | 194 fT[0][1] = 1; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 if (!precisely_between(min, x, max)) { | 260 if (!precisely_between(min, x, max)) { |
261 return 0; | 261 return 0; |
262 } | 262 } |
263 if (AlmostEqualUlps(min, max)) { | 263 if (AlmostEqualUlps(min, max)) { |
264 return 2; | 264 return 2; |
265 } | 265 } |
266 return 1; | 266 return 1; |
267 } | 267 } |
268 | 268 |
269 static double vertical_intercept(const SkDLine& line, double x) { | 269 static double vertical_intercept(const SkDLine& line, double x) { |
270 return (x - line[0].fX) / (line[1].fX - line[0].fX); | 270 return SkPinT((x - line[0].fX) / (line[1].fX - line[0].fX)); |
271 } | 271 } |
272 | 272 |
273 int SkIntersections::vertical(const SkDLine& line, double x) { | 273 int SkIntersections::vertical(const SkDLine& line, double x) { |
274 fMax = 2; | 274 fMax = 2; |
275 int verticalType = vertical_coincident(line, x); | 275 int verticalType = vertical_coincident(line, x); |
276 if (verticalType == 1) { | 276 if (verticalType == 1) { |
277 fT[0][0] = vertical_intercept(line, x); | 277 fT[0][0] = vertical_intercept(line, x); |
278 } else if (verticalType == 2) { | 278 } else if (verticalType == 2) { |
279 fT[0][0] = 0; | 279 fT[0][0] = 0; |
280 fT[0][1] = 1; | 280 fT[0][1] = 1; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 // 4 subs, 2 muls, 1 cmp | 341 // 4 subs, 2 muls, 1 cmp |
342 static bool ccw(const SkDPoint& A, const SkDPoint& B, const SkDPoint& C) { | 342 static bool ccw(const SkDPoint& A, const SkDPoint& B, const SkDPoint& C) { |
343 return (C.fY - A.fY) * (B.fX - A.fX) > (B.fY - A.fY) * (C.fX - A.fX); | 343 return (C.fY - A.fY) * (B.fX - A.fX) > (B.fY - A.fY) * (C.fX - A.fX); |
344 } | 344 } |
345 | 345 |
346 // 16 subs, 8 muls, 6 cmps | 346 // 16 subs, 8 muls, 6 cmps |
347 bool SkIntersections::Test(const SkDLine& a, const SkDLine& b) { | 347 bool SkIntersections::Test(const SkDLine& a, const SkDLine& b) { |
348 return ccw(a[0], b[0], b[1]) != ccw(a[1], b[0], b[1]) | 348 return ccw(a[0], b[0], b[1]) != ccw(a[1], b[0], b[1]) |
349 && ccw(a[0], a[1], b[0]) != ccw(a[0], a[1], b[1]); | 349 && ccw(a[0], a[1], b[0]) != ccw(a[0], a[1], b[1]); |
350 } | 350 } |
OLD | NEW |