| 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 "SkOpAngle.h" | 7 #include "SkOpAngle.h" |
| 8 #include "SkOpSegment.h" | 8 #include "SkOpSegment.h" |
| 9 #include "SkPathOpsCurve.h" | 9 #include "SkPathOpsCurve.h" |
| 10 #include "SkTSort.h" | 10 #include "SkTSort.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return -1; | 215 return -1; |
| 216 } | 216 } |
| 217 | 217 |
| 218 bool SkOpAngle::checkCrossesZero() const { | 218 bool SkOpAngle::checkCrossesZero() const { |
| 219 int start = SkTMin(fSectorStart, fSectorEnd); | 219 int start = SkTMin(fSectorStart, fSectorEnd); |
| 220 int end = SkTMax(fSectorStart, fSectorEnd); | 220 int end = SkTMax(fSectorStart, fSectorEnd); |
| 221 bool crossesZero = end - start > 16; | 221 bool crossesZero = end - start > 16; |
| 222 return crossesZero; | 222 return crossesZero; |
| 223 } | 223 } |
| 224 | 224 |
| 225 // loop looking for a pair of angle parts that are too close to be sorted | |
| 226 /* This is called after other more simple intersection and angle sorting tests h
ave been exhausted. | |
| 227 This should be rarely called -- the test below is thorough and time consuming
. | |
| 228 This checks the distance between start points; the distance between | |
| 229 */ | |
| 230 void SkOpAngle::checkNearCoincidence() { | |
| 231 SkOpAngle* test = this; | |
| 232 do { | |
| 233 SkOpSegment* testSegment = test->segment(); | |
| 234 double testStartT = test->start()->t(); | |
| 235 SkDPoint testStartPt = testSegment->dPtAtT(testStartT); | |
| 236 double testEndT = test->end()->t(); | |
| 237 SkDPoint testEndPt = testSegment->dPtAtT(testEndT); | |
| 238 double testLenSq = testStartPt.distanceSquared(testEndPt); | |
| 239 if (0) { | |
| 240 SkDebugf("%s testLenSq=%1.9g id=%d\n", __FUNCTION__, testLenSq, test
Segment->debugID()); | |
| 241 } | |
| 242 double testMidT = (testStartT + testEndT) / 2; | |
| 243 SkOpAngle* next = test; | |
| 244 while ((next = next->fNext) != this) { | |
| 245 SkOpSegment* nextSegment = next->segment(); | |
| 246 double testMidDistSq = testSegment->distSq(testMidT, next); | |
| 247 double testEndDistSq = testSegment->distSq(testEndT, next); | |
| 248 double nextStartT = next->start()->t(); | |
| 249 SkDPoint nextStartPt = nextSegment->dPtAtT(nextStartT); | |
| 250 double distSq = testStartPt.distanceSquared(nextStartPt); | |
| 251 double nextEndT = next->end()->t(); | |
| 252 double nextMidT = (nextStartT + nextEndT) / 2; | |
| 253 double nextMidDistSq = nextSegment->distSq(nextMidT, test); | |
| 254 double nextEndDistSq = nextSegment->distSq(nextEndT, test); | |
| 255 if (0) { | |
| 256 SkDebugf("%s distSq=%1.9g testId=%d nextId=%d\n", __FUNCTION__,
distSq, | |
| 257 testSegment->debugID(), nextSegment->debugID()); | |
| 258 SkDebugf("%s testMidDistSq=%1.9g\n", __FUNCTION__, testMidDistSq
); | |
| 259 SkDebugf("%s testEndDistSq=%1.9g\n", __FUNCTION__, testEndDistSq
); | |
| 260 SkDebugf("%s nextMidDistSq=%1.9g\n", __FUNCTION__, nextMidDistSq
); | |
| 261 SkDebugf("%s nextEndDistSq=%1.9g\n", __FUNCTION__, nextEndDistSq
); | |
| 262 SkDPoint nextEndPt = nextSegment->dPtAtT(nextEndT); | |
| 263 double nextLenSq = nextStartPt.distanceSquared(nextEndPt); | |
| 264 SkDebugf("%s nextLenSq=%1.9g\n", __FUNCTION__, nextLenSq); | |
| 265 SkDebugf("\n"); | |
| 266 } | |
| 267 } | |
| 268 test = test->fNext; | |
| 269 } while (test->fNext != this); | |
| 270 } | |
| 271 | |
| 272 bool SkOpAngle::checkParallel(SkOpAngle* rh) { | 225 bool SkOpAngle::checkParallel(SkOpAngle* rh) { |
| 273 SkDVector scratch[2]; | 226 SkDVector scratch[2]; |
| 274 const SkDVector* sweep, * tweep; | 227 const SkDVector* sweep, * tweep; |
| 275 if (!this->fUnorderedSweep) { | 228 if (!this->fUnorderedSweep) { |
| 276 sweep = this->fSweep; | 229 sweep = this->fSweep; |
| 277 } else { | 230 } else { |
| 278 scratch[0] = this->fCurvePart[1] - this->fCurvePart[0]; | 231 scratch[0] = this->fCurvePart[1] - this->fCurvePart[0]; |
| 279 sweep = &scratch[0]; | 232 sweep = &scratch[0]; |
| 280 } | 233 } |
| 281 if (!rh->fUnorderedSweep) { | 234 if (!rh->fUnorderedSweep) { |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 return true; | 1044 return true; |
| 1092 } | 1045 } |
| 1093 SkASSERT(s0dt0 != 0); | 1046 SkASSERT(s0dt0 != 0); |
| 1094 double m = s0xt0 / s0dt0; | 1047 double m = s0xt0 / s0dt0; |
| 1095 double sDist = sweep[0].length() * m; | 1048 double sDist = sweep[0].length() * m; |
| 1096 double tDist = tweep[0].length() * m; | 1049 double tDist = tweep[0].length() * m; |
| 1097 bool useS = fabs(sDist) < fabs(tDist); | 1050 bool useS = fabs(sDist) < fabs(tDist); |
| 1098 double mFactor = fabs(useS ? this->distEndRatio(sDist) : rh->distEndRatio(tD
ist)); | 1051 double mFactor = fabs(useS ? this->distEndRatio(sDist) : rh->distEndRatio(tD
ist)); |
| 1099 return mFactor < 2400; // empirically found limit | 1052 return mFactor < 2400; // empirically found limit |
| 1100 } | 1053 } |
| OLD | NEW |