Cleanup: Add utility to compare non-indexed and indexed span values

This will be useful for other types in the future (similar abstractions
for editing face sets), and it makes more semantic sense as a templated
utility function.
This commit is contained in:
Hans Goudey 2023-12-06 22:51:09 -05:00
parent 184418b6d0
commit dc234c5d93
4 changed files with 13 additions and 13 deletions

View File

@ -269,4 +269,15 @@ template<typename T> inline void fill_index_range(MutableSpan<T> span, const T s
std::iota(span.begin(), span.end(), start);
}
template<typename T>
bool indexed_data_equal(const Span<T> all_values, const Span<int> indices, const Span<T> values)
{
for (const int i : indices.index_range()) {
if (all_values[indices[i]] != values[i]) {
return true;
}
}
return false;
}
} // namespace blender::array_utils

View File

@ -177,16 +177,6 @@ void mesh_show_all(Object &object, const Span<PBVHNode *> nodes)
bke::mesh_hide_vert_flush(mesh);
}
bool hide_is_changed(const Span<int> verts, const Span<bool> orig_hide, const Span<bool> new_hide)
{
for (const int i : verts.index_range()) {
if (orig_hide[verts[i]] != new_hide[i]) {
return true;
}
}
return false;
}
static void vert_hide_update(Object &object,
const Span<PBVHNode *> nodes,
const FunctionRef<void(Span<int>, MutableSpan<bool>)> calc_hide)
@ -206,7 +196,7 @@ static void vert_hide_update(Object &object,
new_hide.reinitialize(verts.size());
array_utils::gather(hide_vert.span.as_span(), verts, new_hide.as_mutable_span());
calc_hide(verts, new_hide);
if (!hide_is_changed(verts, hide_vert.span, new_hide)) {
if (!array_utils::indexed_data_equal<bool>(hide_vert.span, verts, new_hide)) {
continue;
}

View File

@ -456,7 +456,6 @@ enum BrushStrokeMode {
namespace blender::ed::sculpt_paint::hide {
void sync_all_from_faces(Object &object);
bool hide_is_changed(Span<int> verts, Span<bool> orig_hide, Span<bool> new_hide);
void mesh_show_all(Object &object, const Span<PBVHNode *> nodes);
void grids_show_all(Depsgraph &depsgraph, Object &object, Span<PBVHNode *> nodes);
void tag_update_visibility(const bContext &C);

View File

@ -861,7 +861,7 @@ static void face_hide_update(Object &object,
MutableSpan<bool> new_hide = tls.new_hide;
array_utils::gather(hide_poly.span.as_span(), faces, new_hide);
calc_hide(faces, new_hide);
if (!hide::hide_is_changed(faces, hide_poly.span, new_hide)) {
if (!array_utils::indexed_data_equal<bool>(hide_poly.span, faces, new_hide)) {
continue;
}