From bf87d4d1c0e79133a494d5e73d1a74a9ff897d32 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 7 Sep 2013 15:53:10 +0200 Subject: [PATCH] Add distSqTo to CAIVector --- .../server/src/ai_service/ai_pos_mirror_inline.h | 15 +++++++++++++++ .../server/src/ai_service/ai_vector_mirror.h | 3 +++ code/ryzom/server/src/ai_share/ai_vector.h | 1 + 3 files changed, 19 insertions(+) diff --git a/code/ryzom/server/src/ai_service/ai_pos_mirror_inline.h b/code/ryzom/server/src/ai_service/ai_pos_mirror_inline.h index b75c54f1a..4185adafa 100644 --- a/code/ryzom/server/src/ai_service/ai_pos_mirror_inline.h +++ b/code/ryzom/server/src/ai_service/ai_pos_mirror_inline.h @@ -155,6 +155,11 @@ inline double CAIVectorMirror::distTo(const CAIPos &dest) const 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 { 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(); } +inline double CAIVectorMirror::distSqTo(const CAIVector &dest) const +{ + return (dest-CAIVector(*this)).sqrnorm(); +} + inline double CAIVectorMirror::quickDistTo(const CAIVector &dest) const { 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(); } +inline double CAIVectorMirror::distSqTo(const CAIVectorMirror &dest) const +{ + return (dest-*this).sqrnorm(); +} + 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); diff --git a/code/ryzom/server/src/ai_service/ai_vector_mirror.h b/code/ryzom/server/src/ai_service/ai_vector_mirror.h index dc03305bc..0464de4fb 100644 --- a/code/ryzom/server/src/ai_service/ai_vector_mirror.h +++ b/code/ryzom/server/src/ai_service/ai_vector_mirror.h @@ -83,14 +83,17 @@ public: // Methods. // a few handy utility methods inline CAngle angleTo(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 CAngle angleTo(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 CAngle angleTo(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; protected: diff --git a/code/ryzom/server/src/ai_share/ai_vector.h b/code/ryzom/server/src/ai_share/ai_vector.h index 34a82bb82..8c818b70a 100644 --- a/code/ryzom/server/src/ai_share/ai_vector.h +++ b/code/ryzom/server/src/ai_share/ai_vector.h @@ -130,6 +130,7 @@ public: // Methods. template CAngle angleTo(const V &v) const { return CAngle(atan2((v.y()-y()).asDouble(), (v.x()-x()).asDouble())); } template double distTo(const V &v) const { return (*this-v).norm(); } + template double distSqTo(const V &v) const { return (*this-v).sqrnorm(); } template double quickDistTo(const V &v) const { double dx=fabs((v.x()-x()).asDouble()), dy=fabs((v.y()-y()).asDouble()); return (dx>dy)? (dx+dy/2): (dy+dx/2); }