Skip to content
Snippets Groups Projects
Commit 91a3b33d authored by Tom Fischer's avatar Tom Fischer
Browse files

[MathLib] Vector3: Reordered methods for readability.

parent 34aba4f0
No related branches found
No related tags found
No related merge requests found
...@@ -98,30 +98,6 @@ public: ...@@ -98,30 +98,6 @@ public:
return *this; return *this;
} }
/** scalarProduct, implementation of scalar product,
* sometimes called dot or inner product.
*/
template <typename T1>
friend T1 scalarProduct(TemplateVector3<T1> const& v, TemplateVector3<T1> const& w);
/** crossProduct: implementation of cross product,
* sometimes called outer product.
*/
template <typename T1>
friend TemplateVector3<T1> crossProduct(
TemplateVector3<T1> const& v,
TemplateVector3<T1> const& w);
/** multiplication with a scalar s */
template <typename T1>
friend TemplateVector3<T1> operator*(
TemplateVector3<T1> const& v,
double s);
template <typename T1>
friend TemplateVector3<T1> operator*(
double s,
TemplateVector3<T1> const& v);
TemplateVector3& operator*=(double s) TemplateVector3& operator*=(double s)
{ {
for (std::size_t i(0); i < 3; i++) for (std::size_t i(0); i < 3; i++)
...@@ -129,6 +105,20 @@ public: ...@@ -129,6 +105,20 @@ public:
return *this; return *this;
} }
/// Comparison if equal
bool operator==(TemplateVector3 const& v) const
{
return std::fabs(this->_x[0] - v[0]) < sqrt(std::numeric_limits<double>::min()) &&
std::fabs(this->_x[1] - v[1]) < sqrt(std::numeric_limits<double>::min()) &&
std::fabs(this->_x[2] - v[2]) < sqrt(std::numeric_limits<double>::min());
}
/// Comparison if not equal
bool operator!=(const TemplateVector3 & v) const
{
return !(v == this);
}
/** /**
* After applying the normalize operator to the vector its length is 1.0. * After applying the normalize operator to the vector its length is 1.0.
*/ */
...@@ -145,19 +135,29 @@ public: ...@@ -145,19 +135,29 @@ public:
return sqrt(sqrLength()); return sqrt(sqrLength());
} }
/// Comparison if equal /** scalarProduct, implementation of scalar product,
bool operator==(TemplateVector3 const& v) const * sometimes called dot or inner product.
{ */
return std::fabs(this->_x[0] - v[0]) < sqrt(std::numeric_limits<double>::min()) && template <typename T1>
std::fabs(this->_x[1] - v[1]) < sqrt(std::numeric_limits<double>::min()) && friend T1 scalarProduct(TemplateVector3<T1> const& v, TemplateVector3<T1> const& w);
std::fabs(this->_x[2] - v[2]) < sqrt(std::numeric_limits<double>::min());
}
/// Comparison if not equal /** crossProduct: implementation of cross product,
bool operator!=(const TemplateVector3 & v) const * sometimes called outer product.
{ */
return !(v == this); template <typename T1>
} friend TemplateVector3<T1> crossProduct(
TemplateVector3<T1> const& v,
TemplateVector3<T1> const& w);
/** multiplication with a scalar s */
template <typename T1>
friend TemplateVector3<T1> operator*(
TemplateVector3<T1> const& v,
double s);
template <typename T1>
friend TemplateVector3<T1> operator*(
double s,
TemplateVector3<T1> const& v);
private: private:
/// Returns the squared length /// Returns the squared length
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment