// // rotate_test.cpp // datamodel // // Created by Sam Jaffe on 9/30/15. // // #include #include #include "rotate/rotate.hpp" struct Point { float x = 0.f, y = 0.f; Point() = default; Point(float _x, float _y) : x(_x), y(_y) {} bool operator==(const Point& other) const { return !memcmp(this, &other, sizeof(*this)); } }; struct Dimension { float width = 0.f, height = 0.f; Dimension() = default; Dimension(float w, float h) : width(w), height(h) {} bool operator==(const Dimension& other) const { return !memcmp(this, &other, sizeof(*this)); } }; struct Material { int id = -1; Material() = default; Material(int i) : id(i) {} bool operator==(const Material& other) const { return !memcmp(this, &other, sizeof(*this)); } }; struct RenderInfo { Point center; Material material; Dimension texture_size, object_size; Point bottom_left, bottom_right, top_right, top_left; float rotation = 0.0f; // TODO RenderInfo(Point c, Dimension sz, Material mat = {0}, Dimension tx_sz = {1.f, 1.f}) : center(c) , material(mat) , texture_size(tx_sz) , object_size(sz) , bottom_left ({c.x - sz.width / 2.f, c.y - sz.height / 2.f}) , bottom_right({c.x - sz.width / 2.f, c.y + sz.height / 2.f}) , top_right ({c.x + sz.width / 2.f, c.y + sz.height / 2.f}) , top_left ({c.x + sz.width / 2.f, c.y - sz.height / 2.f}) { } RenderInfo() = default; bool operator==(const RenderInfo& other) const { return !memcmp(this, &other, sizeof(*this)); } }; DEFINE_ROTATE(RenderInfo, (material)(texture_size)(bottom_left)(bottom_right)(top_right)(top_left)); DEFINE_ROTATE_NAME(simple_rotate, RenderInfo, (material)(texture_size)(center)(object_size)); DEFINE_PROXY_NAME(RenderInfo_position_proxy, RenderInfo, (center)(object_size)); DEFINE_PROXY_CONVERSION(RenderInfo, (material)(texture_size)(center)(object_size), (center)(object_size) ); TEST(RotateTest, CanCreateNormalProxyForData) { RenderInfo_rotate rdata; RenderInfo info{{5, 6}, {1, 1}}; rdata.push_back(info); RenderInfo_proxy proxy = rdata.get(0); EXPECT_THAT(info.texture_size, proxy.texture_size); EXPECT_THAT(info.bottom_left, proxy.bottom_left); EXPECT_THAT(info.bottom_right, proxy.bottom_right); EXPECT_THAT(info.top_left, proxy.top_left); EXPECT_THAT(info.top_right, proxy.top_right); } TEST(RotateTest, CanCreatePartialProxy) { simple_rotate rdata; RenderInfo info{{5, 6}, {1, 1}}; rdata.push_back(info); simple_rotate_proxy proxy = rdata.get(0); EXPECT_THAT(info.texture_size, proxy.texture_size); EXPECT_THAT(info.center, proxy.center); EXPECT_THAT(info.object_size, proxy.object_size); } TEST(RotateTest, RotatedDataModelExistsAsStructOfVectors) { simple_rotate rdata; RenderInfo infos[3] = {{{1,2},{1,1}},{{0,3},{1,1}},{{4,3.2f},{1,1}}}; rdata.push_back(infos[0]); rdata.push_back(infos[1]); rdata.push_back(infos[2]); EXPECT_THAT(rdata.get(access_t(RenderInfo, center){}), (std::vector{{1,2},{0,3},{4,3.2f}})); } TEST(RotateTest, CanCreateMultipleProxiesForSameObject) { simple_rotate rdata; RenderInfo info{{5, 6}, {1, 1}}; rdata.push_back(info); RenderInfo_position_proxy proxy = rdata.getp(0); EXPECT_THAT( sizeof(proxy), sizeof(Point&)+sizeof(Dimension&) ); EXPECT_THAT(info.center, proxy.center); EXPECT_THAT(info.object_size, proxy.object_size); }