diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 5bcb765ea..9311cc989 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -32,7 +32,7 @@ #include #include -#include "Math/Vector.h" +#include "Math/Functions.h" #include "Magnum.h" namespace Magnum { namespace MeshTools { @@ -92,32 +92,23 @@ template void Clean::o if(indices.empty()) return; /* Get mesh bounds */ - Vertex min, max; - for(std::size_t i = 0; i != Vertex::Size; ++i) { - min[i] = std::numeric_limits::max(); - max[i] = std::numeric_limits::min(); + Vertex min = vertices[0], max = vertices[0]; + for(const auto& v: vertices) { + min = Math::min(v, min); + max = Math::max(v, max); } - for(auto it = vertices.cbegin(); it != vertices.cend(); ++it) - for(std::size_t i = 0; i != vertexSize; ++i) - if((*it)[i] < min[i]) - min[i] = (*it)[i]; - else if((*it)[i] > max[i]) - max[i] = (*it)[i]; - - /* Make epsilon so large that std::size_t can index all vertices - inside mesh bounds. */ - Vertex size = max-min; - for(std::size_t i = 0; i != Vertex::Size; ++i) - if(static_cast(size[i]/std::numeric_limits::max()) > epsilon) - epsilon = static_cast(size[i]/std::numeric_limits::max()); + + /* Make epsilon so large that std::size_t can index all vertices inside + mesh bounds. */ + epsilon = Math::max(epsilon, static_cast((max-min).max()/std::numeric_limits::max())); /* First go with original vertex coordinates, then move them by - epsilon/2 in each direction. */ + epsilon/2 in each direction. */ Vertex moved; for(std::size_t moving = 0; moving <= vertexSize; ++moving) { /* Under each index is pointer to face which contains given vertex - and index of vertex in the face. */ + and index of vertex in the face. */ std::unordered_map, HashedVertex, IndexHash> table; /* Reserve space for all vertices */ @@ -131,8 +122,8 @@ template void Clean::o index[ii] = (vertices[*it][ii]+moved[ii]-min[ii])/epsilon; /* Try inserting the vertex into table, if it already - exists, change vertex pointer of the face to already - existing vertex */ + exists, change vertex pointer of the face to already + existing vertex */ HashedVertex v(*it, table.size()); auto result = table.insert(std::pair, HashedVertex>(Math::Vector::from(index), v)); *it = result.first->second.newIndex; diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index 7f5d5fdc4..50b0a711a 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -35,21 +35,7 @@ class CleanTest: public TestSuite::Tester { void cleanMesh(); }; -class Vector1 { - public: - static const std::size_t Size = 1; - typedef Int Type; - - Vector1(): data(0) {} - Vector1(Type i): data(i) {} - Type operator[](std::size_t) const { return data; } - Type& operator[](std::size_t) { return data; } - bool operator==(Vector1 i) const { return i.data == data; } - Vector1 operator-(Vector1 i) const { return data-i.data; } - - private: - Type data; -}; +typedef Math::Vector<1, int> Vector1; CleanTest::CleanTest() { addTests({&CleanTest::cleanMesh}); diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 3b1f26061..232db6940 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -36,26 +36,15 @@ class SubdivideTest: public TestSuite::Tester { void wrongIndexCount(); void subdivide(); +}; - private: - class Vector1 { - public: - static const std::size_t Size = 1; - typedef Int Type; +namespace { - Vector1(): data(0) {} - Vector1(Type i): data(i) {} - Type operator[](std::size_t) const { return data; } - Type& operator[](std::size_t) { return data; } - bool operator==(Vector1 i) const { return i.data == data; } - Vector1 operator-(Vector1 i) const { return data-i.data; } +typedef Math::Vector<1, Int> Vector1; - private: - Type data; - }; +inline Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; } - static Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; } -}; +} SubdivideTest::SubdivideTest() { addTests({&SubdivideTest::wrongIndexCount,