diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-03-31 20:25:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-03-31 20:25:27 +0300 |
commit | 91d0825b5556150c017dad767f7971bb6a731aec (patch) | |
tree | f014e4855bdc65c877b674f88d15f49c057cd615 | |
parent | ae3a1da1e641c89aeb3ac0d681bdbe14ecdf0ee7 (diff) |
BLI_sort_utils: add pointer sorting callback
Also rename Pointer -> Ptr
-rw-r--r-- | source/blender/blenlib/BLI_sort_utils.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/intern/sort_utils.c | 22 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_join_triangles.c | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 2 |
4 files changed, 29 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_sort_utils.h b/source/blender/blenlib/BLI_sort_utils.h index e08f4e5ac83..f6bd80b30d3 100644 --- a/source/blender/blenlib/BLI_sort_utils.h +++ b/source/blender/blenlib/BLI_sort_utils.h @@ -32,7 +32,7 @@ * \note keep \a sort_value first, * so cmp functions can be reused. */ -struct SortPointerByFloat { +struct SortPtrByFloat { float sort_value; void *data; }; @@ -42,7 +42,7 @@ struct SortIntByFloat { int data; }; -struct SortPointerByInt { +struct SortPtrByInt { int sort_value; void *data; }; @@ -58,4 +58,7 @@ int BLI_sortutil_cmp_float_reverse(const void *a_, const void *b_); int BLI_sortutil_cmp_int(const void *a_, const void *b_); int BLI_sortutil_cmp_int_reverse(const void *a_, const void *b_); +int BLI_sortutil_cmp_ptr(const void *a_, const void *b_); +int BLI_sortutil_cmp_ptr_reverse(const void *a_, const void *b_); + #endif /* __BLI_SORT_UTILS_H__ */ diff --git a/source/blender/blenlib/intern/sort_utils.c b/source/blender/blenlib/intern/sort_utils.c index c75e8e7455f..2d55e77b98b 100644 --- a/source/blender/blenlib/intern/sort_utils.c +++ b/source/blender/blenlib/intern/sort_utils.c @@ -37,6 +37,10 @@ struct SortAnyByInt { int sort_value; }; +struct SortAnyByPtr { + const void *sort_value; +}; + int BLI_sortutil_cmp_float(const void *a_, const void *b_) { const struct SortAnyByFloat *a = a_; @@ -72,3 +76,21 @@ int BLI_sortutil_cmp_int_reverse(const void *a_, const void *b_) else if (a->sort_value > b->sort_value) return -1; else return 0; } + +int BLI_sortutil_cmp_ptr(const void *a_, const void *b_) +{ + const struct SortAnyByPtr *a = a_; + const struct SortAnyByPtr *b = b_; + if (a->sort_value > b->sort_value) return 1; + else if (a->sort_value < b->sort_value) return -1; + else return 0; +} + +int BLI_sortutil_cmp_ptr_reverse(const void *a_, const void *b_) +{ + const struct SortAnyByPtr *a = a_; + const struct SortAnyByPtr *b = b_; + if (a->sort_value < b->sort_value) return 1; + else if (a->sort_value > b->sort_value) return -1; + else return 0; +} diff --git a/source/blender/bmesh/operators/bmo_join_triangles.c b/source/blender/bmesh/operators/bmo_join_triangles.c index 69198ff35ab..b1053e6d8c2 100644 --- a/source/blender/bmesh/operators/bmo_join_triangles.c +++ b/source/blender/bmesh/operators/bmo_join_triangles.c @@ -270,7 +270,7 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) BMFace *f; BMEdge *e; /* data: edge-to-join, sort_value: error weight */ - struct SortPointerByFloat *jedges; + struct SortPtrByFloat *jedges; unsigned i, totedge; uint totedge_tag = 0; diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 2d7ddc7d9c1..2a6d7ded949 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -3745,7 +3745,7 @@ static void edbm_fill_grid_prepare(BMesh *bm, int offset, int *r_span, bool span * * note: we may have already checked 'edbm_fill_grid_vert_tag_angle()' on each * vert, but advantage of de-duplicating is minimal. */ - struct SortPointerByFloat *ele_sort = MEM_mallocN(sizeof(*ele_sort) * verts_len, __func__); + struct SortPtrByFloat *ele_sort = MEM_mallocN(sizeof(*ele_sort) * verts_len, __func__); LinkData *v_link; for (v_link = verts->first, i = 0; v_link; v_link = v_link->next, i++) { BMVert *v = v_link->data; |