2013-12-23 16:24:05 +00:00
|
|
|
#include "BaseTestCase.h"
|
|
|
|
|
|
|
|
#include "VertexArray.h"
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
class TestVertex {
|
|
|
|
public:
|
2013-12-23 16:24:05 +00:00
|
|
|
float uv[2];
|
|
|
|
int loc[3];
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
bool operator==(const TestVertex &other) const {
|
|
|
|
return other.uv[0] == uv[0] and other.uv[1] == uv[1] and other.loc[0] == loc[0] and other.loc[1] == loc[1] and
|
|
|
|
other.loc[2] == loc[2];
|
2013-12-23 16:24:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(VertexArray, grid) {
|
2013-12-23 16:24:05 +00:00
|
|
|
VertexArray<TestVertex> array;
|
|
|
|
|
|
|
|
array.setGridSize(3);
|
|
|
|
|
|
|
|
ASSERT_EQ(9, array.getVertexCount());
|
|
|
|
|
|
|
|
TestVertex v1 = {{0.1, 0.2}, {1, 2, 3}};
|
|
|
|
TestVertex vgot;
|
|
|
|
|
|
|
|
array.setGridVertex(3, 1, 2, v1);
|
|
|
|
vgot = array.getGridVertex(3, 1, 2);
|
|
|
|
EXPECT_EQ(v1, vgot);
|
|
|
|
vgot = array.getVertex(7);
|
|
|
|
EXPECT_EQ(v1, vgot);
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(VertexArray, gridIndices) {
|
2013-12-23 16:24:05 +00:00
|
|
|
VertexArray<TestVertex> array;
|
|
|
|
|
|
|
|
array.setGridSize(3);
|
|
|
|
|
|
|
|
array.setAutoGridIndices(3);
|
|
|
|
ASSERT_EQ(24, array.getIndexCount());
|
|
|
|
|
|
|
|
EXPECT_EQ(0, array.getIndex(0));
|
|
|
|
EXPECT_EQ(3, array.getIndex(1));
|
|
|
|
EXPECT_EQ(1, array.getIndex(2));
|
|
|
|
|
|
|
|
EXPECT_EQ(1, array.getIndex(3));
|
|
|
|
EXPECT_EQ(3, array.getIndex(4));
|
|
|
|
EXPECT_EQ(4, array.getIndex(5));
|
|
|
|
|
|
|
|
EXPECT_EQ(1, array.getIndex(6));
|
|
|
|
EXPECT_EQ(4, array.getIndex(7));
|
|
|
|
EXPECT_EQ(2, array.getIndex(8));
|
|
|
|
|
|
|
|
EXPECT_EQ(2, array.getIndex(9));
|
|
|
|
EXPECT_EQ(4, array.getIndex(10));
|
|
|
|
EXPECT_EQ(5, array.getIndex(11));
|
|
|
|
|
|
|
|
EXPECT_EQ(3, array.getIndex(12));
|
|
|
|
EXPECT_EQ(6, array.getIndex(13));
|
|
|
|
EXPECT_EQ(4, array.getIndex(14));
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(VertexArray, gridIndicesStride) {
|
2013-12-23 16:24:05 +00:00
|
|
|
VertexArray<TestVertex> array;
|
|
|
|
|
|
|
|
array.setGridSize(5);
|
|
|
|
|
|
|
|
array.setAutoGridIndices(5, 1);
|
|
|
|
ASSERT_EQ(96, array.getIndexCount());
|
|
|
|
|
|
|
|
array.setAutoGridIndices(5, 2);
|
|
|
|
ASSERT_EQ(24, array.getIndexCount());
|
|
|
|
|
|
|
|
EXPECT_EQ(0, array.getIndex(0));
|
|
|
|
EXPECT_EQ(10, array.getIndex(1));
|
|
|
|
EXPECT_EQ(2, array.getIndex(2));
|
|
|
|
|
|
|
|
EXPECT_EQ(2, array.getIndex(3));
|
|
|
|
EXPECT_EQ(10, array.getIndex(4));
|
|
|
|
EXPECT_EQ(12, array.getIndex(5));
|
|
|
|
|
|
|
|
EXPECT_EQ(2, array.getIndex(6));
|
|
|
|
EXPECT_EQ(12, array.getIndex(7));
|
|
|
|
EXPECT_EQ(4, array.getIndex(8));
|
|
|
|
|
|
|
|
EXPECT_EQ(4, array.getIndex(9));
|
|
|
|
EXPECT_EQ(12, array.getIndex(10));
|
|
|
|
EXPECT_EQ(14, array.getIndex(11));
|
|
|
|
|
|
|
|
EXPECT_EQ(10, array.getIndex(12));
|
|
|
|
EXPECT_EQ(20, array.getIndex(13));
|
|
|
|
EXPECT_EQ(12, array.getIndex(14));
|
|
|
|
}
|