Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-12-20 14:53:40 +0000
committerStijn Buys <ingar@osirion.org>2008-12-20 14:53:40 +0000
commit34747fcb6a29ee573cf432611359ef34fe680dec (patch)
tree1bcdec89de2dab0132f09a57a8881ec70a9f4270 /src
parentbf5e410cb8c041aa6e55fe9e9c38b79d30ee14ec (diff)
added Vector2f distance functions
Diffstat (limited to 'src')
-rw-r--r--src/math/vector2f.cc17
-rw-r--r--src/math/vector2f.h6
2 files changed, 23 insertions, 0 deletions
diff --git a/src/math/vector2f.cc b/src/math/vector2f.cc
index 809269e..2b5ff9e 100644
--- a/src/math/vector2f.cc
+++ b/src/math/vector2f.cc
@@ -63,4 +63,21 @@ Vector2f &Vector2f::operator-=(const Vector2f &other)
return (*this);
}
+float distance(const Vector2f& first, const Vector2f& second)
+{
+ float r = 0;
+ for (int i=0; i < 2; i++)
+ r += (first[i]-second[i])*(first[i]-second[i]);
+
+ return (sqrtf(r));
+}
+
+float distancesquared(const Vector2f& first, const Vector2f& second)
+{
+ float r = 0;
+ for (int i=0; i < 2; i++)
+ r += (first[i]-second[i])*(first[i]-second[i]);
+ return (r);
+}
+
}
diff --git a/src/math/vector2f.h b/src/math/vector2f.h
index ee2d044..6258d85 100644
--- a/src/math/vector2f.h
+++ b/src/math/vector2f.h
@@ -109,6 +109,12 @@ private:
float coord[2];
};
+/// distance between two vectors
+float distance(const Vector2f& first, const Vector2f& second);
+
+/// distance between two vectors squared
+float distancesquared(const Vector2f& first, const Vector2f& second);
+
}
#endif // __INCLUDED_MATH_VECTOR2F_H__