conjugate.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef conjugate_h
00014 #define conjugate_h
00015
00016 #include <cml/quaternion/quaternion_expr.h>
00017
00018 namespace cml {
00019 namespace et {
00020
00022 template<class ExprT>
00023 class ConjugateOp
00024 {
00025 public:
00026
00027 typedef ConjugateOp<ExprT> expr_type;
00028
00029
00030 typedef unary_expression expr_ary;
00031
00032
00033 typedef expr_type expr_const_reference;
00034
00035 typedef typename ExprT::value_type value_type;
00036 typedef quaternion_result_tag result_tag;
00037 typedef typename ExprT::size_tag size_tag;
00038
00039
00040 typedef ExprTraits<ExprT> expr_traits;
00041
00042
00043 typedef typename expr_traits::const_reference expr_reference;
00044
00045
00046 typedef typename expr_traits::result_type result_type;
00047
00048
00049 typedef cml::et::not_assignable_tag assignable_tag;
00050
00051
00052 typedef typename result_type::temporary_type temporary_type;
00053
00054
00055 typedef typename result_type::vector_type vector_type;
00056
00057
00058 typedef typename vector_type::subvector_type imaginary_type;
00059
00060
00061 typedef typename result_type::order_type order_type;
00062
00063
00064 public:
00065
00067 enum { array_size = ExprT::array_size };
00068
00070 enum {
00071 W = order_type::W,
00072 X = order_type::X,
00073 Y = order_type::Y,
00074 Z = order_type::Z
00075 };
00076
00077
00078 public:
00079
00081 value_type real() const {
00082 return m_expr.real();
00083 }
00084
00086 imaginary_type imaginary() const {
00087 return -m_expr.imaginary();
00088 }
00089
00091 value_type norm() const {
00092 return length_squared();
00093 }
00094
00096 value_type length_squared() const {
00097 return dot(
00098 QuaternionXpr<expr_type>(*this),
00099 QuaternionXpr<expr_type>(*this));
00100 }
00101
00103 value_type length() const {
00104 return std::sqrt(length_squared());
00105 }
00106
00108 temporary_type normalize() const {
00109 temporary_type q(QuaternionXpr<expr_type>(*this));
00110 return q.normalize();
00111 }
00112
00117 value_type operator[](size_t i) const {
00118 return (i == W) ? m_expr[W] : - m_expr[i] ;
00119 }
00120
00121
00122 public:
00123
00125 size_t size() const {
00126 return m_expr.size();
00127 }
00128
00130 expr_reference expression() const { return m_expr; }
00131
00132
00133 public:
00134
00136 explicit ConjugateOp(expr_reference expr) : m_expr(expr) {}
00137
00139 ConjugateOp(const expr_type& e) : m_expr(e.m_expr) {}
00140
00141
00142 protected:
00143
00144 expr_reference m_expr;
00145
00146
00147 private:
00148
00149
00150 expr_type& operator=(const expr_type&);
00151 };
00152
00154 template<class ExprT>
00155 struct ExprTraits< ConjugateOp<ExprT> >
00156 {
00157 typedef ConjugateOp<ExprT> expr_type;
00158 typedef ExprT arg_type;
00159
00160 typedef typename expr_type::value_type value_type;
00161 typedef typename expr_type::expr_const_reference const_reference;
00162 typedef typename expr_type::result_tag result_tag;
00163 typedef typename expr_type::size_tag size_tag;
00164 typedef typename expr_type::result_type result_type;
00165 typedef typename expr_type::assignable_tag assignable_tag;
00166 typedef expr_node_tag node_tag;
00167
00168 value_type get(const expr_type& v, size_t i) const { return v[i]; }
00169 size_t size(const expr_type& e) const { return e.size(); }
00170 };
00171
00172 }
00173
00175 template<typename E, class AT, class OT, class CT> inline
00176 et::QuaternionXpr< et::ConjugateOp< quaternion<E,AT,OT,CT> > >
00177 conjugate(const quaternion<E,AT,OT,CT>& arg)
00178 {
00179 typedef et::ConjugateOp< quaternion<E,AT,OT,CT> > ExprT;
00180 return et::QuaternionXpr<ExprT>(ExprT(arg));
00181 }
00182
00184 template<class XprT> inline
00185 et::QuaternionXpr< et::ConjugateOp<XprT> >
00186 conjugate(QUATXPR_ARG_TYPE arg)
00187 {
00188 typedef et::ConjugateOp<XprT> ExprT;
00189 return et::QuaternionXpr<ExprT>(ExprT(arg.expression()));
00190 }
00191
00192 }
00193
00194 #endif
00195
00196
00197