Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 1722)
+++ trunk/psLib/src/math/psStats.c	(revision 1823)
@@ -9,6 +9,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-08 06:04:30 $
+ *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-17 02:14:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1449,5 +1449,4 @@
 void p_ps_FitTheGaussian()
 {
- 
     // Fit a Gaussian to the bins in the range MODE-dL to Mode+dL
     // NOTE: This code uses the psMinimize.c functions to perform
@@ -1455,4 +1454,6 @@
     // I am commenting this code out, and replacing it with code which
     // calculates the mean directly on the robustHistogram.
+    //
+    // XXX: Replace this with the LaGrange interpolation stuff.
  
     domain = psImageAlloc(1, robustHistogramVector->n, PS_TYPE_F32);
@@ -1671,11 +1672,14 @@
 psHistogram* psVectorHistogram(psHistogram* out,
                                const psVector* restrict in,
-                               const psVector* restrict mask, unsigned int maskVal)
+                               const psVector* restrict mask,
+                               unsigned int maskVal)
 {
     int i = 0;                  // Loop index variable
-    int j = 0;                  // Loop index variable
     float binSize = 0.0;        // Histogram bin size
     int binNum = 0;             // A temporary bin number
     int numBins = 0;            // The total number of bins
+    int tmp = 0;
+    psScalar tmpScalar;
+    tmpScalar.type.type = PS_TYPE_F32;
 
     // NOTE: Verify that this is the correct action.
@@ -1708,4 +1712,5 @@
         }
     }
+
     // NOTE: determine the correct action for a variety of other cases:
     // in vector has 0 elements, and histogram structure has zero bins.
@@ -1742,11 +1747,11 @@
                     // bin number requires a bit more work.
                 } else {
-                    // NOTE: This is slow.  Put a smarter algorithm here to
-                    // find the correct bin number (bin search, probably)
-                    for (j = 0; j < (out->bounds->n) - 1; j++) {
-                        if ((out->bounds->data.S32[j] <= in->data.F32[i]) &&
-                                (in->data.F32[i] <= out->bounds->data.S32[j + 1])) {
-                            (out->nums->data.S32[j])++;
-                        }
+                    tmpScalar.data.F32 = in->data.F32[i];
+                    tmp = p_psVectorBinDisect(out->bounds,
+                                              &tmpScalar);
+                    if (tmp == -1) {
+                        //                      XXX: Generate warning message
+                    } else {
+                        (out->nums->data.S32[tmp])++;
                     }
                 }
