Fix casting.

Casting conditions got clarified.
User is now able to say he doesn't care if casting a wrapper on a
type larger than just the coordinates will stomp on extra data
from the casted type.
This commit is contained in:
King_DuckZ 2015-07-25 19:12:21 +02:00
parent e64db02ac3
commit 1567feaa81
4 changed files with 89 additions and 35 deletions

View file

@ -45,7 +45,14 @@ namespace vwr {
float x;
float y;
float z;
float c;
int c, d;
};
struct TrailingDataVector3 {
float X;
float Y;
float Z;
int a, b;
};
template <>
@ -145,6 +152,21 @@ namespace vwr {
};
};
template <>
struct VectorWrapperInfo<TrailingDataVector3> {
enum {
dimensions = 3,
cast_ignore_trailing_properties = 1
};
typedef float scalar_type;
enum {
offset_x = offsetof(TrailingDataVector3, X),
offset_y = offsetof(TrailingDataVector3, Y),
offset_z = offsetof(TrailingDataVector3, Z)
};
};
typedef Vec<float> svec1;
typedef Vec<SimpleVector2> svec2;
typedef Vec<SimpleVector3> svec3;
@ -153,6 +175,7 @@ namespace vwr {
typedef Vec<IntVector3> ivec3;
typedef Vec<MixedDataVector3> mvec3;
typedef Vec<PaddedVector3> pvec3;
typedef Vec<TrailingDataVector3> tvec3;
static_assert(sizeof(svec1) == sizeof(float), "Wrong size");
static_assert(sizeof(svec2) == sizeof(SimpleVector2), "Wrong size");

View file

@ -7,6 +7,12 @@ void test_svec3 (const vwr::svec3& parVec, float parX, float parY, float parZ) {
EXPECT_EQ(parVec.z(), parZ);
}
void test_tvec3 (const vwr::tvec3& parVec, float parX, float parY, float parZ) {
EXPECT_EQ(parVec.x(), parX);
EXPECT_EQ(parVec.y(), parY);
EXPECT_EQ(parVec.z(), parZ);
}
TEST(vwr, conversion) {
using namespace vwr;
@ -42,5 +48,6 @@ TEST(vwr, conversion) {
{
pvec3 p3(1.0f, 2.0f, 3.0f);
test_svec3(p3.cast<svec3>(), p3.x(), p3.y(), p3.z());
test_tvec3(p3.cast<tvec3>(), p3.x(), p3.y(), p3.z());
}
}