path ops -- use standard SkTQSort
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 22 Apr 2013 19:55:19 +0000 (19:55 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 22 Apr 2013 19:55:19 +0000 (19:55 +0000)
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

src/pathops/SkDCubicIntersection.cpp
src/pathops/SkDCubicToQuads.cpp
src/pathops/SkDQuadIntersection.cpp
src/pathops/SkOpAngle.cpp
src/pathops/SkOpContour.cpp
src/pathops/SkPathOpsCommon.cpp
src/pathops/TSearch.h [deleted file]

index f9d8cd5..2f1804d 100644 (file)
@@ -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;
index b8a02c4..b950535 100644 (file)
@@ -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])) {
index 0344680..5abbbdc 100644 (file)
@@ -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];
     }
index f67dfd0..65af383 100644 (file)
@@ -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;
index 54eecfa..1aee405 100644 (file)
@@ -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;
 }
 
index f304764..f1ed169 100644 (file)
@@ -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 (file)
index 2550448..0000000
+++ /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