18 #ifndef __H__OCULAR_MATH_VECTOR_2__H__
19 #define __H__OCULAR_MATH_VECTOR_2__H__
21 #include "MathCommon.hpp"
22 #include "Equality.hpp"
23 #include "Utilities/Types.hpp"
24 #include "Exceptions/Exception.hpp"
54 Vector2(T
const &pX, T
const &pY)
62 x =
static_cast<T
>(0);
63 y =
static_cast<T
>(0);
75 T& operator[](
unsigned const& index)
86 THROW_EXCEPTION(
"Out-Of-Bounds Vector Access");
91 T operator[](
unsigned const& index)
const
102 THROW_EXCEPTION(
"Out-Of-Bounds Vector Access");
193 return std::sqrt((x * x) + (y * y));
216 if(IsEqual<T>(length, static_cast<T>(0)))
218 x =
static_cast<T
>(0);
219 y =
static_cast<T
>(0);
223 x /=
static_cast<T
>(length);
224 y /=
static_cast<T
>(length);
244 return (x * rhs.y) - (rhs.x * y);
256 return (x * rhs.x) + (y * rhs.y);
271 double angle = std::acos(normalLHS.
dot(normalRHS));
275 angle = PI_TWO - angle;
295 union { T x, u, s; };
296 union { T y, v, t; };
298 static bool OCULAR_INTERNAL_Force;
308 bool operator==(Vector2<T>
const &lhs, Vector2<T>
const &rhs)
310 return IsEqual<T>(lhs.x, rhs.x) && IsEqual<T>(lhs.y, rhs.y);
314 bool operator!=(Vector2<T>
const &lhs, Vector2<T>
const &rhs)
316 return !(lhs == rhs);
320 Vector2<T> operator+(Vector2<T>
const &lhs, Vector2<T>
const &rhs)
322 return Vector2<T>(lhs.x + rhs.x, lhs.y + rhs.y);
326 Vector2<T> operator+(Vector2<T>
const &lhs, T
const rhs)
328 return Vector2<T>(lhs.x + rhs, lhs.y + rhs);
332 Vector2<T> operator-(Vector2<T>
const &lhs, Vector2<T>
const &rhs)
334 return Vector2<T>(lhs.x - rhs.x, lhs.y - rhs.y);
338 Vector2<T> operator-(Vector2<T>
const &lhs, T
const &rhs)
340 return Vector2<T>(lhs.x - rhs, lhs.y - rhs);
344 Vector2<T> operator*(Vector2<T>
const &lhs, Vector2<T>
const &rhs)
346 return Vector2<T>(lhs.x * rhs.x, lhs.y * rhs.y);
350 Vector2<T> operator*(Vector2<T>
const &lhs, T
const &rhs)
352 return Vector2<T>(lhs.x * rhs, lhs.y * rhs);
356 Vector2<T> operator/(Vector2<T>
const &lhs, Vector2<T>
const &rhs)
358 return Vector2<T>(lhs.x / rhs.x, lhs.y / rhs.y);
362 Vector2<T> operator/(Vector2<T>
const &lhs, T
const &rhs)
364 return Vector2<T>(lhs.x / rhs, lhs.y / rhs);
370 typedef Vector2<int32_t> Vector2i;
371 typedef Vector2<uint32_t> Vector2ui;
372 typedef Vector2<float> Vector2f;
373 typedef Vector2<double> Vector2d;
375 typedef Vector2f Point2f;
376 typedef Vector2d Point2d;
T getLength() const
Definition: Vector2.hpp:199
T getMagnitude() const
Definition: Vector2.hpp:191
void normalize()
Definition: Vector2.hpp:210
double angleBetween(Vector2< T > const &rhs) const
Definition: Vector2.hpp:266
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: Vector2.hpp:44
T dot(Vector2< T > const &rhs) const
Definition: Vector2.hpp:254
double distanceTo(Vector2< T > const &rhs) const
Definition: Vector2.hpp:285
Vector2< T > getNormalized() const
Definition: Vector2.hpp:231