#pragma once #include namespace phosg { template struct Vector2 { union { T x; T a; }; union { T y; T b; }; Vector2(); Vector2(T x, T y); Vector2 operator-() const; Vector2 operator+(const Vector2& other) const; Vector2 operator-(const Vector2& other) const; Vector2 operator+(T other) const; Vector2 operator-(T other) const; Vector2 operator*(T other) const; Vector2 operator/(T other) const; Vector2 operator%(T other) const; Vector2& operator+=(const Vector2& other); Vector2& operator-=(const Vector2& other); Vector2& operator+=(T other); Vector2& operator-=(T other); Vector2& operator*=(T other); Vector2& operator/=(T other); Vector2& operator%=(T other); bool operator!() const; bool operator==(const Vector2& other) const; bool operator!=(const Vector2& other) const; // for usage in set/map bool operator<(const Vector2& other) const; T at(size_t dim) const; T norm1() const; double norm() const; T norm2() const; T dot(const Vector2& other) const; std::string str() const; static constexpr size_t dimensions(); }; template struct Vector3 { union { T x; T rx; T r; }; union { T y; T ry; T g; }; union { T z; T rz; T b; }; Vector3(); Vector3(T x, T y, T z); Vector3(const Vector2& xy, T z); Vector3 operator-() const; Vector3 operator+(const Vector3& other) const; Vector3 operator-(const Vector3& other) const; Vector3 operator+(T other) const; Vector3 operator-(T other) const; Vector3 operator*(T other) const; Vector3 operator/(T other) const; Vector3 operator%(T other) const; Vector3& operator+=(const Vector3& other); Vector3& operator-=(const Vector3& other); Vector3& operator+=(T other); Vector3& operator-=(T other); Vector3& operator*=(T other); Vector3& operator/=(T other); Vector3& operator%=(T other); bool operator!() const; bool operator==(const Vector3& other) const; bool operator!=(const Vector3& other) const; // for usage in set/map bool operator<(const Vector3& other) const; T at(size_t dim) const; T norm1() const; double norm() const; T norm2() const; T dot(const Vector3& other) const; Vector3 cross(const Vector3& other) const; std::string str() const; static constexpr size_t dimensions(); }; template struct Vector4 { union { T x; T r; }; union { T y; T g; }; union { T z; T b; }; union { T w; T a; }; Vector4(); Vector4(T x, T y, T z, T w); Vector4(const Vector2& xy, T z, T w); Vector4(const Vector3& xyz, T w); Vector4 operator-() const; Vector4 operator+(const Vector4& other) const; Vector4 operator-(const Vector4& other) const; Vector4 operator+(T other) const; Vector4 operator-(T other) const; Vector4 operator*(T other) const; Vector4 operator/(T other) const; Vector4 operator%(T other) const; Vector4& operator+=(const Vector4& other); Vector4& operator-=(const Vector4& other); Vector4& operator+=(T other); Vector4& operator-=(T other); Vector4& operator*=(T other); Vector4& operator/=(T other); Vector4& operator%=(T other); bool operator!() const; bool operator==(const Vector4& other) const; bool operator!=(const Vector4& other) const; // for usage in set/map bool operator<(const Vector4& other) const; T at(size_t dim) const; T norm1() const; double norm() const; T norm2() const; T dot(const Vector4& other) const; std::string str() const; static constexpr size_t dimensions(); }; template struct Matrix4 { union { T m[4][4]; T v[16]; }; Matrix4(); Matrix4 operator+(const Matrix4& other) const; Matrix4 operator-(const Matrix4& other) const; Matrix4 operator+(T other) const; Matrix4 operator-(T other) const; Matrix4 operator*(T other) const; Matrix4 operator/(T other) const; Matrix4 operator%(T other) const; Matrix4& operator+=(const Matrix4& other); Matrix4& operator-=(const Matrix4& other); Matrix4& operator+=(T other); Matrix4& operator-=(T other); Matrix4& operator*=(T other); Matrix4& operator/=(T other); Matrix4& operator%=(T other); Vector4 operator*(const Vector4& other) const; Matrix4 operator*(const Matrix4& other) const; Matrix4 operator*=(const Matrix4& other); bool operator==(const Matrix4& other) const; bool operator!=(const Matrix4& other) const; Matrix4 transposition() const; Matrix4& transpose(); Matrix4 inverse() const; Matrix4& invert(); std::string str() const; }; } // namespace phosg #include "Vector-inl.hh"