Commit 14dffb83 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

C++11: Made VectorT's constructor from array more general.

parent c8b5dea2
......@@ -81,6 +81,9 @@ namespace OpenMesh {
template<typename Scalar, int DIM>
class VectorT {
static_assert(DIM >= 1, "VectorT requires positive dimensionality.");
private:
std::array<Scalar, DIM> 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<typename Iterator>
explicit inline VectorT(Iterator it) {
std::copy_n(it, DIM, values_.begin());
}
/// copy & cast constructor (explicit)
......
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <iostream>
#include <list>
namespace {
......@@ -171,6 +172,15 @@ TEST_F(OpenMeshVectorTest, move_constructor_assignment) {
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
......@@ -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());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment