vectorPositionDimension2d.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. /** This test verifies that position2d and vector2d are interchangeable,
  4. and that they can convert from dimension2d */
  5. #include "testUtils.h"
  6. using namespace irr;
  7. using namespace core;
  8. template <class DIMENSION, class VECTOR, class POSITION, class T>
  9. static bool doTest(void)
  10. {
  11. bool result = true;
  12. DIMENSION dimension((T)99.9, (T)99.9);
  13. VECTOR vector(dimension);
  14. POSITION position(vector);
  15. DIMENSION dimension2(vector);
  16. result &= (vector == position);
  17. result &= (vector == dimension); // The conversion should be explicit.
  18. result &= (dimension2 == position);
  19. result &= (position == POSITION((T)99.9, (T)99.9));
  20. assert_log(result);
  21. dimension = (T)2 * position;
  22. result &= (dimension == VECTOR(2 * (T)99.9, 2 * (T)99.9));
  23. assert_log(result);
  24. dimension /= (T)2;
  25. result &= (dimension == POSITION((T)99.9, (T)99.9));
  26. assert_log(result);
  27. dimension += vector;
  28. result &= (dimension == VECTOR(2 * (T)99.9, 2 * (T)99.9));
  29. assert_log(result);
  30. dimension -= position;
  31. result &= (dimension == POSITION((T)99.9, (T)99.9));
  32. assert_log(result);
  33. position = dimension;
  34. result &= (position == VECTOR((T)99.9, (T)99.9));
  35. assert_log(result);
  36. vector += position;
  37. result &= (vector == POSITION(2 * (T)99.9, 2 * (T)99.9));
  38. assert_log(result);
  39. vector -= position;
  40. result &= (vector == dimension);
  41. assert_log(result);
  42. position *= (T)3.5;
  43. result &= (position == VECTOR((T)3.5 * (T)99.9, (T)3.5 * (T)99.9));
  44. assert_log(result);
  45. vector += dimension;
  46. result &= (vector == VECTOR(2 * (T)99.9, 2 * (T)99.9));
  47. assert_log(result);
  48. return result;
  49. }
  50. bool vectorPositionDimension2d(void)
  51. {
  52. bool result = true;
  53. logTestString("vector,position,dimension test with s32\n\n");
  54. result &= doTest<dimension2di, vector2di, position2di, s32>();
  55. if (result)
  56. logTestString("tests passed\n\n");
  57. else
  58. logTestString("\ntests failed\n\n");
  59. logTestString("vector,position,dimension test with f32\n\n");
  60. result &= doTest<dimension2df, vector2df, position2df, f32>();
  61. if (result)
  62. logTestString("tests passed\n\n");
  63. else
  64. logTestString("\ntests failed\n\n");
  65. logTestString("vector,position,dimension test with f64\n\n");
  66. result &= doTest<dimension2d<f64>, vector2d<f64>, position2d<f64>, f64>();
  67. if (result)
  68. logTestString("tests passed\n\n");
  69. else
  70. logTestString("\ntests failed\n\n");
  71. return result;
  72. }