1// Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
2
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifdef BOOST_QVM_TEST_SINGLE_HEADER
7# include BOOST_QVM_TEST_SINGLE_HEADER
8#else
9# include <boost/qvm/deduce_scalar.hpp>
10# include <boost/qvm/quat.hpp>
11# include <boost/qvm/quat_operations.hpp>
12# include <boost/qvm/vec.hpp>
13# include <boost/qvm/quat_vec_operations.hpp>
14#endif
15
16#include <boost/core/lightweight_test.hpp>
17
18template <class T>
19struct
20wrap
21 {
22 T t;
23 wrap() { }
24 wrap(T t):t(t) { }
25 };
26
27template <class S, class T>
28wrap<T>
29operator*(S s, wrap<T> w)
30 {
31 return wrap<T>(s * w.t);
32 }
33
34template <class T>
35wrap<T> operator+(wrap<T> a, wrap<T> b)
36 {
37 return wrap<T>(a.t + b.t);
38 }
39
40namespace
41boost
42 {
43 namespace
44 qvm
45 {
46 template <class T>
47 struct
48 is_scalar<wrap<T> >
49 {
50 static bool const value=true;
51 };
52 template <class S, class T>
53 struct
54 deduce_scalar<S, wrap<T> >
55 {
56 typedef wrap<typename deduce_scalar<S, T>::type> type;
57 };
58 }
59 }
60
61int
62main()
63 {
64 using namespace boost::qvm;
65 quat<double> q = rotz_quat(angle: 3.14159);
66 vec<wrap<double>, 3> v;
67 v.a[0] = wrap<double>(1.0);
68 v.a[1] = wrap<double>(0);
69 v.a[2] = wrap<double>(0);
70 vec<wrap<double>, 3> r = q * v;
71 BOOST_TEST_LT(fabs(r.a[0].t+1), 0.0001);
72 BOOST_TEST_LT(fabs(r.a[1].t), 0.0001);
73 BOOST_TEST_LT(fabs(r.a[2].t), 0.0001);
74 return boost::report_errors();
75 }
76

source code of boost/libs/qvm/test/deduce_scalar_mq_test.cpp