diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-05-19 20:08:23 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-05-19 20:08:23 +0100 |
commit | 3308d13ad04fac43e7a111b299ff9444aea4ab9f (patch) | |
tree | 54a91113f75e506318101acf3151d3b11d309e96 /include/YAGE/Math | |
parent | e15b2c6dd405d008d9e892608c209fd980bcd8ff (diff) | |
download | YAGE-3308d13ad04fac43e7a111b299ff9444aea4ab9f.tar.gz YAGE-3308d13ad04fac43e7a111b299ff9444aea4ab9f.zip |
Adding math to yage
Diffstat (limited to 'include/YAGE/Math')
-rw-r--r-- | include/YAGE/Math/vector.hpp | 133 | ||||
-rw-r--r-- | include/YAGE/Math/vector2d.hpp | 20 |
2 files changed, 153 insertions, 0 deletions
diff --git a/include/YAGE/Math/vector.hpp b/include/YAGE/Math/vector.hpp new file mode 100644 index 00000000..39553a49 --- /dev/null +++ b/include/YAGE/Math/vector.hpp @@ -0,0 +1,133 @@ +#ifndef YAGE_MATH_VECTOR_HPP +#define YAGE_MATH_VECTOR_HPP + +#include <vector> + +namespace yage +{ + +class Vector +{ +protected: + std::vector<long double> members_; + +public: + Vector()=delete; + virtual ~Vector(); + + inline long double &operator[](std::size_t index) + { + return members_[index]; + } + + inline const long double &operator[](std::size_t index) const + { + return members_[index]; + } + + inline Vector &operator+() + { + return *this; + } + + inline Vector &operator-() + { + for(auto &i : members_) + { + i=-i; + } + return *this; + } + + inline Vector &operator+=(const Vector &other) + { + for(std::size_t i=0; i<members_.size(); ++i) + { + members_[i]+=other[i]; + } + return *this; + } + + inline Vector &operator-=(const Vector &other) + { + for(std::size_t i=0; i<members_.size(); ++i) + { + members_[i]-=other[i]; + } + return *this; + } + + inline Vector &operator*=(const Vector &other) + { + for(std::size_t i=0; i<members_.size(); ++i) + { + members_[i]*=other[i]; + } + return *this; + } + + inline Vector operator+(const Vector &other) const + { + Vector v(members_); + return v+=other; + } + + inline Vector operator-(const Vector &other) const + { + Vector v(members_); + return v-=other; + } + + inline Vector operator*(const Vector &other) const + { + Vector v(members_); + return v*=other; + } + + inline Vector operator+(long double other) const + { + std::vector<long double> mem; + for(auto i : members_) + { + mem.emplace_back(i+other); + } + return Vector(mem); + } + + inline Vector operator-(long double other) const + { + std::vector<long double> mem; + for(auto i : members_) + { + mem.emplace_back(i-other); + } + return Vector(mem); + } + + inline Vector operator*(long double other) const + { + std::vector<long double> mem; + for(auto i : members_) + { + mem.emplace_back(i*other); + } + return Vector(mem); + } + + inline Vector operator/(long double other) const + { + std::vector<long double> mem; + for(auto i : members_) + { + mem.emplace_back(i/other); + } + return Vector(mem); + } + +protected: + Vector(const std::vector<long double> &members); +}; + +} // yage + +#endif diff --git a/include/YAGE/Math/vector2d.hpp b/include/YAGE/Math/vector2d.hpp new file mode 100644 index 00000000..1a6d2856 --- /dev/null +++ b/include/YAGE/Math/vector2d.hpp @@ -0,0 +1,20 @@ +#ifndef YAGE_MATH_VECTOR2D_HPP +#define YAGE_MATH_VECTOR2D_HPP + +#include "vector.hpp" + +namespace yage +{ + +class Vector2D : public Vector +{ +public: + Vector2D(long double x=0.L, long double y=0.L); + + long double getX() const; + long double getY() const; +}; + +} // yage + +#endif |