Chromium Code Reviews| 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 "SkOpEdgeBuilder.h" | 7 #include "SkOpEdgeBuilder.h" |
| 8 #include "SkPathOpsCommon.h" | 8 #include "SkPathOpsCommon.h" |
| 9 #include "SkPathWriter.h" | 9 #include "SkPathWriter.h" |
| 10 #include "TSearch.h" | 10 #include "SkTSort.h" |
| 11 | 11 |
| 12 static int contourRangeCheckY(const SkTDArray<SkOpContour*>& contourList, SkOpSe gment** currentPtr, | 12 static int contourRangeCheckY(const SkTDArray<SkOpContour*>& contourList, SkOpSe gment** currentPtr, |
| 13 int* indexPtr, int* endIndexPtr, double* bestHit, SkScalar* bestDx, | 13 int* indexPtr, int* endIndexPtr, double* bestHit, SkScalar* bestDx, |
| 14 bool* tryAgain, double* midPtr, bool opp) { | 14 bool* tryAgain, double* midPtr, bool opp) { |
| 15 const int index = *indexPtr; | 15 const int index = *indexPtr; |
| 16 const int endIndex = *endIndexPtr; | 16 const int endIndex = *endIndexPtr; |
| 17 const double mid = *midPtr; | 17 const double mid = *midPtr; |
| 18 const SkOpSegment* current = *currentPtr; | 18 const SkOpSegment* current = *currentPtr; |
| 19 double tAtMid = current->tAtMid(index, endIndex, mid); | 19 double tAtMid = current->tAtMid(index, endIndex, mid); |
| 20 SkPoint basePt = current->xyAtT(tAtMid); | 20 SkPoint basePt = current->xyAtT(tAtMid); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 bool evenOdd, bool oppEvenOdd) { | 363 bool evenOdd, bool oppEvenOdd) { |
| 364 int count = contours.count(); | 364 int count = contours.count(); |
| 365 if (count == 0) { | 365 if (count == 0) { |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 for (int index = 0; index < count; ++index) { | 368 for (int index = 0; index < count; ++index) { |
| 369 SkOpContour& contour = contours[index]; | 369 SkOpContour& contour = contours[index]; |
| 370 contour.setOppXor(contour.operand() ? evenOdd : oppEvenOdd); | 370 contour.setOppXor(contour.operand() ? evenOdd : oppEvenOdd); |
| 371 *list.append() = &contour; | 371 *list.append() = &contour; |
| 372 } | 372 } |
| 373 QSort<SkOpContour>(list.begin(), list.end() - 1); | 373 SkTQSort<SkOpContour>(list.begin(), list.end() - 1); |
| 374 } | 374 } |
| 375 | 375 |
| 376 static bool approximatelyEqual(const SkPoint& a, const SkPoint& b) { | 376 static bool approximatelyEqual(const SkPoint& a, const SkPoint& b) { |
| 377 return AlmostEqualUlps(a.fX, b.fX) && AlmostEqualUlps(a.fY, b.fY); | 377 return AlmostEqualUlps(a.fX, b.fX) && AlmostEqualUlps(a.fY, b.fY); |
| 378 } | 378 } |
| 379 | 379 |
| 380 static bool lessThan(SkTDArray<double>& distances, const int one, const int two) { | 380 class DistanceLessThan { |
| 381 return distances[one] < distances[two]; | 381 public: |
| 382 } | 382 DistanceLessThan(double* distances) : fDistances(distances) { } |
| 383 double* fDistances; | |
|
bungeman-skia
2013/04/22 16:00:44
It probably makes no difference whatsoever, but fD
| |
| 384 bool operator()(const int one, const int two) { | |
|
bungeman-skia
2013/04/22 16:00:44
Again, somewhat silly, but this operator can be ma
| |
| 385 return fDistances[one] < fDistances[two]; | |
| 386 } | |
| 387 }; | |
| 388 | |
| 383 /* | 389 /* |
| 384 check start and end of each contour | 390 check start and end of each contour |
| 385 if not the same, record them | 391 if not the same, record them |
| 386 match them up | 392 match them up |
| 387 connect closest | 393 connect closest |
| 388 reassemble contour pieces into new path | 394 reassemble contour pieces into new path |
| 389 */ | 395 */ |
| 390 void Assemble(const SkPathWriter& path, SkPathWriter* simple) { | 396 void Assemble(const SkPathWriter& path, SkPathWriter* simple) { |
| 391 #if DEBUG_PATH_CONSTRUCTION | 397 #if DEBUG_PATH_CONSTRUCTION |
| 392 SkDebugf("%s\n", __FUNCTION__); | 398 SkDebugf("%s\n", __FUNCTION__); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 double dy = iPt.fY - oPt.fY; | 452 double dy = iPt.fY - oPt.fY; |
| 447 double dist = dx * dx + dy * dy; | 453 double dist = dx * dx + dy * dy; |
| 448 distances[row + iIndex] = dist; // oStart distance from iStart | 454 distances[row + iIndex] = dist; // oStart distance from iStart |
| 449 } | 455 } |
| 450 } | 456 } |
| 451 SkTDArray<int> sortedDist; | 457 SkTDArray<int> sortedDist; |
| 452 sortedDist.setCount(entries); | 458 sortedDist.setCount(entries); |
| 453 for (rIndex = 0; rIndex < entries; ++rIndex) { | 459 for (rIndex = 0; rIndex < entries; ++rIndex) { |
| 454 sortedDist[rIndex] = rIndex; | 460 sortedDist[rIndex] = rIndex; |
| 455 } | 461 } |
| 456 QSort<SkTDArray<double>, int>(distances, sortedDist.begin(), sortedDist.end( ) - 1, lessThan); | 462 SkTQSort<int>(sortedDist.begin(), sortedDist.end() - 1, DistanceLessThan(dis tances.begin())); |
| 457 int remaining = count; // number of start/end pairs | 463 int remaining = count; // number of start/end pairs |
| 458 for (rIndex = 0; rIndex < entries; ++rIndex) { | 464 for (rIndex = 0; rIndex < entries; ++rIndex) { |
| 459 int pair = sortedDist[rIndex]; | 465 int pair = sortedDist[rIndex]; |
| 460 int row = pair / ends; | 466 int row = pair / ends; |
| 461 int col = pair - row * ends; | 467 int col = pair - row * ends; |
| 462 int thingOne = row < col ? row : ends - row - 2; | 468 int thingOne = row < col ? row : ends - row - 2; |
| 463 int ndxOne = thingOne >> 1; | 469 int ndxOne = thingOne >> 1; |
| 464 bool endOne = thingOne & 1; | 470 bool endOne = thingOne & 1; |
| 465 int* linkOne = endOne ? eLink.begin() : sLink.begin(); | 471 int* linkOne = endOne ? eLink.begin() : sLink.begin(); |
| 466 if (linkOne[ndxOne] != SK_MaxS32) { | 472 if (linkOne[ndxOne] != SK_MaxS32) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 } | 574 } |
| 569 } | 575 } |
| 570 } while (rIndex < count); | 576 } while (rIndex < count); |
| 571 #if DEBUG_ASSEMBLE | 577 #if DEBUG_ASSEMBLE |
| 572 for (rIndex = 0; rIndex < count; ++rIndex) { | 578 for (rIndex = 0; rIndex < count; ++rIndex) { |
| 573 SkASSERT(sLink[rIndex] == SK_MaxS32); | 579 SkASSERT(sLink[rIndex] == SK_MaxS32); |
| 574 SkASSERT(eLink[rIndex] == SK_MaxS32); | 580 SkASSERT(eLink[rIndex] == SK_MaxS32); |
| 575 } | 581 } |
| 576 #endif | 582 #endif |
| 577 } | 583 } |
| OLD | NEW |