segment.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "simple/geom/segment.hpp"
  2. #include <cassert>
  3. #include "simple/geom/bool_algebra.hpp"
  4. using namespace simple::geom;
  5. using int2 = vector<int, 2>;
  6. using float2 = vector<float, 2>;
  7. using rect = segment<int2>;
  8. using anchored_rect = anchored_segment<int2, float2>;
  9. void Initialization()
  10. {
  11. [[maybe_unused]] rect garbage;
  12. [[maybe_unused]] anchored_rect garbage2;
  13. // default
  14. {
  15. rect r{};
  16. assert(r.position == int2{});
  17. assert(r.size == int2{});
  18. anchored_rect ar{};
  19. assert(ar.position == int2{});
  20. assert(ar.size == int2{});
  21. assert(ar.anchor == float2{});
  22. }
  23. // size
  24. {
  25. rect r{{10,10}};
  26. assert(r.position == int2{});
  27. assert(( r.size == int2{10,10} ));
  28. rect r2{r.size};
  29. assert(r2.position == int2{});
  30. assert(( r2.size == r.size ));
  31. anchored_rect ar{ {{10,10}} };
  32. assert(ar.position == int2{});
  33. assert(( ar.size == int2{10,10} ));
  34. assert(ar.anchor == float2{});
  35. anchored_rect ar2{ {ar.size} };
  36. assert(ar2.position == int2{});
  37. assert(( ar2.size == ar.size ));
  38. assert(ar2.anchor == float2{});
  39. }
  40. // size position
  41. {
  42. rect r{{10,10}, {11,11}};
  43. assert(( r.position == int2{11,11} ));
  44. assert(( r.size == int2{10,10} ));
  45. rect r2{r.size, r.position};
  46. assert(( r2.position == r.position ));
  47. assert(( r2.size == r.size ));
  48. anchored_rect ar{ {{10,10}, {11,11}} };
  49. assert(( ar.position == int2{11,11} ));
  50. assert(( ar.size == int2{10,10} ));
  51. assert(ar.anchor == float2{});
  52. anchored_rect ar2{ {ar.size, ar.position} };
  53. assert(( ar2.position == ar.position ));
  54. assert(( ar2.size == ar.size ));
  55. assert(ar2.anchor == float2{});
  56. anchored_rect ar3{ r };
  57. assert(( ar3.position == r.position ));
  58. assert(( ar3.size == r.size ));
  59. assert(ar3.anchor == float2{});
  60. }
  61. // size anchor
  62. {
  63. anchored_rect ar{ {{10,10}}, float2::one(0.5f) };
  64. assert(( ar.position == int2{} ));
  65. assert(( ar.size == int2{10,10} ));
  66. assert(ar.anchor == float2::one(0.5f));
  67. anchored_rect ar2{ {ar.size}, float2::one(0.5f) };
  68. assert(( ar2.position == int2{} ));
  69. assert(( ar2.size == ar.size ));
  70. assert(ar2.anchor == float2::one(0.5f));
  71. anchored_rect ar3{ ar.size, {}, float2::one(0.5f) };
  72. assert(( ar3.position == int2{} ));
  73. assert(( ar3.size == ar.size ));
  74. assert(ar3.anchor == float2::one(0.5f));
  75. }
  76. // size position anchor
  77. {
  78. rect r{{10,10}, {11,11}};
  79. anchored_rect ar{ {{10,10}, {11,11}}, float2::one()};
  80. anchored_rect ar2 { ar.size, ar.position, ar.anchor};
  81. assert(( ar2.position == ar.position ));
  82. assert(( ar2.size == ar.size ));
  83. assert(( ar2.anchor == ar.anchor ));
  84. anchored_rect ar3{ r, ar.anchor };
  85. assert(( ar3.position == r.position ));
  86. assert(( ar3.size == r.size ));
  87. assert(( ar3.anchor == ar.anchor ));
  88. anchored_rect ar4{ ar, float2::one(0.5f) };
  89. assert(( ar4.position == ar.position ));
  90. assert(( ar4.size == ar.size ));
  91. assert(( ar4.anchor == float2::one(0.5f) ));
  92. assert(( ar4.anchor != ar.anchor ));
  93. }
  94. }
  95. void Conversions()
  96. {
  97. //TODO
  98. auto a = anchored_rect::range{};
  99. const anchored_rect r{};
  100. a = r;
  101. }
  102. int main()
  103. {
  104. return 0;
  105. }