| 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 "SkOpAngle.h" | 8 #include "SkOpAngle.h" |
| 9 #include "SkOpSegment.h" | 9 #include "SkOpSegment.h" |
| 10 #include "SkPathOpsCurve.h" | 10 #include "SkPathOpsCurve.h" |
| 11 #include "SkTSort.h" | 11 #include "SkTSort.h" |
| 12 | 12 |
| 13 #if DEBUG_ANGLE | 13 #if DEBUG_ANGLE |
| 14 #include "SkString.h" | 14 #include "SkString.h" |
| 15 | 15 |
| 16 static const char funcName[] = "SkOpSegment::operator<"; | 16 static const char funcName[] = "SkOpSegment::operator<"; |
| 17 static const int bugChar = strlen(funcName) + 1; | 17 static const int bugChar = strlen(funcName) + 1; |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 /* Angles are sorted counterclockwise. The smallest angle has a positive x and t
he smallest | 20 /* Angles are sorted counterclockwise. The smallest angle has a positive x and t
he smallest |
| 21 positive y. The largest angle has a positive x and a zero y. */ | 21 positive y. The largest angle has a positive x and a zero y. */ |
| 22 | 22 |
| 23 #if DEBUG_ANGLE | 23 #if DEBUG_ANGLE |
| 24 static bool CompareResult(SkString* bugOut, const char* append, bool compare
) { | 24 static bool CompareResult(SkString* bugOut, const char* append, bool compare
) { |
| 25 bugOut->appendf(append); | 25 bugOut->appendf("%s", append); |
| 26 bugOut->writable_str()[bugChar] = "><"[compare]; | 26 bugOut->writable_str()[bugChar] = "><"[compare]; |
| 27 SkDebugf("%s\n", bugOut->c_str()); | 27 SkDebugf("%s\n", bugOut->c_str()); |
| 28 return compare; | 28 return compare; |
| 29 } | 29 } |
| 30 | 30 |
| 31 #define COMPARE_RESULT(append, compare) CompareResult(&bugOut, append, compa
re) | 31 #define COMPARE_RESULT(append, compare) CompareResult(&bugOut, append, compa
re) |
| 32 #else | 32 #else |
| 33 #define COMPARE_RESULT(append, compare) compare | 33 #define COMPARE_RESULT(append, compare) compare |
| 34 #endif | 34 #endif |
| 35 | 35 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 bool sloppy1 = x_ry < rx_y; | 134 bool sloppy1 = x_ry < rx_y; |
| 135 bool sloppy2 = !sloppy1; | 135 bool sloppy2 = !sloppy1; |
| 136 if ((!fComputed || calcSlop(x, y, rx, ry, &sloppy1)) | 136 if ((!fComputed || calcSlop(x, y, rx, ry, &sloppy1)) |
| 137 && (!rh.fComputed || rh.calcSlop(rx, ry, x, y, &sloppy2)) | 137 && (!rh.fComputed || rh.calcSlop(rx, ry, x, y, &sloppy2)) |
| 138 && sloppy1 != sloppy2) { | 138 && sloppy1 != sloppy2) { |
| 139 return COMPARE_RESULT("8 CalcSlop(x, y ...", sloppy1); | 139 return COMPARE_RESULT("8 CalcSlop(x, y ...", sloppy1); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 if (fSide * rh.fSide == 0) { | 143 if (fSide * rh.fSide == 0) { |
| 144 SkASSERT(fSide + rh.fSide != 0); | 144 SkASSERT(fSide + rh.fSide != 0); // hitting this assert means coincidenc
e was undetected |
| 145 return COMPARE_RESULT("9 fSide * rh.fSide == 0 ...", fSide < rh.fSide); | 145 return COMPARE_RESULT("9 fSide * rh.fSide == 0 ...", fSide < rh.fSide); |
| 146 } | 146 } |
| 147 // at this point, the initial tangent line is nearly coincident | 147 // at this point, the initial tangent line is nearly coincident |
| 148 // see if edges curl away from each other | 148 // see if edges curl away from each other |
| 149 if (fSide * rh.fSide < 0 && (!approximately_zero(fSide) || !approximately_ze
ro(rh.fSide))) { | 149 if (fSide * rh.fSide < 0 && (!approximately_zero(fSide) || !approximately_ze
ro(rh.fSide))) { |
| 150 return COMPARE_RESULT("9b fSide * rh.fSide < 0 ...", fSide < rh.fSide); | 150 return COMPARE_RESULT("9b fSide * rh.fSide < 0 ...", fSide < rh.fSide); |
| 151 } | 151 } |
| 152 if (fUnsortable || rh.fUnsortable) { | 152 if (fUnsortable || rh.fUnsortable) { |
| 153 // even with no solution, return a stable sort | 153 // even with no solution, return a stable sort |
| 154 return COMPARE_RESULT("11 fUnsortable || rh.fUnsortable", this < &rh); | 154 return COMPARE_RESULT("11 fUnsortable || rh.fUnsortable", this < &rh); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 #if 1 | 421 #if 1 |
| 422 #if DEBUG_UNSORTABLE | 422 #if DEBUG_UNSORTABLE |
| 423 SkPoint iPt = fSegment->xyAtT(fStart); | 423 SkPoint iPt = fSegment->xyAtT(fStart); |
| 424 SkPoint ePt = fSegment->xyAtT(fEnd); | 424 SkPoint ePt = fSegment->xyAtT(fEnd); |
| 425 SkDebugf("%s all tiny unsortable [%d] (%1.9g,%1.9g) [%d] (%1.9g,%1.9g)\n", _
_FUNCTION__, | 425 SkDebugf("%s all tiny unsortable [%d] (%1.9g,%1.9g) [%d] (%1.9g,%1.9g)\n", _
_FUNCTION__, |
| 426 fStart, iPt.fX, iPt.fY, fEnd, ePt.fX, ePt.fY); | 426 fStart, iPt.fX, iPt.fY, fEnd, ePt.fX, ePt.fY); |
| 427 #endif | 427 #endif |
| 428 fUnsortable = true; | 428 fUnsortable = true; |
| 429 #endif | 429 #endif |
| 430 } | 430 } |
| OLD | NEW |