Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-04-28 18:33:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-04-28 18:35:32 +0400
commit28322c1496a1371d5e46c5d6542b8b5abfa9a6e8 (patch)
treea8b9aa3b12de725f60fe696e67234cde194b251c /source/blender/blenlib/intern/convexhull2d.c
parentfdcb9fcb7e4b32eb32ed7b2cae9451f297884170 (diff)
Convex Hull 2D: avoid calling qsort twice
Diffstat (limited to 'source/blender/blenlib/intern/convexhull2d.c')
-rw-r--r--source/blender/blenlib/intern/convexhull2d.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/source/blender/blenlib/intern/convexhull2d.c b/source/blender/blenlib/intern/convexhull2d.c
index 9f509638e3b..34ee39d8a9b 100644
--- a/source/blender/blenlib/intern/convexhull2d.c
+++ b/source/blender/blenlib/intern/convexhull2d.c
@@ -167,21 +167,17 @@ struct PointRef {
const float *pt; /* 2d vector */
};
-static int pointref_cmp_x(const void *a_, const void *b_)
+static int pointref_cmp_yx(const void *a_, const void *b_)
{
const struct PointRef *a = a_;
const struct PointRef *b = b_;
- if (a->pt[0] > b->pt[0]) return 1;
- else if (a->pt[0] < b->pt[0]) return -1;
- else return 0;
-}
-static int pointref_cmp_y(const void *a_, const void *b_)
-{
- const struct PointRef *a = a_;
- const struct PointRef *b = b_;
if (a->pt[1] > b->pt[1]) return 1;
else if (a->pt[1] < b->pt[1]) return -1;
+
+ if (a->pt[0] > b->pt[0]) return 1;
+ else if (a->pt[0] < b->pt[0]) return -1;
+
else return 0;
}
@@ -207,8 +203,7 @@ int BLI_convexhull_2d(const float (*points)[2], const int n, int r_points[])
}
/* Sort the points by X, then by Y (required by the algorithm) */
- qsort(points_ref, (size_t)n, sizeof(struct PointRef), pointref_cmp_x);
- qsort(points_ref, (size_t)n, sizeof(struct PointRef), pointref_cmp_y);
+ qsort(points_ref, (size_t)n, sizeof(struct PointRef), pointref_cmp_yx);
for (i = 0; i < n; i++) {
memcpy(points_sort[i], points_ref[i].pt, sizeof(float[2]));