Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7580333 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Use std::sort instead of quickSortX" into mnc-dev

parents e4ed4708 1e4209e3
Loading
Loading
Loading
Loading
+5 −30
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@
#define TRANSFORMED_PENUMBRA_ALPHA 1.0f
#define TRANSFORMED_UMBRA_ALPHA 0.0f

#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <utils/Log.h>
@@ -145,7 +146,10 @@ static float rayIntersectPoints(const Vector2& rayOrigin, float dx, float dy,
 * @param pointsLength the number of vertices of the polygon.
 */
void SpotShadow::xsort(Vector2* points, int pointsLength) {
    quicksortX(points, 0, pointsLength - 1);
    auto cmp = [](const Vector2& a, const Vector2& b) -> bool {
        return a.x < b.x;
    };
    std::sort(points, points + pointsLength, cmp);
}

/**
@@ -272,35 +276,6 @@ void SpotShadow::quicksortCirc(Vector2* points, int low, int high,
    if (i < high) quicksortCirc(points, i, high, center);
}

/**
 * Sort points by x axis
 *
 * @param points points to sort
 * @param low start index
 * @param high end index
 */
void SpotShadow::quicksortX(Vector2* points, int low, int high) {
    int i = low, j = high;
    int p = low + (high - low) / 2;
    float pivot = points[p].x;
    while (i <= j) {
        while (points[i].x < pivot) {
            i++;
        }
        while (points[j].x > pivot) {
            j--;
        }

        if (i <= j) {
            swap(points, i, j);
            i++;
            j--;
        }
    }
    if (low < j) quicksortX(points, low, j);
    if (i < high) quicksortX(points, i, high);
}

/**
 * Test whether a point is inside the polygon.
 *