Skip to content
Snippets Groups Projects
Commit 9e26c3ec authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

implemented vector products for mixed arguments (complex/double)

parent 5ba64b5c
No related branches found
No related tags found
No related merge requests found
...@@ -125,8 +125,8 @@ IPixelMap *RectangularDetector::createPixelMap(size_t index) const ...@@ -125,8 +125,8 @@ IPixelMap *RectangularDetector::createPixelMap(size_t index) const
Bin1D u_bin = u_axis.getBin(u_index); Bin1D u_bin = u_axis.getBin(u_index);
Bin1D v_bin = v_axis.getBin(v_index); Bin1D v_bin = v_axis.getBin(v_index);
kvector_t corner_position = m_normal_to_detector kvector_t corner_position( m_normal_to_detector
+ (u_bin.m_lower - m_u0)*m_u_unit + (v_bin.m_lower - m_v0)*m_v_unit; + (u_bin.m_lower - m_u0)*m_u_unit + (v_bin.m_lower - m_v0)*m_v_unit );
kvector_t width = u_bin.getBinSize()*m_u_unit; kvector_t width = u_bin.getBinSize()*m_u_unit;
kvector_t height = v_bin.getBinSize()*m_v_unit; kvector_t height = v_bin.getBinSize()*m_v_unit;
return new RectPixelMap(corner_position, width, height); return new RectPixelMap(corner_position, width, height);
......
...@@ -79,29 +79,52 @@ BasicVector3D<std::complex<double>> BasicVector3D<double>::complex() const ...@@ -79,29 +79,52 @@ BasicVector3D<std::complex<double>> BasicVector3D<double>::complex() const
// Combine two vectors // Combine two vectors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
//! Returns dot product of vectors (antilinear in the first [=self] argument). //! Returns dot product of complex vectors (antilinear in the first [=self] argument).
template<> template<> template<>
complex_t BasicVector3D<complex_t>::dot(const BasicVector3D<complex_t>& v) const complex_t BasicVector3D<complex_t>::dot(const BasicVector3D<complex_t>& v) const
{ {
return std::conj(x())*v.x()+std::conj(y())*v.y()+std::conj(z())*v.z(); return std::conj(x())*v.x()+std::conj(y())*v.y()+std::conj(z())*v.z();
} }
template<> //! Returns mixed dot product of complex and double vectors (antilinear in the complex argument).
template<> template<>
complex_t BasicVector3D<complex_t>::dot(const BasicVector3D<double>& v) const
{
return std::conj( x()*v.x()+y()*v.y()+z()*v.z() );
}
//! Returns mixed dot product of double and complex vectors (linear in the complex argument).
template<> template<>
complex_t BasicVector3D<double>::dot(const BasicVector3D<complex_t>& v) const
{
return x()*v.x()+y()*v.y()+z()*v.z();
}
//! Returns dot product of double-typed vectors.
template<> template<>
double BasicVector3D<double>::dot(const BasicVector3D<double>& v) const double BasicVector3D<double>::dot(const BasicVector3D<double>& v) const
{ {
return x()*v.x()+y()*v.y()+z()*v.z(); return x()*v.x()+y()*v.y()+z()*v.z();
} }
//! Returns cross product of vectors. //! Returns cross product of double-typed vectors.
template<> template<> template<>
BasicVector3D<double> BasicVector3D<double>::cross( BasicVector3D<double> BasicVector3D<double>::cross(const BasicVector3D<double>& v) const
const BasicVector3D<double>& v) const
{ {
return BasicVector3D<double>(y()*v.z()-v.y()*z(), return BasicVector3D<double>(y()*v.z()-v.y()*z(),
z()*v.x()-v.z()*x(), z()*v.x()-v.z()*x(),
x()*v.y()-v.x()*y()); x()*v.y()-v.x()*y());
} }
//! Returns mixed cross product of double and complex vectors.
template<> template<>
BasicVector3D<complex_t> BasicVector3D<double>::cross(const BasicVector3D<complex_t>& v) const
{
return BasicVector3D<complex_t>(y()*v.z()-v.y()*z(),
z()*v.x()-v.z()*x(),
x()*v.y()-v.x()*y());
}
//! Returns angle with respect to another vector. //! Returns angle with respect to another vector.
template<> template<>
double BasicVector3D<double>::angle(const BasicVector3D<double>& v) const double BasicVector3D<double>::angle(const BasicVector3D<double>& v) const
......
...@@ -90,11 +90,13 @@ public: ...@@ -90,11 +90,13 @@ public:
{ v_[0] -= v.v_[0]; v_[1] -= v.v_[1]; v_[2] -= v.v_[2]; return *this; } { v_[0] -= v.v_[0]; v_[1] -= v.v_[1]; v_[2] -= v.v_[2]; return *this; }
//! Multiplies this with a scalar, and returns result. //! Multiplies this with a scalar, and returns result.
inline BasicVector3D<T>& operator*=(double a) template<class U>
inline auto operator*=(U a) -> BasicVector3D<decltype(this->x()*a)>&
{ v_[0] *= a; v_[1] *= a; v_[2] *= a; return *this; } { v_[0] *= a; v_[1] *= a; v_[2] *= a; return *this; }
//! Divides this by a scalar, and returns result. //! Divides this by a scalar, and returns result.
inline BasicVector3D<T>& operator/=(double a) template<class U>
inline auto operator/=(U a) -> BasicVector3D<decltype(this->x()*a)>&
{ v_[0] /= a; v_[1] /= a; v_[2] /= a; return *this; } { v_[0] /= a; v_[1] /= a; v_[2] /= a; return *this; }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -144,10 +146,12 @@ public: ...@@ -144,10 +146,12 @@ public:
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
//! Returns dot product of vectors (antilinear in the first [=self] argument). //! Returns dot product of vectors (antilinear in the first [=self] argument).
T dot(const BasicVector3D<T>& v) const; template<class U>
auto dot(const BasicVector3D<U>& v) const -> decltype(this->x()*v.x());
//! Returns cross product of vectors. //! Returns cross product of vectors.
BasicVector3D<T> cross(const BasicVector3D<T>& v ) const; template<class U>
auto cross(const BasicVector3D<U>& v) const -> BasicVector3D<decltype(this->x()*v.x())>;
//! Returns angle with respect to another vector. //! Returns angle with respect to another vector.
double angle(const BasicVector3D<T>& v) const; double angle(const BasicVector3D<T>& v) const;
...@@ -217,14 +221,14 @@ inline BasicVector3D<T> operator-(const BasicVector3D<T>& a, const BasicVector3D ...@@ -217,14 +221,14 @@ inline BasicVector3D<T> operator-(const BasicVector3D<T>& a, const BasicVector3D
//! Multiplication vector by scalar. //! Multiplication vector by scalar.
//! @relates BasicVector3D //! @relates BasicVector3D
template <class T, class U> template <class T, class U>
inline BasicVector3D<T> operator* (const BasicVector3D<T>& v, U a) inline auto operator* (const BasicVector3D<T>& v, const U a) -> BasicVector3D<decltype(v.x()*a)>
{ return BasicVector3D<T>(v.x()*a, v.y()*a, v.z()*a); } { return BasicVector3D<decltype(v.x()*a)>(v.x()*a, v.y()*a, v.z()*a); }
//! Multiplication scalar by vector. //! Multiplication scalar by vector.
//! @relates BasicVector3D //! @relates BasicVector3D
template <class T, class U> template <class T, class U>
inline BasicVector3D<T> operator* (U a, const BasicVector3D<T>& v) inline auto operator* (const U a, const BasicVector3D<T>& v) -> BasicVector3D<decltype(a*v.x())>
{ return BasicVector3D<T>(a*v.x(), a*v.y(), a*v.z()); } { return BasicVector3D<decltype(a*v.x())>(a*v.x(), a*v.y(), a*v.z()); }
// vector*vector not supported // vector*vector not supported
// (We do not provide the operator form a*b of the dot product: // (We do not provide the operator form a*b of the dot product:
...@@ -262,13 +266,13 @@ BA_CORE_API_ BasicVector3D<double> vecOfLambdaAlphaPhi(const double _lambda, con ...@@ -262,13 +266,13 @@ BA_CORE_API_ BasicVector3D<double> vecOfLambdaAlphaPhi(const double _lambda, con
// ?? for API generation ?? // ?? for API generation ??
// ============================================================================= // =============================================================================
template<> BA_CORE_API_ std::complex<double> BasicVector3D<std::complex<double> >::dot( template<> template<> BA_CORE_API_ std::complex<double> BasicVector3D<std::complex<double> >::dot(
const BasicVector3D<std::complex<double> >& v) const; const BasicVector3D<std::complex<double> >& v) const;
template<> BA_CORE_API_ double BasicVector3D<double>::dot( template<> template<> BA_CORE_API_ double BasicVector3D<double>::dot(
const BasicVector3D<double>& v) const; const BasicVector3D<double>& v) const;
template<> BA_CORE_API_ BasicVector3D<double> BasicVector3D<double>::cross( template<> template<> BA_CORE_API_ BasicVector3D<double> BasicVector3D<double>::cross(
const BasicVector3D<double>& v) const; const BasicVector3D<double>& v) const;
template<> BA_CORE_API_ double BasicVector3D<double>::phi() const; template<> BA_CORE_API_ double BasicVector3D<double>::phi() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment