normalize_v_test.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/vec_operations.hpp>
  5. #include "test_qvm_vector.hpp"
  6. #include "gold.hpp"
  7. namespace
  8. {
  9. template <class T,class U> struct same_type_tester;
  10. template <class T> struct same_type_tester<T,T> { };
  11. template <class T,class U> void test_same_type( T, U ) { same_type_tester<T,U>(); }
  12. template <int Dim>
  13. void
  14. test()
  15. {
  16. using namespace boost::qvm::sfinae;
  17. {
  18. test_qvm::vector<V1,Dim> const x(42,1);
  19. test_same_type(x,normalized(x));
  20. test_qvm::vector<V1,Dim> 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::vector<V1,Dim> x(42,1);
  27. float m=sqrtf(test_qvm::dot<float>(x.a,x.a));
  28. test_qvm::scalar_multiply_v(x.b,x.a,1/m);
  29. normalize(x);
  30. BOOST_QVM_TEST_CLOSE(x.a,x.b,0.000001f);
  31. }
  32. }
  33. }
  34. int
  35. main()
  36. {
  37. test<2>();
  38. test<3>();
  39. test<4>();
  40. test<5>();
  41. return boost::report_errors();
  42. }