C++11: Made VectorT's constructor from array more general.
This commit is contained in:
@@ -81,6 +81,9 @@ namespace OpenMesh {
|
|||||||
|
|
||||||
template<typename Scalar, int DIM>
|
template<typename Scalar, int DIM>
|
||||||
class VectorT {
|
class VectorT {
|
||||||
|
|
||||||
|
static_assert(DIM >= 1, "VectorT requires positive dimensionality.");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<Scalar, DIM> values_;
|
std::array<Scalar, DIM> values_;
|
||||||
|
|
||||||
@@ -154,9 +157,10 @@ class VectorT {
|
|||||||
1);
|
1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// construct from a value array (explicit)
|
/// construct from a value array or any other iterator
|
||||||
explicit inline VectorT(const Scalar _values[DIM]) {
|
template<typename Iterator>
|
||||||
std::copy(_values, _values + DIM, values_.begin());
|
explicit inline VectorT(Iterator it) {
|
||||||
|
std::copy_n(it, DIM, values_.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// copy & cast constructor (explicit)
|
/// copy & cast constructor (explicit)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <Unittests/unittests_common.hh>
|
#include <Unittests/unittests_common.hh>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -171,6 +172,15 @@ TEST_F(OpenMeshVectorTest, move_constructor_assignment) {
|
|||||||
EXPECT_EQ(3, C::copy_con);
|
EXPECT_EQ(3, C::copy_con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(OpenMeshVectorTest, iterator_init) {
|
||||||
|
std::list<float> 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
|
#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);
|
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) {
|
TEST_F(OpenMeshVectorTest, normalized_cond) {
|
||||||
OpenMesh::Vec3d v1(1, -2, 3), v2(0, 0, 0);
|
OpenMesh::Vec3d v1(1, -2, 3), v2(0, 0, 0);
|
||||||
EXPECT_EQ(OpenMesh::Vec3d(0, 0, 0), v2.normalize_cond());
|
EXPECT_EQ(OpenMesh::Vec3d(0, 0, 0), v2.normalize_cond());
|
||||||
|
|||||||
Reference in New Issue
Block a user