diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c index d0d0b0390aa..a5980209346 100644 --- a/dlls/d3dx8/tests/math.c +++ b/dlls/d3dx8/tests/math.c @@ -41,6 +41,15 @@ static void D3X8QuaternionTest(void) expected=0.0f; got = D3DXQuaternionLength(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + +/*_______________D3DXQuaternionLengthSq________________________*/ + expected = 121.0f; + got = D3DXQuaternionLengthSq(&q); + ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + /* Tests the case NULL */ + expected=0.0f; + got = D3DXQuaternionLengthSq(NULL); + ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); } static void D3X8Vector2Test(void) @@ -172,6 +181,15 @@ static void D3X8Vector3Test(void) expected=0.0f; got = D3DXVec3Length(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + +/*_______________D3DXVec3LengthSq________________________*/ + expected = 121.0f; + got = D3DXVec3LengthSq(&u); + ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + /* Tests the case NULL */ + expected=0.0f; + got = D3DXVec3LengthSq(NULL); + ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); } static void D3X8Vector4Test(void) @@ -189,6 +207,15 @@ static void D3X8Vector4Test(void) expected=0.0f; got = D3DXVec4Length(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + +/*_______________D3DXVec4LengthSq________________________*/ + expected = 121.0f; + got = D3DXVec4LengthSq(&u); + ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + /* Tests the case NULL */ + expected=0.0f; + got = D3DXVec4LengthSq(NULL); + ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); } START_TEST(math) diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl index 94e0019c885..c8de09bb23c 100644 --- a/include/d3dx8math.inl +++ b/include/d3dx8math.inl @@ -101,6 +101,12 @@ static inline FLOAT D3DXVec3Length(CONST D3DXVECTOR3 *pv) return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) ); } +static inline FLOAT D3DXVec3LengthSq(CONST D3DXVECTOR3 *pv) +{ + if (!pv) return 0.0f; + return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z); +} + /*__________________D3DXVECTOR4_______________________*/ static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv) @@ -109,6 +115,11 @@ static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv) return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w) ); } +static inline FLOAT D3DXVec4LengthSq(CONST D3DXVECTOR4 *pv) +{ + if (!pv) return 0.0f; + return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w); +} /*__________________D3DXQUATERNION____________________*/ @@ -118,7 +129,10 @@ static inline FLOAT D3DXQuaternionLength( CONST D3DXQUATERNION *pq) return sqrt( (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w) ); } - - +static inline FLOAT D3DXQuaternionLengthSq( CONST D3DXQUATERNION *pq) +{ + if (!pq) return 0.0f; + return (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w); +} #endif