Index: trunk/psLib/src/math/psPolynomial.c
===================================================================
--- trunk/psLib/src/math/psPolynomial.c	(revision 5092)
+++ trunk/psLib/src/math/psPolynomial.c	(revision 5094)
@@ -7,6 +7,6 @@
 *  polynomials.  It also contains a Gaussian functions.
 *
-*  @version $Revision: 1.125 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-09-22 20:45:43 $
+*  @version $Revision: 1.126 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-09-22 22:22:15 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -161,7 +161,11 @@
 used frequently and the data structure created here does not contain the
 outer coefficients of the Chebyshev polynomials.
+ 
+XXX: From the poly nOrder/nTerm changem the maxChebyPoly here is still nTerms,
+not nOrder.
  *****************************************************************************/
-static psPolynomial1D **createChebyshevPolys(unsigned int maxChebyPoly)
-{
+static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly)
+{
+    //printf("createChebyshevPolys(%d)\n", maxChebyPoly);
     PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);
 
@@ -169,6 +173,6 @@
 
     chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
-    for (unsigned int i = 0; i < maxChebyPoly; i++) {
-        chebPolys[i] = psPolynomial1DAlloc(i, PS_POLYNOMIAL_ORD);
+    for (psS32 i = 0; i < maxChebyPoly; i++) {
+        chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
     }
 
@@ -184,7 +188,9 @@
             for (psS32 j = 0; j < chebPolys[i - 1]->COOL_1D_n; j++) {
                 chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
+                //printf("chebPolys[%d]->coeff[%d] is %.2f\n", i, j + 1, chebPolys[i]->coeff[j + 1]);
             }
             for (psS32 j = 0; j < chebPolys[i - 2]->COOL_1D_n; j++) {
                 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
+                //printf("chebPolys[%d]->coeff[%d] is %.2f\n", i, j, chebPolys[i]->coeff[j]);
             }
         }
@@ -203,4 +209,8 @@
                                  const psPolynomial1D* poly)
 {
+    //printf("ordPolynomial1DEval(%f): ", x);
+    //for (psS32 i = 0 ; i < (1 + poly->COOL_1D_n) ; i++) printf("(%.2f) ", poly->coeff[i]);
+    //printf("\n");
+
     unsigned int loop_x = 0;
     psF64 polySum = 0.0;
@@ -527,4 +537,5 @@
         maxChebyPoly = poly->COOL_4D_nT;
     }
+    // XXX: Add 1 since createChebyshevPolys() takes nTerms, not nOrder.
     chebPolys = createChebyshevPolys(maxChebyPoly + 1);
 
@@ -532,9 +543,9 @@
         for (loop_y = 0; loop_y < (1 + poly->COOL_4D_nY); loop_y++) {
             for (loop_z = 0; loop_z < (1 + poly->COOL_4D_nZ); loop_z++) {
-                for (loop_t = 0; loop_t < (1 + poly->COOL_4D_nZ); loop_t++) {
+                for (loop_t = 0; loop_t < (1 + poly->COOL_4D_nT); loop_t++) {
                     if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
                         //printf("HMMM (%d, %d, %d, %d)\n", loop_x, loop_y, loop_z, loop_t);
                         //printf("HMMM (%d, %d, %d, %d)\n", chebPolys[loop_x]->COOL_1D_n, chebPolys[loop_y]->COOL_1D_n, chebPolys[loop_z]->COOL_1D_n, chebPolys[loop_t]->COOL_1D_n);
-
+                        //printf("chebPolynomial4DEval()\n");
                         polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] *
                                    psPolynomial1DEval(chebPolys[loop_x], x) *
