Index: trunk/psLib/src/math/psSpline.c
===================================================================
--- trunk/psLib/src/math/psSpline.c	(revision 6305)
+++ trunk/psLib/src/math/psSpline.c	(revision 6437)
@@ -6,6 +6,6 @@
 *  This file contains the routines that allocate, free, and evaluate splines.
 *
-*  @version $Revision: 1.135 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-02-02 21:09:08 $
+*  @version $Revision: 1.136 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-02-17 00:56:48 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -101,5 +101,5 @@
  
 The first and second derivatives at the endpoints were previously undefined in
-the SDR.  From bugzilla #???, they are required to be 0.0, impementing natural
+the SDR.  From bugzilla #???, they are required to be 0.0, implementing natural
 splines.
  
@@ -228,5 +228,5 @@
     // The following code ensures that xPtr and yPtr points to a psF32 psVector.
     //
-    // XXX: When you debug, use the vector copy and create routines here:
+    // XXX: Use the vector copy and create routines here:
     //
 
@@ -345,5 +345,5 @@
 /*****************************************************************************
 psSpline1DEval(): this routine takes an existing spline of arbitrary order
-and an independent x value.  Each determines which spline that x corresponds
+and an independent x value.  It determines which spline that x corresponds
 to by doing a bracket disection on the knots of the spline data structure
 (vectorBinDisectF32()).  Then it evaluates the spline at that x location
@@ -360,5 +360,5 @@
     float x)
 {
-    psTrace(__func__, 3, "---- %s(%f) begin ----\n", __func__, x);
+    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
     PS_ASSERT_PTR_NON_NULL(spline, NAN);
     PS_ASSERT_INT_NONNEGATIVE(spline->n, NAN);
@@ -366,32 +366,27 @@
 
     psS32 n = spline->n;
+    if ((x < spline->knots->data.F32[0]) || (x > spline->knots->data.F32[n-1])) {
+        // If x is outside the range of spline->knots, generate a warning
+        // message, then return the left, or right, endpoint.
+        psLogMsg(__func__, PS_LOG_WARN,
+                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).",
+                 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n);
+
+        psS32 binNum = (x < spline->knots->data.F32[0]) ? 0 : n-1;
+        psTrace(__func__, 3, "---- %s() end ----\n", __func__);
+        return(psPolynomial1DEval(spline->spline[binNum], x));
+    }
+
     psScalar tmpScalar;
     tmpScalar.type.type = PS_TYPE_F32;
     tmpScalar.data.F32 = x;
     psS32 binNum = p_psVectorBinDisect(spline->knots, &tmpScalar);
-
     if (binNum < 0) {
-        //
-        // If x is outside the range of spline->knots, generate a warning
-        // message, then return the left, or right, endpoint.
-        //
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).",
-                 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n);
-
-        if (x < spline->knots->data.F32[0]) {
-            psF32 rcF32 = psPolynomial1DEval(spline->spline[0], x);
-            psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
-            return(rcF32);
-        } else if (x > spline->knots->data.F32[n-1]) {
-            psF32 rcF32 = psPolynomial1DEval(spline->spline[n-1], x);
-            psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
-            return(rcF32);
-        }
-    }
-
-    psF32 rcF32 = psPolynomial1DEval(spline->spline[binNum], x);
-    psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
-    return(rcF32);
+        psError(PS_ERR_UNKNOWN, false, "Could not perform bin dissection on spline->knots.\n");
+        return(NAN);
+    }
+
+    psTrace(__func__, 3, "---- %s() end ----\n", __func__);
+    return(psPolynomial1DEval(spline->spline[binNum], x));
 }
 
