1 #ifndef IV_MATH_VECTOR_H 2 #define IV_MATH_VECTOR_H 11 static const size_t size = 2;
14 template <
typename number_from_t>
17 inline Vector2_(number_t x_, number_t y_) :
x(x_),
y(y_) { }
19 template<
typename OtherT>
21 :
x(other.
x),
y(other.
y) { }
33 inline number_t
len2()
const {
return x *
x +
y *
y; }
34 inline number_t
len()
const {
return std::sqrt(
x *
x +
y *
y); }
37 return x * v.
y -
y * v.
x;
44 inline double angle()
const {
return std::atan2(
y,
x); }
47 const number_t*
data()
const {
return &
x; }
65 static const size_t size = 3;
68 template <
typename number_from_t>
70 template <
typename number_from_t>
73 inline Vector3_(number_t x_, number_t y_, number_t z_) :
x(x_),
y(y_), z(z_) { }
75 template<
typename OtherT>
77 :
x(other.
x),
y(other.
y), z(other.z) { }
89 inline number_t
len2()
const {
return x *
x +
y *
y + z * z; }
90 inline number_t
len()
const {
return std::sqrt(
x *
x +
y *
y + z * z); }
105 const number_t*
data()
const {
return &
x; }
113 template <
typename T>
119 template <
typename number_from_t>
121 template <
typename number_from_t>
123 template <
typename number_from_t>
126 inline Vector4_(number_t x_, number_t y_, number_t z_, number_t w_) :
x(x_),
y(y_), z(z_),
w(w_) { }
128 template<
typename OtherT>
130 :
x(other.
x),
y(other.
y), z(other.z),
w(other.
w) { }
142 inline number_t
len2()
const {
return x *
x +
y *
y + z * z +
w *
w; }
143 inline number_t
len()
const {
return std::sqrt(
x *
x +
y *
y + z * z +
w *
w); }
152 const number_t*
data()
const {
return &
x; }
164 static_assert(
sizeof(Vector2d) ==
sizeof(
double) * 2,
"Vector2d alignment error.");
165 static_assert(
sizeof(Vector2f) ==
sizeof(
float) * 2,
"Vector2f alignment error.");
171 static_assert(
sizeof(Vector3d) ==
sizeof(
double) * 3,
"Vector3d alignment error.");
172 static_assert(
sizeof(Vector3f) ==
sizeof(
float) * 3,
"Vector3f alignment error.");
178 static_assert(
sizeof(Vector4d) ==
sizeof(
double) * 4,
"Vector4d alignment error.");
179 static_assert(
sizeof(Vector4f) ==
sizeof(
float) * 4,
"Vector4f alignment error.");
number_t dot(const Vector2_ &v) const
Definition: vector.h:32
number_t cross(const Vector2_ &v) const
Definition: vector.h:36
Vector2_ operator*(number_t s) const
Definition: vector.h:30
Vector2_< number_t > xy() const
Definition: vector.h:102
number_t dot(const Vector4_ &v) const
Definition: vector.h:141
bool isnan(const Vector4_< T > &v)
Definition: vector.h:183
Vector3_< float > Vector3f
Definition: vector.h:168
number_t x
Definition: vector.h:53
number_t z
Definition: vector.h:157
number_t dot(const Vector3_ &v) const
Definition: vector.h:88
number_t x
Definition: vector.h:110
Vector3_(const OtherT &other)
Definition: vector.h:76
number_t len() const
Definition: vector.h:34
Vector2_(const OtherT &other)
Definition: vector.h:20
number_t y
Definition: vector.h:157
static Vector2_ NaN()
Definition: vector.h:50
Vector2_ & operator*=(number_t s)
Definition: vector.h:25
Vector2_ unit() const
Definition: vector.h:35
Vector2_ rotate90deg() const
Definition: vector.h:43
Vector2_ & operator/=(number_t s)
Definition: vector.h:26
Vector2_ operator/(number_t s) const
Definition: vector.h:31
number_t len() const
Definition: vector.h:143
number_t len2() const
Definition: vector.h:142
Vector4_(const Vector3_< number_from_t > &v)
Definition: vector.h:122
Vector2d Vector2
Definition: vector.h:162
number_t len() const
Definition: vector.h:90
static Vector4_ NaN()
Definition: vector.h:155
Vector2_(const Vector2_< number_from_t > &v)
Definition: vector.h:15
Vector3_ cross(const Vector3_ &v) const
Definition: vector.h:92
number_t y
Definition: vector.h:57
double angle() const
Definition: vector.h:44
number_t w
Definition: vector.h:157
number_t h
Definition: vector.h:58
Vector2_< double > Vector2d
Definition: vector.h:160
number_t len2() const
Definition: vector.h:89
Vector2_ & operator+=(const Vector2_ &v)
Definition: vector.h:23
number_t * data()
Definition: vector.h:46
number_t * data()
Definition: vector.h:104
Vector4d Vector4
Definition: vector.h:176
Vector3_ unit() const
Definition: vector.h:91
Vector4_(const Vector4_< number_from_t > &v)
Definition: vector.h:124
Vector4_< float > Vector4f
Definition: vector.h:175
T number_t
Definition: vector.h:64
Vector3_< double > Vector3d
Definition: vector.h:164
Vector2_< number_t > xy() const
Definition: vector.h:148
Vector4_(number_t v)
Definition: vector.h:125
bool isnan(const Vector2_< T > &v)
Definition: vector.h:181
Vector2_ & operator-=(const Vector2_ &v)
Definition: vector.h:24
Vector3d Vector3
Definition: vector.h:169
const number_t * data() const
Definition: vector.h:47
number_t y
Definition: vector.h:110
Vector4_ unit() const
Definition: vector.h:144
int shape() const
Definition: vector.h:106
Vector4_(const Vector2_< number_from_t > &v)
Definition: vector.h:120
Vector2_ operator+(const Vector2_ &v) const
Definition: vector.h:27
static Vector3_ NaN()
Definition: vector.h:108
T number_t
Definition: vector.h:115
const number_t * data() const
Definition: vector.h:152
int shape() const
Definition: vector.h:48
Vector2_(number_t x_, number_t y_)
Definition: vector.h:17
int shape() const
Definition: vector.h:153
number_t len2() const
Definition: vector.h:33
Vector4_(const OtherT &other)
Definition: vector.h:129
number_t z
Definition: vector.h:110
static const size_t size
Definition: vector.h:11
Vector3_(const Vector3_< number_from_t > &v)
Definition: vector.h:71
Vector4_(number_t x_, number_t y_, number_t z_, number_t w_)
Definition: vector.h:126
number_t * data()
Definition: vector.h:151
Vector3_(number_t x_, number_t y_, number_t z_)
Definition: vector.h:73
Vector4_< double > Vector4d
Definition: vector.h:171
T number_t
Definition: vector.h:10
number_t x
Definition: vector.h:157
number_t w
Definition: vector.h:54
const number_t * data() const
Definition: vector.h:105
Vector2_(number_t v)
Definition: vector.h:16
Vector3_(const Vector2_< number_from_t > &v)
Definition: vector.h:69
Vector2_< float > Vector2f
Definition: vector.h:161
Vector2_ operator-() const
Definition: vector.h:29
Vector3_(number_t v)
Definition: vector.h:72
Vector3_< number_t > xyz() const
Definition: vector.h:149