From 4a6701bd3dbd29530451f728126d30edb89eaddb Mon Sep 17 00:00:00 2001 From: florianf Date: Sun, 28 Feb 2010 10:51:32 +0000 Subject: [PATCH] Rectf: Implement distance(). Calculates the distance from this rectangle to another rectangle or a vector. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6447 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/math/rectf.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/math/rectf.hpp b/src/math/rectf.hpp index f34bb43f7..f9d456593 100644 --- a/src/math/rectf.hpp +++ b/src/math/rectf.hpp @@ -20,6 +20,7 @@ #include #include "math/vector.hpp" +#include "object/anchor_point.hpp" /** This class represents a rectangle. * (Implementation Note) We're using upper left and lower right point instead of @@ -109,6 +110,20 @@ public: return true; } + float distance (const Vector& other, AnchorPoint ap = ANCHOR_MIDDLE) const + { + Vector v = get_anchor_pos (*this, ap); + return ((v - other).norm ()); + } + + float distance (const Rectf& other, AnchorPoint ap = ANCHOR_MIDDLE) const + { + Vector v1 = get_anchor_pos (*this, ap); + Vector v2 = get_anchor_pos (other, ap); + + return ((v1 - v2).norm ()); + } + // leave these two public to save the headaches of set/get functions for such // simple things :) -- 2.11.0