rotate_tc.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // rotate_tc.h
  3. // datamodel
  4. //
  5. // Created by Sam Jaffe on 9/30/15.
  6. //
  7. //
  8. #include <cxxtest/TestSuite.h>
  9. #include "rotate.hpp"
  10. struct Point {
  11. float x = 0.f, y = 0.f;
  12. Point() = default;
  13. Point(float _x, float _y) : x(_x), y(_y) {}
  14. bool operator==(const Point& other) const {
  15. return !memcmp(this, &other, sizeof(*this));
  16. }
  17. };
  18. struct Dimension {
  19. float width = 0.f, height = 0.f;
  20. Dimension() = default;
  21. Dimension(float w, float h) : width(w), height(h) {}
  22. bool operator==(const Dimension& other) const {
  23. return !memcmp(this, &other, sizeof(*this));
  24. }
  25. };
  26. struct Material {
  27. int id = -1;
  28. Material() = default;
  29. Material(int i) : id(i) {}
  30. bool operator==(const Material& other) const {
  31. return !memcmp(this, &other, sizeof(*this));
  32. }
  33. };
  34. struct RenderInfo {
  35. Point center;
  36. Material material;
  37. Dimension texture_size, object_size;
  38. Point bottom_left, bottom_right, top_right, top_left;
  39. float rotation = 0.0f; // TODO
  40. RenderInfo(Point c, Dimension sz, Material mat = {0}, Dimension tx_sz = {1.f, 1.f})
  41. : center(c)
  42. , material(mat)
  43. , texture_size(tx_sz)
  44. , object_size(sz)
  45. , bottom_left ({c.x - sz.width / 2.f, c.y - sz.height / 2.f})
  46. , bottom_right({c.x - sz.width / 2.f, c.y + sz.height / 2.f})
  47. , top_right ({c.x + sz.width / 2.f, c.y + sz.height / 2.f})
  48. , top_left ({c.x + sz.width / 2.f, c.y - sz.height / 2.f})
  49. {
  50. }
  51. RenderInfo() = default;
  52. bool operator==(const RenderInfo& other) const {
  53. return !memcmp(this, &other, sizeof(*this));
  54. }
  55. };
  56. DEFINE_ROTATE(RenderInfo, (material)(texture_size)(bottom_left)(bottom_right)(top_right)(top_left));
  57. DEFINE_ROTATE_NAME(simple_rotate, RenderInfo, (material)(texture_size)(center)(object_size));
  58. class rotate_TestSuite : public CxxTest::TestSuite {
  59. public:
  60. void test_proxy1() const {
  61. RenderInfo_rotate rdata;
  62. RenderInfo info{{5, 6}, {1, 1}};
  63. rdata.push_back(info);
  64. auto proxy = rdata.get(0);
  65. TS_ASSERT_EQUALS(info.texture_size, proxy.texture_size);
  66. TS_ASSERT_EQUALS(info.bottom_left, proxy.bottom_left);
  67. TS_ASSERT_EQUALS(info.bottom_right, proxy.bottom_right);
  68. TS_ASSERT_EQUALS(info.top_left, proxy.top_left);
  69. TS_ASSERT_EQUALS(info.top_right, proxy.top_right);
  70. }
  71. void test_proxy2() const {
  72. simple_rotate rdata;
  73. RenderInfo info{{5, 6}, {1, 1}};
  74. rdata.push_back(info);
  75. auto proxy = rdata.get(0);
  76. TS_ASSERT_EQUALS(info.texture_size, proxy.texture_size);
  77. TS_ASSERT_EQUALS(info.center, proxy.center);
  78. TS_ASSERT_EQUALS(info.object_size, proxy.object_size);
  79. }
  80. void test_datamodel_center() const {
  81. simple_rotate rdata;
  82. RenderInfo infos[3] = {{{1,2},{1,1}},{{0,3},{1,1}},{{4,3.2},{1,1}}};
  83. rdata.push_back(infos[0]);
  84. rdata.push_back(infos[1]);
  85. rdata.push_back(infos[2]);
  86. TS_ASSERT_EQUALS(rdata.get(access_t(RenderInfo, center){}), (std::vector<Point>{{1,2},{0,3},{4,3.2}}));
  87. }
  88. private:
  89. };