BLI_heap: add an API function to directly read the top node value.
It is very commonly needed in loop conditions to check if the items in the heap are good enough to continue.
This commit is contained in:
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -317,6 +317,17 @@ HeapNode *BLI_heap_top(const Heap *heap)
|
||||
return heap->tree[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user