Index: /trunk/psLib/test/astronomy/tst_psAstrometry01.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psAstrometry01.c	(revision 3709)
+++ /trunk/psLib/test/astronomy/tst_psAstrometry01.c	(revision 3710)
@@ -1,10 +1,10 @@
 /** @file  tst_psAstrometry01.c
 *
-*  @brief The code in this file will test the code in psAstrometry.[ch]
+*  @brief This code will test the code in psAstrometry.[ch]
 *
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-04-18 23:55:29 $
+*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-04-19 01:22:23 $
 *
 * XXX: Must test
@@ -571,55 +571,173 @@
 }
 
+
 /******************************************************************************
-XXX: This is only a rudimentary test of the psPlaneTransformCombine()
-function.  It tests a few NULL input parameter conditions.  Then, it combines
-two very simply functions and prints the result to the screen.  No values are
-checked.
- 
-// XXX: This function must verify the outputs of the combined functions.
- 
-// XXX: Must do: Run thru several combinations of random parameters, then pipe
-   random x/y values thru both trans1+trans2, as well as the combined function
-   and verify the output.
+TEST04: The strategy behind test04() is to generate a pair of transforms t1
+and t2 with a wide variety of sizes for the x/y components of the x/y
+transforms, then set the coefficients of t1/t2 to arbitray values, then
+generate a new transform t3 via psPlaneTransformCombine() function.  Then, for
+several arbitrary input plane coordinates, we tarnsform them via the new
+transform t3, as well as individually via t1 then t2, and verify that they
+produce identical output coordinates.
+ *****************************************************************************/
+// These macros determine the number of x/y test points which will be x-formed.
+#define TST04_X_MIN 0.0
+#define TST04_X_MAX 10.0
+#define TST04_Y_MIN 0.0
+#define TST04_Y_MAX 10.0
+#define TST04_NUM 5.0
+// These macros define the max sizes of the various input transforms.
+#define TST04_T1_X_X 6
+#define TST04_T1_X_Y 3
+#define TST04_T1_Y_X 3
+#define TST04_T1_Y_Y 3
+#define TST04_T2_X_X 3
+#define TST04_T2_X_Y 3
+#define TST04_T2_Y_X 3
+#define TST04_T2_Y_Y 3
+/******************************************************************************
+tstTransforms(t1, t2, t3): this function generates a set of arbitrary x/y
+coordinates, then transforms them into output coordinates via the t3
+transform, as well as the t1 followed by the t2 transform.  It verifies the
+output coordinates are identical and returns TRUE if so.  Otherwise, it prints
+an error message and returns FALSE.
+ *****************************************************************************/
+bool tstTransforms(psPlaneTransform *t1, psPlaneTransform *t2, psPlaneTransform *t3)
+{
+    bool testStatus = true;
+    psPlane *in = psPlaneAlloc();
+    in->xErr = 0.0;
+    in->yErr = 0.0;
+
+    for (in->x = TST04_X_MIN ;
+            in->x <= TST04_X_MAX ;
+            in->x+= (TST04_X_MAX-TST04_X_MIN) / TST04_NUM) {
+        for (in->y = TST04_Y_MIN ; in->y <= TST04_Y_MAX ; in->y+= (TST04_Y_MAX-TST04_Y_MIN) / TST04_NUM) {
+            // Apply the t1/t2 transforms individually to the in coords.
+            psPlane *mid = psPlaneTransformApply(NULL, t1, in);
+            if (mid == NULL) {
+                printf("TEST ERROR: intermediate psPlane coords are NULL.\n");
+                psFree(in);
+                return(false);
+            }
+
+            psPlane *outT1T2 = psPlaneTransformApply(NULL, t2, mid);
+            if (outT1T2 == NULL) {
+                printf("TEST ERROR: intermediate psPlane coords are NULL.\n");
+                psFree(mid);
+                return(false);
+            }
+
+            // Apply the t3 transforms individually to the in coords.
+            psPlane *outT3 = psPlaneTransformApply(NULL, t3, in);
+            if (outT3 == NULL) {
+                printf("TEST ERROR: intermediate psPlane coords are NULL.\n");
+                psFree(mid);
+                psFree(outT1T2);
+                return(false);
+            }
+
+            // Verify that the results are identical.
+            if (fabs(outT3->x - outT1T2->x) > FLT_EPSILON) {
+                printf("TEST ERROR: x is %f, should be %f\n", outT3->x, outT1T2->x);
+                testStatus = false;
+            }
+            if (fabs(outT3->y - outT1T2->y) > FLT_EPSILON) {
+                printf("TEST ERROR: y is %f, should be %f\n", outT3->y, outT1T2->y);
+                testStatus = false;
+            }
+            psFree(mid);
+            psFree(outT1T2);
+            psFree(outT3);
+        }
+    }
+
+    psFree(in);
+    return(testStatus);
+}
+
+/******************************************************************************
+setCoeffs(t1, t2): this function sets the coefficients of the t1 and t2
+transforms to somewhat arbitrary values.
+ *****************************************************************************/
+int setCoeffs(psPlaneTransform *t1, psPlaneTransform *t2)
+{
+    for (psS32 t1xx = 0 ; t1xx < t1->x->nX ; t1xx++) {
+        for (psS32 t1xy = 0 ; t1xy < t1->x->nY ; t1xy++) {
+            t1->x->coeff[t1xx][t1xy] = (psF32) (t1xx + t1xy);
+        }
+    }
+
+    for (psS32 t1yx = 0 ; t1yx < t1->y->nX ; t1yx++) {
+        for (psS32 t1yy = 0 ; t1yy < t1->y->nY ; t1yy++) {
+            t1->y->coeff[t1yx][t1yy] = (psF32) (t1yx + t1yy - 10);
+        }
+    }
+    for (psS32 t2xx = 0 ; t2xx < t2->x->nX ; t2xx++) {
+        for (psS32 t2xy = 0 ; t2xy < t2->x->nY ; t2xy++) {
+            t2->x->coeff[t2xx][t2xy] = (psF32) (2 + (t2xx * t2xy));
+        }
+    }
+    for (psS32 t2yx = 0 ; t2yx < t2->y->nX ; t2yx++) {
+        for (psS32 t2yy = 0 ; t2yy < t2->y->nY ; t2yy++) {
+            t2->y->coeff[t2yx][t2yy] = (psF32) (3 - t2yx + t2yy);
+        }
+    }
+
+    return(0);
+}
+
+/******************************************************************************
+test04(): We test psPlaneTransformCombine() with a wariety of input
+transforms, as well as input coordinates, as well as erroneous input
+parameters.
  *****************************************************************************/
 psS32 test4( void )
 {
     bool testStatus = true;
+
+
+    //
+    // Create a variety of input input transforms, then test them.
+    //
+    for (psS32 t1xx = 1 ; t1xx < TST04_T1_X_X ; t1xx++) {
+        for (psS32 t1xy = 1 ; t1xy < TST04_T1_X_Y ; t1xy++) {
+            for (psS32 t1yx = 1 ; t1yx < TST04_T1_Y_X ; t1yx++) {
+                for (psS32 t1yy = 1 ; t1yy < TST04_T1_Y_Y ; t1yy++) {
+                    for (psS32 t2xx = 1 ; t2xx < TST04_T2_X_X ; t2xx++) {
+                        for (psS32 t2xy = 1 ; t2xy < TST04_T2_X_Y ; t2xy++) {
+                            for (psS32 t2yx = 1 ; t2yx < TST04_T2_Y_X ; t2yx++) {
+                                for (psS32 t2yy = 1 ; t2yy < TST04_T2_Y_Y ; t2yy++) {
+                                    psPlaneTransform *trans1 = psPlaneTransformAlloc(PS_MAX(t1xx, t1yx), PS_MAX(t1xy, t1yy));
+                                    psPlaneTransform *trans2 = psPlaneTransformAlloc(PS_MAX(t2xx, t2yx), PS_MAX(t2xy, t2yy));
+                                    psPlaneTransform *trans3 = NULL;
+                                    setCoeffs(trans1, trans2);
+                                    trans3 = psPlaneTransformCombine(NULL, trans1, trans2);
+
+                                    if (trans3 == NULL) {
+                                        printf("TEST ERROR: psPlaneTransformCombine() returned NULL/\n");
+                                        testStatus = false;
+                                    } else {
+                                        testStatus = tstTransforms(trans1, trans2, trans3);
+                                    }
+                                    psFree(trans1);
+                                    psFree(trans2);
+                                    psFree(trans3);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    //
+    // Test erroneous input parameter combinations
+    //
     psPlaneTransform *trans1 = psPlaneTransformAlloc(2, 2);
     psPlaneTransform *trans2 = psPlaneTransformAlloc(2, 2);
     psPlaneTransform *trans3 = NULL;
-
-    printf("trans1: x = x+y, y = x+y\n");
-    trans1->x->coeff[0][0] = 0.0;
-    trans1->x->coeff[0][1] = 1.0;
-    trans1->x->coeff[1][0] = 1.0;
-    trans1->x->coeff[1][1] = 0;
-    trans1->y->coeff[0][0] = 0.0;
-    trans1->y->coeff[0][1] = 1.0;
-    trans1->y->coeff[1][0] = 1.0;
-    trans1->y->coeff[1][1] = 0;
-    printTrans(trans1);
-
-    printf("trans2: x = x+y, y = x+y\n");
-    trans2->x->coeff[0][0] = 0.0;
-    trans2->x->coeff[0][1] = 1.0;
-    trans2->x->coeff[1][0] = 1.0;
-    trans2->x->coeff[1][1] = 0;
-    trans2->y->coeff[0][0] = 0.0;
-    trans2->y->coeff[0][1] = 1.0;
-    trans2->y->coeff[1][0] = 1.0;
-    trans2->y->coeff[1][1] = 0;
-    printTrans(trans2);
-
-    printf("trans2: x = xy, y = xy\n");
-    trans2->x->coeff[0][0] = 0.0;
-    trans2->x->coeff[0][1] = 0.0;
-    trans2->x->coeff[1][0] = 0.0;
-    trans2->x->coeff[1][1] = 1.0;
-    trans2->y->coeff[0][0] = 0.0;
-    trans2->y->coeff[0][1] = 0.0;
-    trans2->y->coeff[1][0] = 0.0;
-    trans2->y->coeff[1][1] = 1.0;
-    printTrans(trans2);
 
     printf("----------------------------------------------------------------------------------\n");
@@ -641,20 +759,6 @@
     }
 
-
-    printf("----------------------------------------------------------------------------------\n");
-    printf("Calling psPlaneTransformCombine with acceptable data.\n");
-    trans3 = psPlaneTransformCombine(NULL, trans1, trans2);
-    if (trans3 == NULL) {
-        printf("TEST ERROR: psPlaneTransformCombine() returned a NULL psPlaneTransform.\n");
-        testStatus = false;
-        psFree(trans3);
-    }
-    printf("trans3: \n");
-    printTrans(trans3);
-
     psFree(trans1);
     psFree(trans2);
-    psFree(trans3);
-
     return(!testStatus);
 }
