diff --git a/src/OpenMesh/Core/Geometry/Vector11T.hh b/src/OpenMesh/Core/Geometry/Vector11T.hh index e29f5013..4d8792aa 100644 --- a/src/OpenMesh/Core/Geometry/Vector11T.hh +++ b/src/OpenMesh/Core/Geometry/Vector11T.hh @@ -81,6 +81,9 @@ namespace OpenMesh { template class VectorT { + + static_assert(DIM >= 1, "VectorT requires positive dimensionality."); + private: std::array values_; @@ -154,9 +157,10 @@ class VectorT { 1); } - /// construct from a value array (explicit) - explicit inline VectorT(const Scalar _values[DIM]) { - std::copy(_values, _values + DIM, values_.begin()); + /// construct from a value array or any other iterator + template + explicit inline VectorT(Iterator it) { + std::copy_n(it, DIM, values_.begin()); } /// copy & cast constructor (explicit) diff --git a/src/Unittests/unittests_vector_type.cc b/src/Unittests/unittests_vector_type.cc index e6bf0176..bb27754d 100644 --- a/src/Unittests/unittests_vector_type.cc +++ b/src/Unittests/unittests_vector_type.cc @@ -1,6 +1,7 @@ #include #include #include +#include namespace { @@ -171,6 +172,15 @@ TEST_F(OpenMeshVectorTest, move_constructor_assignment) { EXPECT_EQ(3, C::copy_con); } +TEST_F(OpenMeshVectorTest, iterator_init) { + std::list a; + a.push_back(1.0); + a.push_back(2.0); + a.push_back(3.0); + OpenMesh::Vec3f v(a.begin()); + EXPECT_EQ(OpenMesh::Vec3f(1.0, 2.0, 3.0), v); +} + #endif // C++11 @@ -200,6 +210,12 @@ TEST_F(OpenMeshVectorTest, BasicLinearAlgebra) { EXPECT_NEAR(14, OpenMesh::Vec3d(-1, -2, -3) | OpenMesh::Vec3d(-1, -2, -3), 1e-6); } +TEST_F(OpenMeshVectorTest, array_init) { + float a[3]; a[0] = 1.0; a[1] = 2.0; a[2] = 3.0; + OpenMesh::Vec3f v(a); + EXPECT_EQ(OpenMesh::Vec3f(1.0, 2.0, 3.0), v); +} + TEST_F(OpenMeshVectorTest, normalized_cond) { OpenMesh::Vec3d v1(1, -2, 3), v2(0, 0, 0); EXPECT_EQ(OpenMesh::Vec3d(0, 0, 0), v2.normalize_cond());