Commit 3e505614 authored by Andrew Heather's avatar Andrew Heather Committed by Mattijs Janssens
Browse files

ENH: Vector2D - added isClose function

parent b8768e28
......@@ -116,13 +116,18 @@ public:
//- Access to the vector y component
inline Cmpt& y();
//- Normalise the vector by its magnitude
inline Vector2D<Cmpt>& normalise();
//- Perp dot product (dot product with perpendicular vector)
inline scalar perp(const Vector2D<Cmpt>& b) const;
//- Return true if vector is within tol
inline bool isClose
(
const Vector2D<Cmpt>& b,
const scalar tol = 1e-10
) const;
};
......
......@@ -126,7 +126,18 @@ operator&(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
template<class Cmpt>
inline scalar Vector2D<Cmpt>::perp(const Vector2D<Cmpt>& b) const
{
return x()*b.y()-y()*b.x();
return x()*b.y() - y()*b.x();
}
template<class Cmpt>
inline bool Vector2D<Cmpt>::isClose
(
const Vector2D<Cmpt>& b,
const scalar tol
) const
{
return (mag(x() - b.x()) < tol && mag(y() - b.y()) < tol);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment