diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-22 19:55:19 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-22 19:55:19 +0000 |
commit | b76d3b677713693137936ff813b92c4be48af173 (patch) | |
tree | 5650fd2fd30fcc678aff98d03a47c9a2702e566a /src | |
parent | da2cd7b1880ac7c8836bcd74ec946bf28c0ee9fd (diff) |
path ops -- use standard SkTQSort
thanks to bungeman for the contextual sort
R=bungeman@google.com
Author: caryclark@google.com
Review URL: https://chromiumcodereview.appspot.com/14034014
git-svn-id: http://skia.googlecode.com/svn/trunk@8810 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/pathops/SkDCubicIntersection.cpp | 4 | ||||
-rw-r--r-- | src/pathops/SkDCubicToQuads.cpp | 4 | ||||
-rw-r--r-- | src/pathops/SkDQuadIntersection.cpp | 4 | ||||
-rw-r--r-- | src/pathops/SkOpAngle.cpp | 4 | ||||
-rw-r--r-- | src/pathops/SkOpContour.cpp | 4 | ||||
-rw-r--r-- | src/pathops/SkPathOpsCommon.cpp | 18 | ||||
-rw-r--r-- | src/pathops/TSearch.h | 101 |
7 files changed, 22 insertions, 117 deletions
diff --git a/src/pathops/SkDCubicIntersection.cpp b/src/pathops/SkDCubicIntersection.cpp index f9d8cd5535..2f1804d526 100644 --- a/src/pathops/SkDCubicIntersection.cpp +++ b/src/pathops/SkDCubicIntersection.cpp @@ -13,7 +13,7 @@ #include "SkPathOpsRect.h" #include "SkReduceOrder.h" #include "SkTDArray.h" -#include "TSearch.h" +#include "SkTSort.h" #if ONE_OFF_DEBUG static const double tLimits1[2][2] = {{0.36, 0.37}, {0.63, 0.64}}; @@ -342,7 +342,7 @@ static void intersectEnd(const SkDCubic& cubic1, bool start, const SkDCubic& cub if (tVals.count() == 0) { return; } - QSort<double>(tVals.begin(), tVals.end() - 1); + SkTQSort<double>(tVals.begin(), tVals.end() - 1); double tMin1 = start ? 0 : 1 - LINE_FRACTION; double tMax1 = start ? LINE_FRACTION : 1; int tIdx = 0; diff --git a/src/pathops/SkDCubicToQuads.cpp b/src/pathops/SkDCubicToQuads.cpp index b8a02c4294..b95053593b 100644 --- a/src/pathops/SkDCubicToQuads.cpp +++ b/src/pathops/SkDCubicToQuads.cpp @@ -50,7 +50,7 @@ http://www.caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html #include "SkPathOpsQuad.h" #include "SkReduceOrder.h" #include "SkTDArray.h" -#include "TSearch.h" +#include "SkTSort.h" #define USE_CUBIC_END_POINTS 1 @@ -129,7 +129,7 @@ void SkDCubic::toQuadraticTs(double precision, SkTDArray<double>* ts) const { inflections += findMaxCurvature(&inflectT[inflections]); SkASSERT(inflections <= 5); } - QSort<double>(inflectT, &inflectT[inflections - 1]); + SkTQSort<double>(inflectT, &inflectT[inflections - 1]); // OPTIMIZATION: is this filtering common enough that it needs to be pulled out into its // own subroutine? while (inflections && approximately_less_than_zero(inflectT[0])) { diff --git a/src/pathops/SkDQuadIntersection.cpp b/src/pathops/SkDQuadIntersection.cpp index 0344680b6d..5abbbdcd82 100644 --- a/src/pathops/SkDQuadIntersection.cpp +++ b/src/pathops/SkDQuadIntersection.cpp @@ -10,7 +10,7 @@ #include "SkPathOpsLine.h" #include "SkQuarticRoot.h" #include "SkTDArray.h" -#include "TSearch.h" +#include "SkTSort.h" /* given the implicit form 0 = Ax^2 + Bxy + Cy^2 + Dx + Ey + F * and given x = at^2 + bt + c (the parameterized form) @@ -169,7 +169,7 @@ static bool is_linear_inner(const SkDQuad& q1, double t1s, double t1e, const SkD if (tCount == 1) { tMin = tMax = tsFound[0]; } else if (tCount > 1) { - QSort<double>(tsFound.begin(), tsFound.end() - 1); + SkTQSort<double>(tsFound.begin(), tsFound.end() - 1); tMin = tsFound[0]; tMax = tsFound[tsFound.count() - 1]; } diff --git a/src/pathops/SkOpAngle.cpp b/src/pathops/SkOpAngle.cpp index f67dfd0f48..65af3830a6 100644 --- a/src/pathops/SkOpAngle.cpp +++ b/src/pathops/SkOpAngle.cpp @@ -7,7 +7,7 @@ #include "SkIntersections.h" #include "SkOpAngle.h" #include "SkPathOpsCurve.h" -#include "TSearch.h" +#include "SkTSort.h" // FIXME: this is bogus for quads and cubics // if the quads and cubics' line from end pt to ctrl pt are coincident, @@ -221,7 +221,7 @@ void SkOpAngle::setSpans() { } testTs[testCount++] = startT; testTs[testCount++] = endT; - QSort<double>(testTs, &testTs[testCount - 1]); + SkTQSort<double>(testTs, &testTs[testCount - 1]); double bestSide = 0; int testCases = (testCount << 1) - 1; index = 0; diff --git a/src/pathops/SkOpContour.cpp b/src/pathops/SkOpContour.cpp index 54eecfab51..1aee4055c2 100644 --- a/src/pathops/SkOpContour.cpp +++ b/src/pathops/SkOpContour.cpp @@ -7,7 +7,7 @@ #include "SkIntersections.h" #include "SkOpContour.h" #include "SkPathWriter.h" -#include "TSearch.h" +#include "SkTSort.h" void SkOpContour::addCoincident(int index, SkOpContour* other, int otherIndex, const SkIntersections& ts, bool swap) { @@ -159,7 +159,7 @@ void SkOpContour::sortSegments() { for (int test = 0; test < segmentCount; ++test) { *fSortedSegments.append() = &fSegments[test]; } - QSort<SkOpSegment>(fSortedSegments.begin(), fSortedSegments.end() - 1); + SkTQSort<SkOpSegment>(fSortedSegments.begin(), fSortedSegments.end() - 1); fFirstSorted = 0; } diff --git a/src/pathops/SkPathOpsCommon.cpp b/src/pathops/SkPathOpsCommon.cpp index f30476443a..f1ed1697de 100644 --- a/src/pathops/SkPathOpsCommon.cpp +++ b/src/pathops/SkPathOpsCommon.cpp @@ -7,7 +7,7 @@ #include "SkOpEdgeBuilder.h" #include "SkPathOpsCommon.h" #include "SkPathWriter.h" -#include "TSearch.h" +#include "SkTSort.h" static int contourRangeCheckY(const SkTDArray<SkOpContour*>& contourList, SkOpSegment** currentPtr, int* indexPtr, int* endIndexPtr, double* bestHit, SkScalar* bestDx, @@ -370,16 +370,22 @@ void MakeContourList(SkTArray<SkOpContour>& contours, SkTDArray<SkOpContour*>& l contour.setOppXor(contour.operand() ? evenOdd : oppEvenOdd); *list.append() = &contour; } - QSort<SkOpContour>(list.begin(), list.end() - 1); + SkTQSort<SkOpContour>(list.begin(), list.end() - 1); } static bool approximatelyEqual(const SkPoint& a, const SkPoint& b) { return AlmostEqualUlps(a.fX, b.fX) && AlmostEqualUlps(a.fY, b.fY); } -static bool lessThan(SkTDArray<double>& distances, const int one, const int two) { - return distances[one] < distances[two]; -} +class DistanceLessThan { +public: + DistanceLessThan(double* distances) : fDistances(distances) { } + double* fDistances; + bool operator()(const int one, const int two) { + return fDistances[one] < fDistances[two]; + } +}; + /* check start and end of each contour if not the same, record them @@ -453,7 +459,7 @@ void Assemble(const SkPathWriter& path, SkPathWriter* simple) { for (rIndex = 0; rIndex < entries; ++rIndex) { sortedDist[rIndex] = rIndex; } - QSort<SkTDArray<double>, int>(distances, sortedDist.begin(), sortedDist.end() - 1, lessThan); + SkTQSort<int>(sortedDist.begin(), sortedDist.end() - 1, DistanceLessThan(distances.begin())); int remaining = count; // number of start/end pairs for (rIndex = 0; rIndex < entries; ++rIndex) { int pair = sortedDist[rIndex]; diff --git a/src/pathops/TSearch.h b/src/pathops/TSearch.h deleted file mode 100644 index 2550448c9c..0000000000 --- a/src/pathops/TSearch.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#ifndef TSearch_DEFINED -#define TSearch_DEFINED - -// FIXME: Move this templated version into SKTSearch.h - -template <typename T> -static T* QSort_Partition(T* left, T* right, T* pivot) -{ - T pivotValue = *pivot; - SkTSwap(*pivot, *right); - T* newPivot = left; - while (left < right) { - if (*left < pivotValue) { - SkTSwap(*left, *newPivot); - newPivot += 1; - } - left += 1; - } - SkTSwap(*newPivot, *right); - return newPivot; -} - -template <typename T> -void QSort(T* left, T* right) -{ - if (left >= right) { - return; - } - T* pivot = left + ((right - left) >> 1); - pivot = QSort_Partition(left, right, pivot); - QSort(left, pivot - 1); - QSort(pivot + 1, right); -} - -template <typename T> -static T** QSort_Partition(T** left, T** right, T** pivot) -{ - T* pivotValue = *pivot; - SkTSwap(*pivot, *right); - T** newPivot = left; - while (left < right) { - if (**left < *pivotValue) { - SkTSwap(*left, *newPivot); - newPivot += 1; - } - left += 1; - } - SkTSwap(*newPivot, *right); - return newPivot; -} - -template <typename T> -void QSort(T** left, T** right) -{ - if (left >= right) { - return; - } - T** pivot = left + ((right - left) >> 1); - pivot = QSort_Partition(left, right, pivot); - QSort(left, pivot - 1); - QSort(pivot + 1, right); -} - -template <typename S, typename T> -static T* QSort_Partition(S& context, T* left, T* right, T* pivot, - bool (*lessThan)(S&, const T, const T)) -{ - T pivotValue = *pivot; - SkTSwap(*pivot, *right); - T* newPivot = left; - while (left < right) { - if (lessThan(context, *left, pivotValue)) { - SkTSwap(*left, *newPivot); - newPivot += 1; - } - left += 1; - } - SkTSwap(*newPivot, *right); - return newPivot; -} - -template <typename S, typename T> -void QSort(S& context, T* left, T* right, - bool (*lessThan)(S& , const T, const T)) -{ - if (left >= right) { - return; - } - T* pivot = left + ((right - left) >> 1); - pivot = QSort_Partition(context, left, right, pivot, lessThan); - QSort(context, left, pivot - 1, lessThan); - QSort(context, pivot + 1, right, lessThan); -} - -#endif |