[PATCH] Implement D3DXColorNegative with a test

David Adam David.Adam at math.cnrs.fr
Tue Oct 23 04:30:55 CDT 2007


---
 dlls/d3dx8/tests/math.c |   31 +++++++++++++++++++++++++++++++
 include/d3dx8math.inl   |   10 ++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index e73a619..7c74b65 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -24,12 +24,42 @@
=20
 #define admitted_error 0.00001f
=20
+#define expect_color(expectedcolor,gotcolor) ok((fabs(expectedcolor.r-gotco=
lor.r)<admitted_error)&&(fabs(expectedcolor.g-gotcolor.g)<admitted_error)&&(=
fabs(expectedcolor.b-gotcolor.b)<admitted_error)&&(fabs(expectedcolor.a-gotc=
olor.a)<admitted_error),"Expected Color=3D (%f, %f, %f, %f)\n , Got Color=3D=
 (%f, %f, %f, %f)\n", expectedcolor.r, expectedcolor.g, expectedcolor.b, exp=
ectedcolor.a, gotcolor.r, gotcolor.g, gotcolor.b, gotcolor.a);
+
 #define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<adm=
itted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector=
=3D (%f, %f)\n , Got Vector=3D (%f, %f)\n", expectedvec.x, expectedvec.y, go=
tvec.x, gotvec.y);
=20
 #define expect_vec3(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<ad=
mitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expected=
vec.z-gotvec.z)<admitted_error),"Expected Vector=3D (%f, %f,%f)\n , Got Vect=
or=3D (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.x=
, gotvec.y, gotvec.z);
=20
 #define expect_vec4(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<ad=
mitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expected=
vec.z-gotvec.z)<admitted_error)&&(fabs(expectedvec.w-gotvec.w)<admitted_erro=
r),"Expected Vector=3D (%f, %f, %f, %f)\n , Got Vector=3D (%f, %f, %f, %f)\n=
", expectedvec.x, expectedvec.y, expectedvec.z, expectedvec.w, gotvec.x, got=
vec.y, gotvec.z, gotvec.w);
=20
+static void D3DXColorTest(void)
+{
+    D3DXCOLOR color, color1, expected, got;
+    LPD3DXCOLOR funcpointer;
+
+    color.r =3D 0.2f; color.g =3D 0.75f; color.b =3D 0.41f; color.a =3D 0.9=
3f;
+
+/*_______________D3DXColorNegative________________*/
+    expected.r =3D 0.8f; expected.g =3D 0.25f; expected.b =3D 0.59f; expect=
ed.a =3D 0.93f;
+    D3DXColorNegative(&got,&color);
+    expect_color(got,expected);
+    /* Test the greater than 1 case */
+    color1.r =3D 0.2f; color1.g =3D 1.75f; color1.b =3D 0.41f; color1.a =3D=
 0.93f;
+    expected.r =3D 0.8f; expected.g =3D -0.75f; expected.b =3D 0.59f; expec=
ted.a =3D 0.93f;
+    D3DXColorNegative(&got,&color1);
+    expect_color(got,expected);
+    /* Test the negative case */
+    color1.r =3D 0.2f; color1.g =3D -0.75f; color1.b =3D 0.41f; color1.a =
=3D 0.93f;
+    expected.r =3D 0.8f; expected.g =3D 1.75f; expected.b =3D 0.59f; expect=
ed.a =3D 0.93f;
+    D3DXColorNegative(&got,&color1);
+    expect_color(got,expected);
+    /* Test the NULL case */
+    funcpointer =3D D3DXColorNegative(&got,NULL);
+    ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+    funcpointer =3D D3DXColorNegative(NULL,NULL);
+    ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+}
+
 static void D3DXPlaneTest(void)
 {
     D3DXPLANE plane;
@@ -473,6 +503,7 @@ static void D3X8Vector4Test(void)
=20
 START_TEST(math)
 {
+    D3DXColorTest();
     D3DXPlaneTest();
     D3X8QuaternionTest();
     D3X8Vector2Test();
diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl
index 71f9641..d4ddb14 100644
--- a/include/d3dx8math.inl
+++ b/include/d3dx8math.inl
@@ -19,6 +19,16 @@
 #ifndef __D3DX8MATH_INL__
 #define __D3DX8MATH_INL__
=20
+static inline D3DXCOLOR* D3DXColorNegative(D3DXCOLOR *pout, CONST D3DXCOLOR=
 *pc)
+{
+    if ( !pout || !pc ) return NULL;
+    pout->r =3D 1.0f - pc->r;
+    pout->g =3D 1.0f - pc->g;
+    pout->b =3D 1.0f - pc->b;
+    pout->a =3D pc->a;
+    return pout;
+}
+
 /*_______________D3DXVECTOR2________________________*/
=20
 static inline D3DXVECTOR2* D3DXVec2Add(D3DXVECTOR2 *pout, CONST D3DXVECTOR2=
 *pv1, CONST D3DXVECTOR2 *pv2)
--=20
1.5.3.2


--=_43y9gcxqjtgk--



More information about the wine-patches mailing list