| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // rotate_tc.h
- // datamodel
- //
- // Created by Sam Jaffe on 9/30/15.
- //
- //
- #include <cxxtest/TestSuite.h>
- #include "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) );
- class rotate_TestSuite : public CxxTest::TestSuite {
- public:
- void test_proxy1() const {
- RenderInfo_rotate rdata;
- RenderInfo info{{5, 6}, {1, 1}};
- rdata.push_back(info);
- RenderInfo_proxy proxy = rdata.get(0);
- TS_ASSERT_EQUALS(info.texture_size, proxy.texture_size);
- TS_ASSERT_EQUALS(info.bottom_left, proxy.bottom_left);
- TS_ASSERT_EQUALS(info.bottom_right, proxy.bottom_right);
- TS_ASSERT_EQUALS(info.top_left, proxy.top_left);
- TS_ASSERT_EQUALS(info.top_right, proxy.top_right);
- }
-
- void test_proxy2() const {
- simple_rotate rdata;
- RenderInfo info{{5, 6}, {1, 1}};
- rdata.push_back(info);
- simple_rotate_proxy proxy = rdata.get(0);
- TS_ASSERT_EQUALS(info.texture_size, proxy.texture_size);
- TS_ASSERT_EQUALS(info.center, proxy.center);
- TS_ASSERT_EQUALS(info.object_size, proxy.object_size);
- }
- void test_datamodel_center() const {
- 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]);
- TS_ASSERT_EQUALS(rdata.get(access_t(RenderInfo, center){}), (std::vector<Point>{{1,2},{0,3},{4,3.2f}}));
- }
-
- void test_datamodel_multiproxy() const {
- simple_rotate rdata;
- RenderInfo info{{5, 6}, {1, 1}};
- rdata.push_back(info);
- RenderInfo_position_proxy proxy = rdata.getp<rotate_members(RenderInfo, (center)(object_size))>(0);
- TS_ASSERT_EQUALS( sizeof(proxy), sizeof(Point&)+sizeof(Dimension&) );
- TS_ASSERT_EQUALS(info.center, proxy.center);
- TS_ASSERT_EQUALS(info.object_size, proxy.object_size);
- }
- private:
-
- };
|