diff options
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/vector2f.cc | 6 | ||||
-rw-r--r-- | src/math/vector2f.h | 36 | ||||
-rw-r--r-- | src/math/vector3f.cc | 9 | ||||
-rw-r--r-- | src/math/vector3f.h | 32 |
4 files changed, 50 insertions, 33 deletions
diff --git a/src/math/vector2f.cc b/src/math/vector2f.cc index 2b5ff9e..65f1f93 100644 --- a/src/math/vector2f.cc +++ b/src/math/vector2f.cc @@ -12,17 +12,17 @@ namespace math { -Vector2f::Vector2f() : x(coord[0]), y(coord[1]) +Vector2f::Vector2f() { clear(); } -Vector2f::Vector2f(const Vector2f &other) : x(coord[0]), y(coord[1]) +Vector2f::Vector2f(const Vector2f &other) { assign(other); } -Vector2f::Vector2f(const float x, const float y) : x(coord[0]), y(coord[1]) +Vector2f::Vector2f(const float x, const float y) { assign(x, y); } diff --git a/src/math/vector2f.h b/src/math/vector2f.h index 6258d85..ba60aa1 100644 --- a/src/math/vector2f.h +++ b/src/math/vector2f.h @@ -78,6 +78,28 @@ public: return coord[index]; } + /// x coordinate + inline float width() const { + return coord[0]; + } + + /// y coordinate + inline float height() const { + return coord[1]; + } + + /// x coordinate + inline float x() const { return coord[0]; } + + /// y coordinate + inline float y() const { return coord[1]; } + + /// mutable reference to the x coordinate + inline float & get_x() { return coord[0]; } + + /// mutable reference to the y coordinate + inline float & get_y() { return coord[1]; } + /// a pointer to the internal data inline float *ptr() const { return (float *) coord; @@ -91,20 +113,6 @@ public: return ((x >= 0) && (y >= 0) && (x <= coord[0]) && (y <= coord[1])); } - inline float width() const { - return coord[0]; - } - - inline float height() const { - return coord[1]; - } - - /// x coordinate - float &x; - - /// y coordinate - float &y; - private: float coord[2]; }; diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc index 8a6dd5e..1e9fd2b 100644 --- a/src/math/vector3f.cc +++ b/src/math/vector3f.cc @@ -12,20 +12,17 @@ namespace math { -Vector3f::Vector3f() : - x(coord[0]), y(coord[1]), z(coord[2]) +Vector3f::Vector3f() { clear(); } -Vector3f::Vector3f(const Vector3f &other) : - x(coord[0]), y(coord[1]), z(coord[2]) +Vector3f::Vector3f(const Vector3f &other) { assign(other); } -Vector3f::Vector3f(const float x, const float y, const float z) : - x(coord[0]), y(coord[1]), z(coord[2]) +Vector3f::Vector3f(const float x, const float y, const float z) { assign(x, y, z); } diff --git a/src/math/vector3f.h b/src/math/vector3f.h index 82b818e..99a665f 100644 --- a/src/math/vector3f.h +++ b/src/math/vector3f.h @@ -114,6 +114,27 @@ public: return coord[index]; } + /// x coordinate + inline float x() const { return coord[0]; } + + /// y coordinate + inline float y() const { return coord[1]; } + + /// z coordinate + inline float z() const { return coord[2]; } + + /// mutable reference to the x coordinate + inline float & get_x() { return coord[0]; } + + /// mutable reference to the y coordinate + inline float & get_y() { return coord[1]; } + + /// mutable reference to the z coordinate + inline float & get_z() { return coord[2]; } + + /// a pointer to the internal data + inline float *ptr() const { return (float *) coord; } + /// cartesian length float length() const; @@ -125,11 +146,6 @@ public: /// vector must not be (0, 0, 0) void normalize(); - /// a pointer to the internal data - inline float *ptr() const { - return (float *) coord; - } - /* static functions */ /// Returns the unity vector on the X-axis @@ -158,11 +174,7 @@ public: static inline Vector3f normalized(const Vector3f & vector) { return (vector / vector.length()); } - - float &x; - float &y; - float &z; - + private: float coord[3]; }; |