mirror of
https://projects.blender.org/blender/blender.git
synced 2025-01-22 07:22:12 -05:00
Fix: Complete recent fix to array_utils boolean mix utility
1d53025868
missed the fix to the VArray case.
This commit is contained in:
parent
6edeae5c90
commit
9266fbab02
Notes:
blender-bot
2024-06-15 12:36:19 +02:00
Referenced by issue #104061, Custom render engine is unable to create gpu context
1 changed files with 21 additions and 14 deletions
|
@ -92,6 +92,17 @@ void invert_booleans(MutableSpan<bool> span, const IndexMask &mask)
|
|||
mask.foreach_index_optimized<int64_t>([&](const int64_t i) { span[i] = !span[i]; });
|
||||
}
|
||||
|
||||
static bool all_equal(const Span<bool> span, const bool test)
|
||||
{
|
||||
return std::all_of(span.begin(), span.end(), [&](const bool value) { return value == test; });
|
||||
}
|
||||
|
||||
static bool all_equal(const VArray<bool> &varray, const IndexRange range, const bool test)
|
||||
{
|
||||
return std::all_of(
|
||||
range.begin(), range.end(), [&](const int64_t i) { return varray[i] == test; });
|
||||
}
|
||||
|
||||
BooleanMix booleans_mix_calc(const VArray<bool> &varray, const IndexRange range_to_check)
|
||||
{
|
||||
if (varray.is_empty()) {
|
||||
|
@ -111,16 +122,13 @@ BooleanMix booleans_mix_calc(const VArray<bool> &varray, const IndexRange range_
|
|||
if (init == BooleanMix::Mixed) {
|
||||
return init;
|
||||
}
|
||||
|
||||
const Span<bool> slice = span.slice(range);
|
||||
const bool compare_value = (init == BooleanMix::None) ? slice.first() :
|
||||
(init == BooleanMix::AllTrue);
|
||||
for (const bool value : slice) {
|
||||
if (value != compare_value) {
|
||||
return BooleanMix::Mixed;
|
||||
}
|
||||
const bool compare = (init == BooleanMix::None) ? slice.first() :
|
||||
(init == BooleanMix::AllTrue);
|
||||
if (all_equal(slice, compare)) {
|
||||
return compare ? BooleanMix::AllTrue : BooleanMix::AllFalse;
|
||||
}
|
||||
return compare_value ? BooleanMix::AllTrue : BooleanMix::AllFalse;
|
||||
return BooleanMix::Mixed;
|
||||
},
|
||||
[&](BooleanMix a, BooleanMix b) { return (a == b) ? a : BooleanMix::Mixed; });
|
||||
}
|
||||
|
@ -133,13 +141,12 @@ BooleanMix booleans_mix_calc(const VArray<bool> &varray, const IndexRange range_
|
|||
return init;
|
||||
}
|
||||
/* Alternatively, this could use #materialize to retrieve many values at once. */
|
||||
const bool first = varray[range.first()];
|
||||
for (const int64_t i : range.drop_front(1)) {
|
||||
if (varray[i] != first) {
|
||||
return BooleanMix::Mixed;
|
||||
}
|
||||
const bool compare = (init == BooleanMix::None) ? varray[range.first()] :
|
||||
(init == BooleanMix::AllTrue);
|
||||
if (all_equal(varray, range, compare)) {
|
||||
return compare ? BooleanMix::AllTrue : BooleanMix::AllFalse;
|
||||
}
|
||||
return first ? BooleanMix::AllTrue : BooleanMix::AllFalse;
|
||||
return BooleanMix::Mixed;
|
||||
},
|
||||
[&](BooleanMix a, BooleanMix b) { return (a == b) ? a : BooleanMix::Mixed; });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue