Index: trunk/psLib/src/math/psSpline.h
===================================================================
--- trunk/psLib/src/math/psSpline.h	(revision 23486)
+++ trunk/psLib/src/math/psSpline.h	(revision 42336)
@@ -5,5 +5,6 @@
  * and evaluate splines.
  *
- * @author GLG, MHPCC
+ * @author GLG (MHPCC)
+ * reworked by EAM (IfA)
  *
  * @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
@@ -27,24 +28,31 @@
 #include "psPolynomial.h"
 
-#define PS_LEFT_SPLINE_DERIV 0.0
-#define PS_RIGHT_SPLINE_DERIV 0.0
-
-/** One-Dimensional Spline */
+/** One-Dimensional Spline
+    This structure represents a 1D cubic spline.  Note the option for 
+    equally-spaced knots allows a quick selection of the correct spline 
+    segment.  The values (xMin, xMax, xDel) are stored for ease of access.
+ */
 typedef struct
 {
-    unsigned int n;                    ///< The number of spline pieces
-    psPolynomial1D **spline;           ///< An array of n pointers to the spline polynomials
-    psVector *knots;                   ///< The boundaries between each spline piece.  Size is n+1.
-    psF32 *p_psDeriv2;                 ///< For cubic splines, the second derivative at each domain point.  Size is n+1.
+    unsigned int n;    ///< The number of knots
+    psF32 *xKnots; ///< x-coordinate of the knots
+    psF32 *yKnots; ///< y-coordinate of the knots
+    psF32 *d2yKnots; ///< 2nd derivative of y at the knots
+    bool equalSpacing; // if knots are equally spaced, the seqment choice can be optimized
+    psF32 xMin; // for equally-spaced knots, the value at the lower bound (xKnots[0])
+    psF32 xMax; // for equally-spaced knots, the value at the upper bound (xKnots[n])
+    psF32 xDel; // for equally-spaced knots, the spacing (xKnots[n] - xKnots[0])/n
 }
 psSpline1D;
 
-/** Allocates a psSpline1D structure
- *
- *  Allocator for psSpline1D.
+/** Allocator for psSpline1D.
  *
  *  @return psSpline1D*    new 1-D spline struct
  */
 psSpline1D *psSpline1DAlloc(void) PS_ATTR_MALLOC;
+
+/** Create an empty 1D spline **/
+psSpline1D *psSpline1DCreate(
+    int nKnots);			///< number of knots
 
 /** Evaluates 1-D spline polynomials at a specific coordinate.
@@ -53,5 +61,15 @@
  */
 float psSpline1DEval(
-    const psSpline1D *spline,          ///< Coefficients for spline polynomials
+    const psSpline1D *spline,          ///< spline pointer
+    float x                            ///< location at which to evaluate
+);
+
+/** Evaluates 1-D spline polynomials at a specific coordinate.
+ *
+ *  @return float    result of spline polynomials evaluated at given location
+ */
+float psSpline1DEval_Segment(
+    const psSpline1D *spline,          ///< spline pointer
+    int n,			       // choice of segment
     float x                            ///< location at which to evaluate
 );
@@ -71,9 +89,13 @@
  *  generates the linear splines which satisfy those data points.
  *
+ *  XXX EAM: add option to generate / select a subset of knots from the data
+ *
  *  @return psSpline1D*:  the calculated one-dimensional splines
  */
-psSpline1D *psVectorFitSpline1D(
+psSpline1D *psSpline1DFitVector(
     const psVector* x,                 ///< Ordinates (or NULL to just use the indices)
-    const psVector* y                  ///< Coordinates
+    const psVector* y,                  ///< Coordinates.
+    psF32 dyLower,			///< 1st derivative at lower bound
+    psF32 dyUpper			///< 1st derivative at upper bound
 );
 
@@ -87,4 +109,10 @@
     psPtr ptr                          ///< the pointer whose type to check
 );
+
+// check for equal spacing and set internal boolean if true
+bool psSpline1DisEqualSpacing (psSpline1D *spline);
+
+// convert the cubic spline elements to a simply ordinary polynomial for segment n
+psPolynomial1D *psSpline1DToPoly (psSpline1D *spline, int n);
 
 /*****************************************************************************
