MathTest.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. #ifndef ASSIMP_MATH_TEST_H
  35. #define ASSIMP_MATH_TEST_H
  36. #include "UnitTestPCH.h"
  37. #include <assimp/types.h>
  38. #include "RandomNumberGeneration.h"
  39. namespace Assimp {
  40. /** Custom test class providing several math related utilities. */
  41. class AssimpMathTest : public ::testing::Test {
  42. public:
  43. /** Return a random non-null 2D vector. */
  44. inline static aiVector2D random_vec2() {
  45. return aiVector2D(RandNonZero.next(), RandNonZero.next());
  46. }
  47. /** Return a random non-null 3D vector. */
  48. inline static aiVector3D random_vec3() {
  49. return aiVector3D(RandNonZero.next(), RandNonZero.next(),RandNonZero.next());
  50. }
  51. /** Return a random unit 3D vector. */
  52. inline static aiVector3D random_unit_vec3() {
  53. return random_vec3().NormalizeSafe();
  54. }
  55. /** Return a quaternion with random orientation and
  56. * rotation angle around axis. */
  57. inline static aiQuaternion random_quat() {
  58. return aiQuaternion(random_unit_vec3(), RandPI.next());
  59. }
  60. /** Return a random non-null 3x3 matrix. */
  61. inline static aiMatrix3x3 random_mat3() {
  62. return aiMatrix3x3(
  63. RandNonZero.next(), RandNonZero.next(),RandNonZero.next(),
  64. RandNonZero.next(), RandNonZero.next(),RandNonZero.next(),
  65. RandNonZero.next(), RandNonZero.next(),RandNonZero.next());
  66. }
  67. /** Return a random non-null 4x4 matrix. */
  68. inline static aiMatrix4x4 random_mat4() {
  69. return aiMatrix4x4(
  70. RandNonZero.next(), RandNonZero.next(),RandNonZero.next(), RandNonZero.next(),
  71. RandNonZero.next(), RandNonZero.next(),RandNonZero.next(), RandNonZero.next(),
  72. RandNonZero.next(), RandNonZero.next(),RandNonZero.next(), RandNonZero.next(),
  73. RandNonZero.next(), RandNonZero.next(),RandNonZero.next(), RandNonZero.next());
  74. }
  75. /** Epsilon value to use in tests. */
  76. static const float Epsilon;
  77. /** Random number generators. */
  78. static RandomUniformFloatGenerator RandNonZero, RandPI;
  79. };
  80. }
  81. #endif // ASSIMP_MATH_TEST_H