| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 /* Slopes match when denom goes to zero: | 69 /* Slopes match when denom goes to zero: |
| 70 axLen / ayLen == bxLen / byLen | 70 axLen / ayLen == bxLen / byLen |
| 71 (ayLen * byLen) * axLen / ayLen == (ayLen * byLen) * bxLen / byLen | 71 (ayLen * byLen) * axLen / ayLen == (ayLen * byLen) * bxLen / byLen |
| 72 byLen * axLen == ayLen * bxLen | 72 byLen * axLen == ayLen * bxLen |
| 73 byLen * axLen - ayLen * bxLen == 0 ( == denom ) | 73 byLen * axLen - ayLen * bxLen == 0 ( == denom ) |
| 74 */ | 74 */ |
| 75 double denom = bLen.fY * aLen.fX - aLen.fY * bLen.fX; | 75 double denom = bLen.fY * aLen.fX - aLen.fY * bLen.fX; |
| 76 SkDVector ab0 = a[0] - b[0]; | 76 SkDVector ab0 = a[0] - b[0]; |
| 77 double numerA = ab0.fY * bLen.fX - bLen.fY * ab0.fX; | 77 double numerA = ab0.fY * bLen.fX - bLen.fY * ab0.fX; |
| 78 double numerB = ab0.fY * aLen.fX - aLen.fY * ab0.fX; | 78 double numerB = ab0.fY * aLen.fX - aLen.fY * ab0.fX; |
| 79 #if 0 |
| 80 if (!between(0, numerA, denom) || !between(0, numerB, denom)) { |
| 81 fUsed = 0; |
| 82 return 0; |
| 83 } |
| 84 #endif |
| 79 numerA /= denom; | 85 numerA /= denom; |
| 80 numerB /= denom; | 86 numerB /= denom; |
| 81 int used; | 87 int used; |
| 82 if (!approximately_zero(denom)) { | 88 if (!approximately_zero(denom)) { |
| 83 fT[0][0] = numerA; | 89 fT[0][0] = numerA; |
| 84 fT[1][0] = numerB; | 90 fT[1][0] = numerB; |
| 85 used = 1; | 91 used = 1; |
| 86 } else { | 92 } else { |
| 87 /* See if the axis intercepts match: | 93 /* See if the axis intercepts match: |
| 88 ay - ax * ayLen / axLen == by - bx * ayLen / axLen | 94 ay - ax * ayLen / axLen == by - bx * ayLen / axLen |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 fT[0][0] = horizontal_intercept(line, y); | 197 fT[0][0] = horizontal_intercept(line, y); |
| 192 } else if (horizontalType == 2) { | 198 } else if (horizontalType == 2) { |
| 193 fT[0][0] = 0; | 199 fT[0][0] = 0; |
| 194 fT[0][1] = 1; | 200 fT[0][1] = 1; |
| 195 } | 201 } |
| 196 return fUsed = horizontalType; | 202 return fUsed = horizontalType; |
| 197 } | 203 } |
| 198 | 204 |
| 199 int SkIntersections::horizontal(const SkDLine& line, double left, double right, | 205 int SkIntersections::horizontal(const SkDLine& line, double left, double right, |
| 200 double y, bool flipped) { | 206 double y, bool flipped) { |
| 201 fMax = 2; | 207 fMax = 3; // clean up parallel at the end will limit the result to 2 at the
most |
| 202 // see if end points intersect the opposite line | 208 // see if end points intersect the opposite line |
| 203 double t; | 209 double t; |
| 204 const SkDPoint leftPt = { left, y }; | 210 const SkDPoint leftPt = { left, y }; |
| 205 if ((t = line.exactPoint(leftPt)) >= 0) { | 211 if ((t = line.exactPoint(leftPt)) >= 0) { |
| 206 insert(t, (double) flipped, leftPt); | 212 insert(t, (double) flipped, leftPt); |
| 207 } | 213 } |
| 208 if (left != right) { | 214 if (left != right) { |
| 209 const SkDPoint rightPt = { right, y }; | 215 const SkDPoint rightPt = { right, y }; |
| 210 if ((t = line.exactPoint(rightPt)) >= 0) { | 216 if ((t = line.exactPoint(rightPt)) >= 0) { |
| 211 insert(t, (double) !flipped, rightPt); | 217 insert(t, (double) !flipped, rightPt); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // 4 subs, 2 muls, 1 cmp | 351 // 4 subs, 2 muls, 1 cmp |
| 346 static bool ccw(const SkDPoint& A, const SkDPoint& B, const SkDPoint& C) { | 352 static bool ccw(const SkDPoint& A, const SkDPoint& B, const SkDPoint& C) { |
| 347 return (C.fY - A.fY) * (B.fX - A.fX) > (B.fY - A.fY) * (C.fX - A.fX); | 353 return (C.fY - A.fY) * (B.fX - A.fX) > (B.fY - A.fY) * (C.fX - A.fX); |
| 348 } | 354 } |
| 349 | 355 |
| 350 // 16 subs, 8 muls, 6 cmps | 356 // 16 subs, 8 muls, 6 cmps |
| 351 bool SkIntersections::Test(const SkDLine& a, const SkDLine& b) { | 357 bool SkIntersections::Test(const SkDLine& a, const SkDLine& b) { |
| 352 return ccw(a[0], b[0], b[1]) != ccw(a[1], b[0], b[1]) | 358 return ccw(a[0], b[0], b[1]) != ccw(a[1], b[0], b[1]) |
| 353 && ccw(a[0], a[1], b[0]) != ccw(a[0], a[1], b[1]); | 359 && ccw(a[0], a[1], b[0]) != ccw(a[0], a[1], b[1]); |
| 354 } | 360 } |
| OLD | NEW |