[PATCH] Implement D3DX__LengthSq with a test
David Adam
David.Adam at math.cnrs.fr
Thu Oct 18 04:37:17 CDT 2007
---
dlls/d3dx8/tests/math.c | 41 ++++++++++++++++++++++++++++++++++-------
include/d3dx8math.inl | 16 ++++++++++++++++
2 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 3449dfa..c77cef6 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -34,10 +34,19 @@ static void D3X8QuaternionTest(void)
q.x =3D 1.0f, q.y =3D 2.0f; q.z =3D 4.0f; q.w =3D 10.0f;=20
=20
/*_______________D3DXQuaternionLength__________________________*/
- expected =3D 11.0f;
- got =3D D3DXQuaternionLength(&q);
- ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", e=
xpected, got);
- /* Tests the case NULL */
+ expected =3D 11.0f;
+ got =3D D3DXQuaternionLength(&q);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D D3DXQuaternionLength(NULL);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+
+/*_______________D3DXQuaternionLengthSq________________________*/
+ expected =3D 121.0f;
+ got =3D D3DXQuaternionLength(&q);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+ /* Tests the case NULL */
expected=3D0.0f;
got =3D D3DXQuaternionLength(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
@@ -172,6 +181,15 @@ static void D3X8Vector3Test(void)
expected=3D0.0f;
got =3D D3DXVec3Length(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+
+/*_______________D3DXVec3LengthSq________________________*/
+ expected =3D 121.0f;
+ got =3D D3DXVec3Length(&u);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", e=
xpected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D D3DXVec3Length(NULL);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
}
=20
static void D3X8Vector4Test(void)
@@ -182,13 +200,22 @@ static void D3X8Vector4Test(void)
u.x =3D 1.0f; u.y =3D 2.0f; u.z =3D 4.0f; u.w =3D 10.0;
=20
/*_______________D3DXVec4Length__________________________*/
- expected =3D 11.0f;
- got =3D D3DXVec4Length(&u);
- ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", e=
xpected, got);
+ expected =3D 11.0f;
+ got =3D D3DXVec4Length(&u);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
/* Tests the case NULL */
expected=3D0.0f;
got =3D D3DXVec4Length(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+
+/*_______________D3DXVec4LengthSq________________________*/
+ expected =3D 121.0f;
+ got =3D D3DXVec4LengthSq(&u);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D D3DXVec4LengthSq(NULL);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
}
=20
START_TEST(math)
diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl
index 94e0019..50e1d97 100644
--- a/include/d3dx8math.inl
+++ b/include/d3dx8math.inl
@@ -101,6 +101,12 @@ static inline FLOAT D3DXVec3Length(CONST D3DXVECTOR3 *p=
v)
return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) =
);
}
=20
+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_______________________*/
=20
static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv)
@@ -109,6 +115,11 @@ static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *p=
v)
return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) =
+ (pv->w) * (pv->w) );
}
=20
+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);
+}
=20
/*__________________D3DXQUATERNION____________________*/
=20
@@ -118,6 +129,11 @@ static inline FLOAT D3DXQuaternionLength( CONST D3DXQUA=
TERNION *pq)
return sqrt( (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) =
+ (pq->w) * (pq->w) );
}
=20
+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);
+}
=20
=20
=20
--=20
1.5.3.2
--=_1a4rte1ze83o--
More information about the wine-patches
mailing list