Skip to content
Permalink
Browse files

Some fixes for vectors

  • Loading branch information...
Amanieu committed May 10, 2015
1 parent 582112c commit 7d6492cbcd6fd0579d18a0136a9cb3359a080ac0
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/common/math/Vector.h
@@ -97,7 +97,8 @@ namespace Math {
template<typename Func> Type Reduce(Type init, Func func);

// Get an element of the vector
Type& operator[](size_t index) const {return data[index];}
Type& operator[](size_t index) {return data[index];}
const Type& operator[](size_t index) const {return data[index];}
};

// Type-specific vector operations
@@ -119,8 +120,10 @@ namespace Math {
Vector<Length, Type> operator-(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a - b;}, other);}
Vector<Length, Type> operator*(Type x) const {return this->Apply([x](Type a) {return a * x;});}
Vector<Length, Type> operator*(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a * b;}, other);}
friend Vector<Length, Type> operator*(Type x, Vector<Length, Type> other) {return other->Apply([x](Type a) {return x * a;});}
Vector<Length, Type> operator/(Type x) const {return this->Apply([x](Type a) {return a / x;});}
Vector<Length, Type> operator/(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a / b;}, other);}
friend Vector<Length, Type> operator/(Type x, Vector<Length, Type> other) {return other->Apply([x](Type a) {return x / a;});}

// Compound arithmetic operators
Vector<Length, Type>& operator+=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) + other;}
@@ -147,10 +150,13 @@ namespace Math {
Vector<Length, Type> operator-(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a - b;}, other);}
Vector<Length, Type> operator*(Type x) const {return this->Apply([x](Type a) {return a * x;});}
Vector<Length, Type> operator*(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a * b;}, other);}
friend Vector<Length, Type> operator*(Type x, Vector<Length, Type> other) {return other->Apply([x](Type a) {return x * a;});}
Vector<Length, Type> operator/(Type x) const {return this->Apply([x](Type a) {return a / x;});}
Vector<Length, Type> operator/(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a / b;}, other);}
friend Vector<Length, Type> operator/(Type x, Vector<Length, Type> other) {return other->Apply([x](Type a) {return x / a;});}
Vector<Length, Type> operator%(Type x) const {return this->Apply([x](Type a) {return a % x;});}
Vector<Length, Type> operator%(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a % b;}, other);}
friend Vector<Length, Type> operator%(Type x, Vector<Length, Type> other) {return other->Apply([x](Type a) {return x % a;});}

// Compound arithmetic operators
Vector<Length, Type>& operator+=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) + other;}

0 comments on commit 7d6492c

Please sign in to comment.
You can’t perform that action at this time.