diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-28 18:33:48 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-28 18:35:32 +0400 |
commit | 28322c1496a1371d5e46c5d6542b8b5abfa9a6e8 (patch) | |
tree | a8b9aa3b12de725f60fe696e67234cde194b251c /source/blender/blenlib/intern/convexhull2d.c | |
parent | fdcb9fcb7e4b32eb32ed7b2cae9451f297884170 (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.c | 17 |
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])); |