1/*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: math_Vector2.ipp 4 Copyright (C)2009-2010 Nintendo Co., Ltd. All rights reserved. 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 $Revision: 17995 $ 11 *--------------------------------------------------------------------------- 12 13 14*/ 15 16namespace nn { 17namespace math { 18 19/* ------------------------------------------------------------------------ 20 VEC2 21 ------------------------------------------------------------------------ */ 22 23/* Please see man pages for details 24 25 26*/ 27 28/* 29 30 31 32 33 34*/ 35NN_MATH_INLINE bool 36VEC2IsZero(const VEC2* p) 37{ 38 return p->x == 0.f && p->y == 0.f; 39} 40 41/* 42 43 44 45 46 47 48 49*/ 50NN_MATH_INLINE VEC2* 51VEC2Maximize(VEC2* pOut, const VEC2* p1, const VEC2* p2) 52{ 53 pOut->x = (p1->x > p2->x) ? p1->x : p2->x; 54 pOut->y = (p1->y > p2->y) ? p1->y : p2->y; 55 56 return pOut; 57} 58 59 60/* 61 62 63 64 65 66 67 68*/ 69NN_MATH_INLINE VEC2* 70VEC2Minimize(VEC2* pOut, const VEC2* p1, const VEC2* p2) 71{ 72 pOut->x = (p1->x < p2->x) ? p1->x : p2->x; 73 pOut->y = (p1->y < p2->y) ? p1->y : p2->y; 74 75 return pOut; 76} 77 78 79/* 80 81 82 83 84 85 86*/ 87NN_MATH_INLINE VEC2* 88VEC2Normalize(VEC2* pOut, const VEC2* p) 89{ 90 (void)VEC2Scale(pOut, p, FrSqrt(p->x * p->x + p->y * p->y)); 91 92 return pOut; 93} 94 95/* 96 97 98 99 100 101 102 103 104*/ 105NN_MATH_INLINE VEC2* 106VEC2SafeNormalize(VEC2* pOut, const VEC2* p, const VEC2& alt) 107{ 108 NN_NULL_ASSERT(pOut); 109 NN_NULL_ASSERT(p); 110 111 f32 mag = (p->x * p->x) + (p->y * p->y); 112 113 if (mag == 0) 114 { 115 *pOut = alt; 116 117 return pOut; 118 } 119 120 (void)VEC2Scale(pOut, p, FrSqrt(mag)); 121 122 return pOut; 123} 124 125/* 126 127*/ 128 129} // namespace math 130} // namespace nn 131