1#ifndef NW_MATH_VECTOR2_H_
2#define NW_MATH_VECTOR2_H_
5#include <nw/math/math_Config.h>
6#include <nw/math/math_Arithmetic.h>
8namespace nw {
namespace math {
19#if defined(NW_MATH_ENABLE_INTRINSICS)
55 static const VEC2 zero(0.0f, 0.0f);
64 explicit VEC2(
const f32* p) { x = p[0]; y = p[1]; }
66 VEC2(f32 fx, f32 fy) { x = fx; y = fy; }
74 template <
typename ToPtr>
77 return reinterpret_cast<
ToPtr>(
this );
80 template <
typename ToPtr>
83 return reinterpret_cast<
ToPtr>(
this );
149#pragma clang diagnostic push
150#pragma clang diagnostic ignored "-Wfloat-equal"
155#pragma clang diagnostic pop
167 pOut->x = p1->x + p2->x; pOut->y = p1->y + p2->y;
174 pOut->x = p1->x - p2->x; pOut->y = p1->y - p2->y;
181 pOut->x = p->x * scale; pOut->y = p->y * scale;
189 pOut->x = p1->x + t * (p2->x - p1->x);
190 pOut->y = p1->y + t * (p2->y - p1->y);
197 return p1->x * p2->x + p1->y * p2->y;
203 return p->x * p->x + p->y * p->y;
215#if defined(NW_MATH_ENABLE_INTRINSICS)
322 return internal::standard::VEC2LenSq(p);
326VEC2Len(
const VEC2* p) {
return FSqrt(p->x * p->x + p->y * p->y); }
341namespace nw {
namespace math {
348 pOut->x = (p1->x > p2->x) ? p1->x : p2->x;
349 pOut->y = (p1->y > p2->y) ? p1->y : p2->y;
357 pOut->x = (p1->x < p2->x) ? p1->x : p2->x;
358 pOut->y = (p1->y < p2->y) ? p1->y : p2->y;
365#if defined(NW_MATH_ENABLE_INTRINSICS)
396 return p->x == 0.f && p->y == 0.f;
465namespace nw {
namespace math {
#define NW_MATH_AS_INLINE
Definition math_Config.h:6
#define NW_MATH_INLINE
Definition math_Config.h:7
#define NW_MATH_IMPL_NS
Definition math_Config.h:14
Definition math_Matrix34.h:11
NW_INLINE f32 VEC2DistSq(const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:207
VEC2 * VEC2Minimize(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
NW_INLINE VEC2 * VEC2Add(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:165
NW_INLINE f32 VEC2LenSq(const VEC2 *p)
Definition math_Vector2.h:201
NW_INLINE VEC2 * VEC2Lerp(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2, f32 t)
Definition math_Vector2.h:186
NW_INLINE VEC2 * VEC2Sub(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:172
NW_INLINE VEC2 * VEC2Scale(VEC2 *pOut, const VEC2 *p, f32 scale)
Definition math_Vector2.h:179
VEC2 * VEC2Maximize(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
NW_INLINE f32 VEC2Dot(const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:195
Definition math_Triangular.cpp:3
Definition math_Constant.cpp:5
f32 VEC2Len(const VEC2 *p)
Definition math_Vector2.h:326
VEC2 * VEC2Scale(VEC2 *pOut, const VEC2 &v, f32 scale)
Definition math_Vector2.h:470
NW_MATH_INLINE VEC2 * VEC2Lerp(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2, f32 t)
Definition math_Vector2.h:308
NW_MATH_INLINE VEC2 * VEC2Maximize(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
f32 VEC2LenSq(const VEC2 *p)
Definition math_Vector2.h:320
VEC2 * VEC2Sub(VEC2 *pOut, const VEC2 &v1, const VEC2 &v2)
Definition math_Vector2.h:469
VEC2 * VEC2FastNormalize(VEC2 *pOut, const VEC2 &v)
Definition math_Vector2.h:480
VEC2 * VEC2Lerp(VEC2 *pOut, const VEC2 &v1, const VEC2 &v2, f32 t)
Definition math_Vector2.h:471
VEC2 * VEC2FastNormalize(VEC2 *pOut, const VEC2 *p)
VEC2 * VEC2Normalize(VEC2 *pOut, const VEC2 &v)
Definition math_Vector2.h:479
VEC2 * VEC2Add(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:290
VEC2 * VEC2Add(VEC2 *pOut, const VEC2 &p1, const VEC2 &p2)
Definition math_Vector2.h:468
VEC2 * VEC2Minimize(VEC2 *pOut, const VEC2 &v1, const VEC2 &v2)
Definition math_Vector2.h:478
VEC2 * VEC2Sub(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:296
struct VEC2 Vector2
Definition math_Vector2.h:160
f32 VEC2Len(const VEC2 &v)
Definition math_Vector2.h:474
NW_MATH_INLINE bool VEC2IsZero(const VEC2 *p)
f32 VEC2DistSq(const VEC2 &v1, const VEC2 &v2)
Definition math_Vector2.h:475
VEC2 * VEC2Scale(VEC2 *pOut, const VEC2 *p, f32 scale)
Definition math_Vector2.h:302
bool VEC2IsZero(const VEC2 &v)
Definition math_Vector2.h:467
VEC2 * VEC2Normalize(VEC2 *pOut, const VEC2 *p)
VEC2 * VEC2Maximize(VEC2 *pOut, const VEC2 &v1, const VEC2 &v2)
Definition math_Vector2.h:477
VEC2 * VEC2FastSafeNormalize(VEC2 *pOut, const VEC2 *p, const VEC2 &alt)
NW_MATH_INLINE f32 VEC2Dot(const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:314
VEC2 * VEC2SafeNormalize(VEC2 *pOut, const VEC2 &v, const VEC2 &alt)
Definition math_Vector2.h:481
VEC2 * VEC2SafeNormalize(VEC2 *pOut, const VEC2 *p, const VEC2 &alt)
NW_MATH_INLINE f32 VEC2DistSq(const VEC2 *p1, const VEC2 *p2)
Definition math_Vector2.h:329
NW_MATH_INLINE VEC2 * VEC2Minimize(VEC2 *pOut, const VEC2 *p1, const VEC2 *p2)
f32 VEC2Dot(const VEC2 &v1, const VEC2 &v2)
Definition math_Vector2.h:472
VEC2 * VEC2FastSafeNormalize(VEC2 *pOut, const VEC2 &v, const VEC2 &alt)
Definition math_Vector2.h:482
VEC2 operator*(f32 f, const VEC2 &rhs)
Definition math_Vector2.h:335
f32 VEC2LenSq(const VEC2 &v)
Definition math_Vector2.h:473
Definition math_Constant.cpp:5
Definition math_Vector2.h:43
f32 y
Definition math_Vector2.h:45
f32 x
Definition math_Vector2.h:44
Definition math_Vector2.h:49
f32 value_type
Definition math_Vector2.h:61
VEC2(const VEC2_ &v)
Definition math_Vector2.h:65
VEC2 self_type
Definition math_Vector2.h:60
VEC2(const f32 *p)
Definition math_Vector2.h:64
VEC2()
Definition math_Vector2.h:63
static const VEC2 & Zero()
Definition math_Vector2.h:53
static const int DIMENSION
Definition math_Vector2.h:51
VEC2(f32 fx, f32 fy)
Definition math_Vector2.h:66
#define NW_INLINE
Definition types.h:14