diff options
-rw-r--r-- | source/blender/blenkernel/intern/colorband.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_heap.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_heap.c | 11 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_decimate_collapse.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 4 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_heap_test.cc | 1 |
6 files changed, 18 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/colorband.c b/source/blender/blenkernel/intern/colorband.c index f72d4df725a..38631c76009 100644 --- a/source/blender/blenkernel/intern/colorband.c +++ b/source/blender/blenkernel/intern/colorband.c @@ -208,7 +208,7 @@ static void colorband_init_from_table_rgba_resample( } while ((carr_len > 1 && !BLI_heap_is_empty(heap)) && - ((carr_len >= MAXCOLORBAND) || (BLI_heap_node_value(BLI_heap_top(heap)) <= eps_2x))) + ((carr_len >= MAXCOLORBAND) || (BLI_heap_top_value(heap) <= eps_2x))) { c = BLI_heap_pop_min(heap); struct ColorResampleElem *c_next = c->next, *c_prev = c->prev; diff --git a/source/blender/blenlib/BLI_heap.h b/source/blender/blenlib/BLI_heap.h index 771b9dabe4d..35c8df3075c 100644 --- a/source/blender/blenlib/BLI_heap.h +++ b/source/blender/blenlib/BLI_heap.h @@ -43,6 +43,7 @@ void BLI_heap_remove(Heap *heap, HeapNode *node) ATTR_NONNULL(1, 2); bool BLI_heap_is_empty(const Heap *heap) ATTR_NONNULL(1); unsigned int BLI_heap_len(const Heap *heap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); HeapNode *BLI_heap_top(const Heap *heap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); +float BLI_heap_top_value(const Heap *heap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); void *BLI_heap_pop_min(Heap *heap) ATTR_NONNULL(1); void BLI_heap_node_value_update(Heap *heap, HeapNode *node, float value) ATTR_NONNULL(1, 2); void BLI_heap_node_value_update_ptr(Heap *heap, HeapNode *node, float value, void *ptr) ATTR_NONNULL(1, 2); diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 5658c1fd103..17a15f93266 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -318,6 +318,17 @@ HeapNode *BLI_heap_top(const Heap *heap) } /** + * Return the value of top node of the heap. + * This is the node with the lowest value. + */ +float BLI_heap_top_value(const Heap *heap) +{ + BLI_assert(heap->size != 0); + + return heap->tree[0]->value; +} + +/** * Pop the top node off the heap and return it's pointer. */ void *BLI_heap_pop_min(Heap *heap) diff --git a/source/blender/bmesh/tools/bmesh_decimate_collapse.c b/source/blender/bmesh/tools/bmesh_decimate_collapse.c index c1b2bc2625b..fa427b3b9eb 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_collapse.c +++ b/source/blender/bmesh/tools/bmesh_decimate_collapse.c @@ -1354,7 +1354,7 @@ void BM_mesh_decimate_collapse( /* simple non-mirror case */ while ((bm->totface > face_tot_target) && (BLI_heap_is_empty(eheap) == false) && - (BLI_heap_node_value(BLI_heap_top(eheap)) != COST_INVALID)) + (BLI_heap_top_value(eheap) != COST_INVALID)) { // const float value = BLI_heap_node_value(BLI_heap_top(eheap)); BMEdge *e = BLI_heap_pop_min(eheap); @@ -1379,7 +1379,7 @@ void BM_mesh_decimate_collapse( else { while ((bm->totface > face_tot_target) && (BLI_heap_is_empty(eheap) == false) && - (BLI_heap_node_value(BLI_heap_top(eheap)) != COST_INVALID)) + (BLI_heap_top_value(eheap) != COST_INVALID)) { /** * \note diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index c11aefb7e14..b16195023c9 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -7868,10 +7868,10 @@ static int edbm_average_normals_exec(bContext *C, wmOperator *op) BLI_SMALLSTACK_DECLARE(loops, BMLoop *); float wnor[3], avg_normal[3] = { 0.0f }, count = 0; - float val = BLI_heap_node_value(BLI_heap_top(loop_weight)); + float val = BLI_heap_top_value(loop_weight); while (!BLI_heap_is_empty(loop_weight)) { - const float cur_val = BLI_heap_node_value(BLI_heap_top(loop_weight)); + const float cur_val = BLI_heap_top_value(loop_weight); if (!compare_ff(val, cur_val, threshold)) { count++; val = cur_val; diff --git a/tests/gtests/blenlib/BLI_heap_test.cc b/tests/gtests/blenlib/BLI_heap_test.cc index 69566d8dca6..26f3aa19b9f 100644 --- a/tests/gtests/blenlib/BLI_heap_test.cc +++ b/tests/gtests/blenlib/BLI_heap_test.cc @@ -176,6 +176,7 @@ static void random_heap_reinsert_helper( for (int out_test = 0; out_test < items_total; out_test++) { HeapNode *node_top = BLI_heap_top(heap); float out = BLI_heap_node_value(node_top); + EXPECT_EQ(out, BLI_heap_top_value(heap)); EXPECT_EQ((float)out_test, out); BLI_heap_pop_min(heap); } |