78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
#ifndef VECTOR_HPP
|
|
#define VECTOR_HPP
|
|
|
|
#include <cmath>
|
|
#include <array>
|
|
#include <istream>
|
|
|
|
namespace pae
|
|
{
|
|
|
|
template<typename T, std::size_t N>
|
|
class Vector
|
|
{
|
|
public:
|
|
Vector();
|
|
|
|
template<typename... Types>
|
|
Vector(Types... l);
|
|
|
|
Vector(Vector const& v);
|
|
|
|
T norm2() const;
|
|
T norm() const;
|
|
|
|
Vector<T,N>& operator=(T t);
|
|
Vector<T,N>& operator=(Vector<T,N> t);
|
|
|
|
Vector<T,N> operator-();
|
|
|
|
Vector<T,N>& operator+=(Vector<T,N> const& v);
|
|
Vector<T,N>& operator-=(Vector<T,N> const& v);
|
|
|
|
Vector<T,N>& operator*=(float f);
|
|
Vector<T,N>& operator/=(float f);
|
|
|
|
T& x() {static_assert(N > 0, "x() doesn't exist on Vector<T,0>"); return data[0]; };
|
|
T& y() {static_assert(N > 1, "y() doesn't exist on Vector<T,1>"); return data[1]; };
|
|
T& z() {static_assert(N > 2, "z() doesn't exist on Vector<T,2>"); return data[2]; };
|
|
T const& x() const {static_assert(N > 0, "x() doesn't exist on Vector<T,0>"); return data[0]; };
|
|
T const& y() const {static_assert(N > 1, "y() doesn't exist on Vector<T,1>"); return data[1]; };
|
|
T const& z() const {static_assert(N > 2, "z() doesn't exist on Vector<T,2>"); return data[2]; };
|
|
|
|
std::array<T,N> data;
|
|
};
|
|
|
|
template<typename T, std::size_t N>
|
|
bool operator==(Vector<T,N> const& l, Vector<T,N> const& r);
|
|
|
|
template<typename T, std::size_t N>
|
|
bool operator!=(Vector<T,N> const& l, Vector<T,N> const& r);
|
|
|
|
template<typename T, std::size_t N>
|
|
Vector<T,N> operator+(Vector<T,N> l, Vector<T,N> const& r);
|
|
|
|
template<typename T, std::size_t N>
|
|
Vector<T,N> operator-(Vector<T,N> l, Vector<T,N> const& r);
|
|
|
|
template<typename T, std::size_t N>
|
|
Vector<T,N> operator*(Vector<T,N> l, float f);
|
|
|
|
template<typename T, std::size_t N>
|
|
Vector<T,N> operator/(Vector<T,N> l, float f);
|
|
|
|
template<typename T, std::size_t N>
|
|
std::istream& operator>>(std::istream& stream, Vector<T,N>& v);
|
|
|
|
template<typename T, std::size_t N>
|
|
std::ostream& operator<<(std::ostream& stream, Vector<T,N> const& v);
|
|
|
|
template<typename T>
|
|
using Vector3 = Vector<T,3>;
|
|
|
|
} // namespace pae
|
|
|
|
#include "Vector.inl"
|
|
|
|
#endif // VECTOR_HPP
|