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

[MathLib] For readability: Vector::length() -> Vector3::getLength().

parent f78a141f
No related branches found
No related tags found
No related merge requests found
...@@ -58,10 +58,10 @@ Orientation getOrientation(const GeoLib::Point* p0, const GeoLib::Point* p1, ...@@ -58,10 +58,10 @@ Orientation getOrientation(const GeoLib::Point* p0, const GeoLib::Point* p1,
bool parallel(MathLib::Vector3 v, MathLib::Vector3 w) bool parallel(MathLib::Vector3 v, MathLib::Vector3 w)
{ {
// check degenerated cases // check degenerated cases
if (v.length() < std::numeric_limits<double>::min()) if (v.getLength() < std::numeric_limits<double>::min())
return false; return false;
if (w.length() < std::numeric_limits<double>::min()) if (w.getLength() < std::numeric_limits<double>::min())
return false; return false;
v.normalize(); v.normalize();
...@@ -269,7 +269,7 @@ void getNewellPlane(const std::vector<GeoLib::Point*>& pnts, MathLib::Vector3 &p ...@@ -269,7 +269,7 @@ void getNewellPlane(const std::vector<GeoLib::Point*>& pnts, MathLib::Vector3 &p
centroid += *(pnts[j]); centroid += *(pnts[j]);
} }
plane_normal *= 1.0 / plane_normal.length(); plane_normal *= 1.0 / plane_normal.getLength();
d = MathLib::scalarProduct(centroid, plane_normal) / n_pnts; d = MathLib::scalarProduct(centroid, plane_normal) / n_pnts;
} }
......
...@@ -124,15 +124,21 @@ public: ...@@ -124,15 +124,21 @@ public:
*/ */
void normalize() void normalize()
{ {
const double s(1/length()); const double s(1/getLength());
for (std::size_t i(0); i < 3; i++) for (std::size_t i(0); i < 3; i++)
this->_x[i] *= s; this->_x[i] *= s;
} }
/// Returns the squared length
double getSqrLength(void) const
{
return this->_x[0]*this->_x[0] + this->_x[1]*this->_x[1] + this->_x[2]*this->_x[2];
}
/// Returns the length /// Returns the length
double length(void) const double getLength(void) const
{ {
return sqrt(sqrLength()); return sqrt(getSqrLength());
} }
/** scalarProduct, implementation of scalar product, /** scalarProduct, implementation of scalar product,
...@@ -158,13 +164,6 @@ public: ...@@ -158,13 +164,6 @@ public:
friend TemplateVector3<T1> operator*( friend TemplateVector3<T1> operator*(
double s, double s,
TemplateVector3<T1> const& v); TemplateVector3<T1> const& v);
private:
/// Returns the squared length
double sqrLength(void) const
{
return this->_x[0]*this->_x[0] + this->_x[1]*this->_x[1] + this->_x[2]*this->_x[2];
}
}; };
template <typename T> template <typename T>
......
...@@ -158,7 +158,7 @@ TEST(MathLib, TestVector3Multiplications) ...@@ -158,7 +158,7 @@ TEST(MathLib, TestVector3Multiplications)
// test normalisation // test normalisation
v.normalize(); v.normalize();
ASSERT_NEAR(1.0, v.length(), std::numeric_limits<double>::epsilon()); ASSERT_NEAR(1.0, v.getLength(), std::numeric_limits<double>::epsilon());
} }
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