#ifndef SPECTRE_MATH_VECTOR2_H #define SPECTRE_MATH_VECTOR2_H #include #include namespace sp { template struct Vector2 { union { struct { T x, y; }; T v[2]; }; inline Vector2(); inline Vector2(T s); inline Vector2(T x, T y); template inline Vector2(const Vector2& vec); // ----------------- // Named operations. // ----------------- inline float length() const; inline Vector2& normalize(); // Dot product inline T dot(const Vector2& vec) const; inline Vector2& reflect(const Vector2& n); std::string toString() const; }; // ------------ // Compare // ------------ template inline bool operator==(const Vector2& a, const Vector2& b); template inline bool operator!=(const Vector2& a, const Vector2& b); template inline bool operator<(const Vector2& a, const Vector2& b); template inline bool operator<=(const Vector2& a, const Vector2& b); template inline bool operator>(const Vector2& a, const Vector2& b); template inline bool operator>=(const Vector2& a, const Vector2& b); // ------------------ // Unary arithmetic // ------------------ template inline Vector2 operator+(const Vector2& v); template inline Vector2 operator-(const Vector2& v); // ------------ // Arithmetic // ------------ template inline Vector2 operator+(const Vector2& a, const Vector2& b); template inline Vector2 operator-(const Vector2& a, const Vector2& b); template inline Vector2 operator/(const Vector2& a, const Vector2& b); template inline Vector2 operator*(const Vector2& a, const Vector2& b); template inline Vector2& operator+=(Vector2& a, const Vector2& b); template inline Vector2& operator-=(Vector2& a, const Vector2& b); template inline Vector2& operator/=(Vector2& a, const Vector2& b); template inline Vector2& operator*=(Vector2& a, const Vector2& b); // ------------------- // Scalar Arithmetic // ------------------- template inline Vector2 operator+(const Vector2& v, T s); template inline Vector2 operator+(T s, const Vector2& v); template inline Vector2 operator-(const Vector2& v, T s); template inline Vector2 operator-(T s, const Vector2& v); template inline Vector2 operator/(const Vector2& v, T s); template inline Vector2 operator/(T s, const Vector2& v); template inline Vector2 operator*(const Vector2& v, T s); template inline Vector2 operator*(T s, const Vector2& v); template inline Vector2& operator+=(Vector2& v, T s); template inline Vector2& operator-=(Vector2& v, T s); template inline Vector2& operator/=(Vector2& v, T s); template inline Vector2& operator*=(Vector2& v, T s); // ---------------- // Scalar compare // ---------------- template inline bool operator<(const Vector2& v, T s); template inline bool operator<(T s, const Vector2& v); template inline bool operator<=(const Vector2& v, T s); template inline bool operator<=(T s, const Vector2& v); template inline bool operator>(const Vector2& v, T s); template inline bool operator>(T s, const Vector2& v); template inline bool operator>=(const Vector2& v, T s); template inline bool operator>=(T s, const Vector2& v); // ------------------- // Stream operations // ------------------- template inline std::ostream& operator<<(std::ostream &s, const Vector2& v); // ----------------------------- // Common specialization types // ----------------------------- typedef Vector2 Vector2f; typedef Vector2 Vector2i; typedef Vector2 Vector2u; typedef Vector2 Vector2b; typedef Vector2 vec2f; typedef Vector2 vec2i; typedef Vector2 vec2u; typedef Vector2 vec2b; } // namespace sp #include "Vector2.inl" #endif /* SPECTRE_MATH_VECTOR2_H */