1/*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: math_Vector2.ipp 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 45840 $ 14 *---------------------------------------------------------------------------*/ 15 16namespace nn { 17namespace math { 18 19/* ------------------------------------------------------------------------ 20 VEC2 21 ------------------------------------------------------------------------ */ 22NN_MATH_INLINE bool 23VEC2IsZero(const VEC2* p) 24{ 25 return p->x == 0.f && p->y == 0.f; 26} 27 28NN_MATH_INLINE VEC2* 29VEC2Maximize(VEC2* pOut, const VEC2* p1, const VEC2* p2) 30{ 31 pOut->x = (p1->x > p2->x) ? p1->x : p2->x; 32 pOut->y = (p1->y > p2->y) ? p1->y : p2->y; 33 34 return pOut; 35} 36 37NN_MATH_INLINE VEC2* 38VEC2Minimize(VEC2* pOut, const VEC2* p1, const VEC2* p2) 39{ 40 pOut->x = (p1->x < p2->x) ? p1->x : p2->x; 41 pOut->y = (p1->y < p2->y) ? p1->y : p2->y; 42 43 return pOut; 44} 45 46NN_MATH_INLINE VEC2* 47VEC2Normalize(VEC2* pOut, const VEC2* p) 48{ 49 (void)VEC2Scale(pOut, p, FrSqrt(p->x * p->x + p->y * p->y)); 50 51 return pOut; 52} 53 54NN_MATH_INLINE VEC2* 55VEC2SafeNormalize(VEC2* pOut, const VEC2* p, const VEC2& alt) 56{ 57 NN_NULL_ASSERT(pOut); 58 NN_NULL_ASSERT(p); 59 60 f32 mag = (p->x * p->x) + (p->y * p->y); 61 62 if (mag == 0) 63 { 64 *pOut = alt; 65 66 return pOut; 67 } 68 69 (void)VEC2Scale(pOut, p, FrSqrt(mag)); 70 71 return pOut; 72} 73 74} // namespace math 75} // namespace nn 76