Make scalar_type and vector_type public in Vec.
- Add a dot product implementation. - Test code to demonstrate dot product. - Test code to demonstrate wrapping structs with unordered properties.
This commit is contained in:
parent
40ca5cd388
commit
958de67849
4 changed files with 71 additions and 3 deletions
|
@ -3,6 +3,7 @@ project(unit CXX)
|
|||
add_executable(${PROJECT_NAME}
|
||||
${GTEST_MAIN_CPP}
|
||||
test_conversions.cpp
|
||||
test_ops.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
|
|
45
test/unit/test_ops.cpp
Normal file
45
test/unit/test_ops.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "sample_vectors.hpp"
|
||||
#include "vectorwrapper/vectorops.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
struct UnorderedVector {
|
||||
int64_t y;
|
||||
int64_t z;
|
||||
int64_t x;
|
||||
};
|
||||
namespace vwr {
|
||||
template <>
|
||||
struct VectorWrapperInfo<UnorderedVector> {
|
||||
enum { dimensions = 3 };
|
||||
typedef int64_t scalar_type;
|
||||
|
||||
enum {
|
||||
offset_x = offsetof(UnorderedVector, x),
|
||||
offset_y = offsetof(UnorderedVector, y),
|
||||
offset_z = offsetof(UnorderedVector, z)
|
||||
};
|
||||
};
|
||||
} //namespace vwr
|
||||
|
||||
typedef vwr::Vec<UnorderedVector> uvec3i;
|
||||
|
||||
TEST(vwr, ops) {
|
||||
using namespace vwr;
|
||||
|
||||
ivec3 a(1);
|
||||
ivec3 b(1);
|
||||
|
||||
EXPECT_EQ(3, dot(a, b));
|
||||
EXPECT_EQ(3, dot(a, a));
|
||||
|
||||
a = ivec3{5, 2, 8};
|
||||
b = ivec3{6, 9, 3};
|
||||
EXPECT_EQ(6*5+2*9+8*3, dot(a, b));
|
||||
|
||||
uvec3i c(7, 2, 9);
|
||||
EXPECT_EQ(7, c.x());
|
||||
EXPECT_EQ(2, c.y());
|
||||
EXPECT_EQ(9, c.z());
|
||||
EXPECT_EQ(7*5+2*2+9*8, dot(a, c));
|
||||
EXPECT_EQ(7*6+2*9+9*3, dot(b, c));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue