PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmath/tests/llbboxlocal_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 232 lines | 116 code | 48 blank | 68 comment | 0 complexity | cbd412e3abeedd25da83afde3490d774 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llbboxlocal_test.cpp
  3. * @author Martin Reddy
  4. * @date 2009-06-25
  5. * @brief Test for llbboxlocal.cpp.
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "linden_common.h"
  29. #include "../test/lltut.h"
  30. #include "../llbboxlocal.h"
  31. namespace tut
  32. {
  33. struct LLBBoxLocalData
  34. {
  35. };
  36. typedef test_group<LLBBoxLocalData> factory;
  37. typedef factory::object object;
  38. }
  39. namespace
  40. {
  41. tut::factory llbboxlocal_test_factory("LLBBoxLocal");
  42. }
  43. namespace tut
  44. {
  45. template<> template<>
  46. void object::test<1>()
  47. {
  48. //
  49. // test the default constructor
  50. //
  51. LLBBoxLocal bbox1;
  52. ensure_equals("Default bbox min", bbox1.getMin(), LLVector3(0.0f, 0.0f, 0.0f));
  53. ensure_equals("Default bbox max", bbox1.getMax(), LLVector3(0.0f, 0.0f, 0.0f));
  54. }
  55. template<> template<>
  56. void object::test<2>()
  57. {
  58. //
  59. // test the non-default constructor
  60. //
  61. LLBBoxLocal bbox2(LLVector3(-1.0f, -2.0f, 0.0f), LLVector3(1.0f, 2.0f, 3.0f));
  62. ensure_equals("Custom bbox min", bbox2.getMin(), LLVector3(-1.0f, -2.0f, 0.0f));
  63. ensure_equals("Custom bbox max", bbox2.getMax(), LLVector3(1.0f, 2.0f, 3.0f));
  64. }
  65. template<> template<>
  66. void object::test<3>()
  67. {
  68. //
  69. // test the setMin()
  70. //
  71. // N.B. no validation is currently performed to ensure that the min
  72. // and max vectors are actually the min/max values.
  73. //
  74. LLBBoxLocal bbox2;
  75. bbox2.setMin(LLVector3(1.0f, 2.0f, 3.0f));
  76. ensure_equals("Custom bbox min (2)", bbox2.getMin(), LLVector3(1.0f, 2.0f, 3.0f));
  77. }
  78. template<> template<>
  79. void object::test<4>()
  80. {
  81. //
  82. // test the setMax()
  83. //
  84. // N.B. no validation is currently performed to ensure that the min
  85. // and max vectors are actually the min/max values.
  86. //
  87. LLBBoxLocal bbox2;
  88. bbox2.setMax(LLVector3(10.0f, 20.0f, 30.0f));
  89. ensure_equals("Custom bbox max (2)", bbox2.getMax(), LLVector3(10.0f, 20.0f, 30.0f));
  90. }
  91. template<> template<>
  92. void object::test<5>()
  93. {
  94. //
  95. // test the getCenter() method
  96. //
  97. ensure_equals("Default bbox center", LLBBoxLocal().getCenter(), LLVector3(0.0f, 0.0f, 0.0f));
  98. LLBBoxLocal bbox1(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(0.0f, 0.0f, 0.0f));
  99. ensure_equals("Custom bbox center", bbox1.getCenter(), LLVector3(-0.5f, -0.5f, -0.5f));
  100. LLBBoxLocal bbox2(LLVector3(0.0f, 0.0f, 0.0f), LLVector3(-1.0f, -1.0f, -1.0f));
  101. ensure_equals("Invalid bbox center", bbox2.getCenter(), LLVector3(-0.5f, -0.5f, -0.5f));
  102. }
  103. template<> template<>
  104. void object::test<6>()
  105. {
  106. //
  107. // test the getExtent() method
  108. //
  109. LLBBoxLocal bbox2(LLVector3(0.0f, 0.0f, 0.0f), LLVector3(-1.0f, -1.0f, -1.0f));
  110. ensure_equals("Default bbox extent", LLBBoxLocal().getExtent(), LLVector3(0.0f, 0.0f, 0.0f));
  111. LLBBoxLocal bbox3(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(1.0f, 2.0f, 0.0f));
  112. ensure_equals("Custom bbox extent", bbox3.getExtent(), LLVector3(2.0f, 3.0f, 1.0f));
  113. }
  114. template<> template<>
  115. void object::test<7>()
  116. {
  117. //
  118. // test the addPoint() method
  119. //
  120. // N.B. if you create an empty bbox and then add points,
  121. // the vector (0, 0, 0) will always be part of the bbox.
  122. // (Fixing this would require adding a bool to the class size).
  123. //
  124. LLBBoxLocal bbox1;
  125. bbox1.addPoint(LLVector3(-1.0f, -2.0f, -3.0f));
  126. bbox1.addPoint(LLVector3(3.0f, 4.0f, 5.0f));
  127. ensure_equals("Custom BBox center (1)", bbox1.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
  128. ensure_equals("Custom BBox min (1)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
  129. ensure_equals("Custom BBox max (1)", bbox1.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
  130. bbox1.addPoint(LLVector3(0.0f, 0.0f, 0.0f));
  131. bbox1.addPoint(LLVector3(1.0f, 2.0f, 3.0f));
  132. bbox1.addPoint(LLVector3(2.0f, 2.0f, 2.0f));
  133. ensure_equals("Custom BBox center (2)", bbox1.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
  134. ensure_equals("Custom BBox min (2)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
  135. ensure_equals("Custom BBox max (2)", bbox1.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
  136. bbox1.addPoint(LLVector3(5.0f, 5.0f, 5.0f));
  137. ensure_equals("Custom BBox center (3)", bbox1.getCenter(), LLVector3(2.0f, 1.5f, 1.0f));
  138. ensure_equals("Custom BBox min (3)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
  139. ensure_equals("Custom BBox max (3)", bbox1.getMax(), LLVector3(5.0f, 5.0f, 5.0f));
  140. }
  141. template<> template<>
  142. void object::test<8>()
  143. {
  144. //
  145. // test the addBBox() methods
  146. //
  147. // N.B. if you create an empty bbox and then add points,
  148. // the vector (0, 0, 0) will always be part of the bbox.
  149. // (Fixing this would require adding a bool to the class size).
  150. //
  151. LLBBoxLocal bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLVector3(2.0f, 2.0f, 2.0f));
  152. bbox2.addBBox(LLBBoxLocal(LLVector3(1.5f, 1.5f, 1.5f), LLVector3(3.0f, 3.0f, 3.0f)));
  153. ensure_equals("Custom BBox center (4)", bbox2.getCenter(), LLVector3(2.0f, 2.0f, 2.0f));
  154. ensure_equals("Custom BBox min (4)", bbox2.getMin(), LLVector3(1.0f, 1.0f, 1.0f));
  155. ensure_equals("Custom BBox max (4)", bbox2.getMax(), LLVector3(3.0f, 3.0f, 3.0f));
  156. bbox2.addBBox(LLBBoxLocal(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(0.0f, 0.0f, 0.0f)));
  157. ensure_equals("Custom BBox center (5)", bbox2.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
  158. ensure_equals("Custom BBox min (5)", bbox2.getMin(), LLVector3(-1.0f, -1.0f, -1.0f));
  159. ensure_equals("Custom BBox max (5)", bbox2.getMax(), LLVector3(3.0f, 3.0f, 3.0f));
  160. }
  161. template<> template<>
  162. void object::test<9>()
  163. {
  164. //
  165. // test the expand() method
  166. //
  167. LLBBoxLocal bbox1;
  168. bbox1.expand(0.0f);
  169. ensure_equals("Zero-expanded Default BBox center", bbox1.getCenter(), LLVector3(0.0f, 0.0f, 0.0f));
  170. LLBBoxLocal bbox2(LLVector3(1.0f, 2.0f, 3.0f), LLVector3(3.0f, 4.0f, 5.0f));
  171. bbox2.expand(0.0f);
  172. ensure_equals("Zero-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
  173. ensure_equals("Zero-expanded BBox min", bbox2.getMin(), LLVector3(1.0f, 2.0f, 3.0f));
  174. ensure_equals("Zero-expanded BBox max", bbox2.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
  175. bbox2.expand(0.5f);
  176. ensure_equals("Positive-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
  177. ensure_equals("Positive-expanded BBox min", bbox2.getMin(), LLVector3(0.5f, 1.5f, 2.5f));
  178. ensure_equals("Positive-expanded BBox max", bbox2.getMax(), LLVector3(3.5f, 4.5f, 5.5f));
  179. bbox2.expand(-1.0f);
  180. ensure_equals("Negative-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
  181. ensure_equals("Negative-expanded BBox min", bbox2.getMin(), LLVector3(1.5f, 2.5f, 3.5f));
  182. ensure_equals("Negative-expanded BBox max", bbox2.getMax(), LLVector3(2.5f, 3.5f, 4.5f));
  183. }
  184. }