Add distSqTo to CAIVector

This commit is contained in:
kaetemi 2013-09-07 15:53:10 +02:00
parent 9e1ca3d1d0
commit 082ce825a5
3 changed files with 19 additions and 0 deletions

View file

@ -155,6 +155,11 @@ inline double CAIVectorMirror::distTo(const CAIPos &dest) const
return (dest-CAIVector(*this)).norm(); return (dest-CAIVector(*this)).norm();
} }
inline double CAIVectorMirror::distSqTo(const CAIPos &dest) const
{
return (dest-CAIVector(*this)).sqrnorm();
}
inline double CAIVectorMirror::quickDistTo(const CAIPos &dest) const inline double CAIVectorMirror::quickDistTo(const CAIPos &dest) const
{ {
double dx=fabs((dest.x()-x()).asDouble()), dy=fabs((dest.y()-y()).asDouble()); double dx=fabs((dest.x()-x()).asDouble()), dy=fabs((dest.y()-y()).asDouble());
@ -172,6 +177,11 @@ inline double CAIVectorMirror::distTo(const CAIVector &dest) const
return (dest-CAIVector(*this)).norm(); return (dest-CAIVector(*this)).norm();
} }
inline double CAIVectorMirror::distSqTo(const CAIVector &dest) const
{
return (dest-CAIVector(*this)).sqrnorm();
}
inline double CAIVectorMirror::quickDistTo(const CAIVector &dest) const inline double CAIVectorMirror::quickDistTo(const CAIVector &dest) const
{ {
double dx=fabs((dest.x()-x()).asDouble()), dy=fabs((dest.y()-y()).asDouble()); double dx=fabs((dest.x()-x()).asDouble()), dy=fabs((dest.y()-y()).asDouble());
@ -189,6 +199,11 @@ inline double CAIVectorMirror::distTo(const CAIVectorMirror &dest) const
return (dest-*this).norm(); return (dest-*this).norm();
} }
inline double CAIVectorMirror::distSqTo(const CAIVectorMirror &dest) const
{
return (dest-*this).sqrnorm();
}
inline double CAIVectorMirror::quickDistTo(const CAIVectorMirror &dest) const inline double CAIVectorMirror::quickDistTo(const CAIVectorMirror &dest) const
{ {
double dx=fabs((dest.x()-x()).asDouble()), dy=fabs((dest.y()-y()).asDouble()); return (dx>dy)? (dx+dy/2): (dy+dx/2); double dx=fabs((dest.x()-x()).asDouble()), dy=fabs((dest.y()-y()).asDouble()); return (dx>dy)? (dx+dy/2): (dy+dx/2);

View file

@ -83,14 +83,17 @@ public: // Methods.
// a few handy utility methods // a few handy utility methods
inline CAngle angleTo(const CAIPos &dest) const; inline CAngle angleTo(const CAIPos &dest) const;
inline double distTo(const CAIPos &dest) const; inline double distTo(const CAIPos &dest) const;
inline double distSqTo(const CAIPos &dest) const;
inline double quickDistTo(const CAIPos &dest) const; inline double quickDistTo(const CAIPos &dest) const;
inline CAngle angleTo(const CAIVector &dest) const; inline CAngle angleTo(const CAIVector &dest) const;
inline double distTo(const CAIVector &dest) const; inline double distTo(const CAIVector &dest) const;
inline double distSqTo(const CAIVector &dest) const;
inline double quickDistTo(const CAIVector &dest) const; inline double quickDistTo(const CAIVector &dest) const;
inline CAngle angleTo(const CAIVectorMirror &dest) const; inline CAngle angleTo(const CAIVectorMirror &dest) const;
inline double distTo(const CAIVectorMirror &dest) const; inline double distTo(const CAIVectorMirror &dest) const;
inline double distSqTo(const CAIVectorMirror &dest) const;
inline double quickDistTo(const CAIVectorMirror &dest) const; inline double quickDistTo(const CAIVectorMirror &dest) const;
protected: protected:

View file

@ -130,6 +130,7 @@ public: // Methods.
template <class V> CAngle angleTo(const V &v) const { return CAngle(atan2((v.y()-y()).asDouble(), template <class V> CAngle angleTo(const V &v) const { return CAngle(atan2((v.y()-y()).asDouble(),
(v.x()-x()).asDouble())); } (v.x()-x()).asDouble())); }
template <class V> double distTo(const V &v) const { return (*this-v).norm(); } template <class V> double distTo(const V &v) const { return (*this-v).norm(); }
template <class V> double distSqTo(const V &v) const { return (*this-v).sqrnorm(); }
template <class V> double quickDistTo(const V &v) const { double dx=fabs((v.x()-x()).asDouble()), template <class V> double quickDistTo(const V &v) const { double dx=fabs((v.x()-x()).asDouble()),
dy=fabs((v.y()-y()).asDouble()); dy=fabs((v.y()-y()).asDouble());
return (dx>dy)? (dx+dy/2): (dy+dx/2); } return (dx>dy)? (dx+dy/2): (dy+dx/2); }