Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-10-12 11:14:22 +0000
committerStijn Buys <ingar@osirion.org>2008-10-12 11:14:22 +0000
commit18383a5fc596bf9546f14d7393ee66c57720b116 (patch)
tree5382c3b380a72149eabbc4f75a2c5744b895e48a /src/math/vector2f.h
parent0d831968949b1119db48530a86c2d1651c6cbfc6 (diff)
libmath API cleanup
Diffstat (limited to 'src/math/vector2f.h')
-rw-r--r--src/math/vector2f.h84
1 files changed, 58 insertions, 26 deletions
diff --git a/src/math/vector2f.h b/src/math/vector2f.h
index 87f61a8..6029b3c 100644
--- a/src/math/vector2f.h
+++ b/src/math/vector2f.h
@@ -9,62 +9,94 @@
#include <iostream>
-namespace math {
+namespace math
+{
/// a point or vector in 2D space
-class Vector2f {
+class Vector2f
+{
public:
/// default constructor
Vector2f();
+
/// assignment constructor
- Vector2f(float const x, float const y);
+ Vector2f(const float x, const float y);
+
/// copy constructor
- Vector2f(Vector2f const &other);
-
+ Vector2f(const Vector2f &other);
+
/// assign (0,0)
void clear();
-
+
/// assignment operator
- void assign(float const x, float const y);
+ void assign(const float x, const float y);
+
/// assignment operator
- void assign(Vector2f const &other);
-
+ void assign(const Vector2f &other);
+
/// assignment operator
- Vector2f & operator=(Vector2f const &other);
-
+ Vector2f & operator=(const Vector2f &other);
+
/// vector subtraction
- Vector2f & operator-=(Vector2f const &other);
-
+ Vector2f & operator-=(const Vector2f &other);
+
/// vector sum
- Vector2f & operator+=(Vector2f const &other);
-
+ Vector2f & operator+=(const Vector2f &other);
+
/// vector subtraction
- Vector2f operator-(Vector2f const &other) const;
-
+ inline Vector2f operator+(const Vector2f &other) const {
+ Vector2f v(coord[0] + other.coord[0], coord[1]+other.coord[1]);
+ return v;
+ }
+
/// vector sum
- Vector2f operator+(Vector2f const &other) const;
-
-
+ inline Vector2f operator-(const Vector2f &other) const {
+ Vector2f v(coord[0] - other.coord[0], coord[1] - other.coord[1]);
+ return v;
+ }
+
+ /// scalar product
+ inline Vector2f operator*(const float scalar) const {
+ Vector2f v(coord[0]*scalar, coord[1]*scalar);
+ return v;
+ }
+
+ /// scalar division
+ inline Vector2f operator/(const float scalar) const {
+ Vector2f v(coord[0]/scalar, coord[1]/scalar);
+ return v;
+ }
+
/// array operator
inline float& operator[](const size_t index) {
return coord[index];
}
-
+
/// array operator
inline float operator[](const size_t index) const {
return coord[index];
}
-
+
/// a pointer to the internal data
- inline float *ptr() const { return (float *) coord; }
-
+ inline float *ptr() const {
+ return (float *) coord;
+ }
+
+ inline bool contains(const Vector2f &other) const {
+ return ((other.coord[0] >= 0) && (other.coord[1] >= 0) && (other.coord[0] <= coord[0]) && (other.coord[1] <= coord[1]));
+ }
+
+ inline bool contains(float x, float y) const {
+ return ((x >= 0) && (y >= 0) && (x <= coord[0]) && (y <= coord[1]));
+ }
+
/// x coordinate
float &x;
-
+
/// y coordinate
float &y;
-
+
private:
float coord[2];
};