[PATCH] Implement D3DX__LengthSq with a test
David Adam
David.Adam at math.cnrs.fr
Thu Oct 18 10:47:50 CDT 2007
---
dlls/d3dx8/tests/math.c | 27 +++++++++++++++++++++++++++
include/d3dx8math.inl | 18 ++++++++++++++++--
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 3449dfa..d6afdf4 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -41,6 +41,15 @@ static void D3X8QuaternionTest(void)
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 D3DXQuaternionLengthSq(&q);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D D3DXQuaternionLengthSq(NULL);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
}
=20
static void D3X8Vector2Test(void)
@@ -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 D3DXVec3LengthSq(&u);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D D3DXVec3LengthSq(NULL);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
}
=20
static void D3X8Vector4Test(void)
@@ -189,6 +207,15 @@ static void D3X8Vector4Test(void)
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..c8de09b 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,7 +129,10 @@ 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
#endif
--=20
1.5.3.2
--=_5c9fsdw7ds00--
More information about the wine-patches
mailing list