d3dx8: Implement D3DX*Length with a test.

oldstable
David Adam 2007-10-18 14:03:03 +02:00 committed by Alexandre Julliard
parent 8f3accc718
commit d6377d2fd8
2 changed files with 84 additions and 0 deletions

View File

@ -26,6 +26,23 @@
#define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector= (%f, %f)\n , Got Vector= (%f, %f)\n", expectedvec.x, expectedvec.y, gotvec.x, gotvec.y);
static void D3X8QuaternionTest(void)
{
D3DXQUATERNION q;
FLOAT expected, got;
q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
/*_______________D3DXQuaternionLength__________________________*/
expected = 11.0f;
got = D3DXQuaternionLength(&q);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
/* Tests the case NULL */
expected=0.0f;
got = D3DXQuaternionLength(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
}
static void D3X8Vector2Test(void)
{
D3DXVECTOR2 expectedvec, gotvec, u, v;
@ -140,7 +157,44 @@ static void D3X8Vector2Test(void)
}
static void D3X8Vector3Test(void)
{
D3DXVECTOR3 u;
FLOAT expected, got;
u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
/*_______________D3DXVec3Length__________________________*/
expected = 11.0f;
got = D3DXVec3Length(&u);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
/* Tests the case NULL */
expected=0.0f;
got = D3DXVec3Length(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
}
static void D3X8Vector4Test(void)
{
D3DXVECTOR4 u;
FLOAT expected, got;
u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
/*_______________D3DXVec4Length__________________________*/
expected = 11.0f;
got = D3DXVec4Length(&u);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
/* Tests the case NULL */
expected=0.0f;
got = D3DXVec4Length(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
}
START_TEST(math)
{
D3X8QuaternionTest();
D3X8Vector2Test();
D3X8Vector3Test();
D3X8Vector4Test();
}

View File

@ -19,6 +19,8 @@
#ifndef __D3DX8MATH_INL__
#define __D3DX8MATH_INL__
/*_______________D3DXVECTOR2________________________*/
static inline D3DXVECTOR2* D3DXVec2Add(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
{
if ( !pout || !pv1 || !pv2) return NULL;
@ -91,4 +93,32 @@ static inline D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2 *pout, CONST D3DXVECTOR2
return pout;
}
/*__________________D3DXVECTOR3_______________________*/
static inline FLOAT D3DXVec3Length(CONST D3DXVECTOR3 *pv)
{
if (!pv) return 0.0f;
return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) );
}
/*__________________D3DXVECTOR4_______________________*/
static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv)
{
if (!pv) return 0.0f;
return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w) );
}
/*__________________D3DXQUATERNION____________________*/
static inline FLOAT D3DXQuaternionLength( CONST D3DXQUATERNION *pq)
{
if (!pq) return 0.0f;
return sqrt( (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w) );
}
#endif