Skip to content

Commit

Permalink
std::any_of instead of for-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
HeiJuli authored and endJunction committed Jul 26, 2023
1 parent 0d1886a commit da723ce
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,23 @@ bool isVoxelGrid(MeshLib::Mesh const& mesh)
"aligned hexahedra).");
return false;
}

for (auto const& e : elements)
auto is_voxel = [](auto const& e)
{
auto const n = e->getNodes();
if ((*n[0])[2] != (*n[1])[2] || (*n[1])[2] != (*n[2])[2] ||
(*n[4])[2] != (*n[5])[2] || (*n[5])[2] != (*n[6])[2] ||
(*n[1])[0] != (*n[2])[0] || (*n[2])[0] != (*n[5])[0] ||
(*n[0])[0] != (*n[3])[0] || (*n[3])[0] != (*n[7])[0])
{
ERR("Input mesh needs to be voxel grid (i.e. equally sized axis "
"aligned hexahedra).");
return false;
}
return ((*n[0])[2] != (*n[1])[2] || (*n[1])[2] != (*n[2])[2] ||
(*n[4])[2] != (*n[5])[2] || (*n[5])[2] != (*n[6])[2] ||
(*n[1])[0] != (*n[2])[0] || (*n[2])[0] != (*n[5])[0] ||
(*n[0])[0] != (*n[3])[0] || (*n[3])[0] != (*n[7])[0]);
};

if (std::any_of(elements.cbegin(), elements.cend(), is_voxel))
{
ERR("Input mesh needs to be voxel grid (i.e. equally sized axis "
"aligned hexahedra).");
return false;
}
return true;
}
} // namespace
} // namespace
namespace MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid
{
Expand Down

0 comments on commit da723ce

Please sign in to comment.