normalize_q_test.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/qvm/quat_operations.hpp>
  5. #include <boost/qvm/quat.hpp>
  6. #include "test_qvm_quaternion.hpp"
  7. #include "gold.hpp"
  8. namespace
  9. {
  10. template <class T,class U> struct same_type_tester;
  11. template <class T> struct same_type_tester<T,T> { };
  12. template <class T,class U> void test_same_type( T, U ) { same_type_tester<T,U>(); }
  13. void
  14. test()
  15. {
  16. using namespace boost::qvm::sfinae;
  17. {
  18. test_qvm::quaternion<Q1> const x(42,1);
  19. test_same_type(x,normalized(x));
  20. test_qvm::quaternion<Q1> y=normalized(x);
  21. float m=sqrtf(test_qvm::dot<float>(x.a,x.a));
  22. test_qvm::scalar_multiply_v(y.b,x.a,1/m);
  23. BOOST_QVM_TEST_CLOSE(y.a,y.b,0.000001f);
  24. }
  25. {
  26. test_qvm::quaternion<Q1> const x(42,1);
  27. test_qvm::quaternion<Q1> y=normalized(qref(x));
  28. float m=sqrtf(test_qvm::dot<float>(x.a,x.a));
  29. test_qvm::scalar_multiply_v(y.b,x.a,1/m);
  30. BOOST_QVM_TEST_CLOSE(y.a,y.b,0.000001f);
  31. }
  32. {
  33. test_qvm::quaternion<Q1> x(42,1);
  34. float m=sqrtf(test_qvm::dot<float>(x.a,x.a));
  35. test_qvm::scalar_multiply_v(x.b,x.a,1/m);
  36. normalize(x);
  37. BOOST_QVM_TEST_CLOSE(x.a,x.b,0.000001f);
  38. }
  39. }
  40. }
  41. int
  42. main()
  43. {
  44. test();
  45. return boost::report_errors();
  46. }