Index: /branches/eam_branch_20070830/psLib/src/math/psHistogram.c
===================================================================
--- /branches/eam_branch_20070830/psLib/src/math/psHistogram.c	(revision 14770)
+++ /branches/eam_branch_20070830/psLib/src/math/psHistogram.c	(revision 14771)
@@ -5,6 +5,6 @@
  *  @author GLG (MHPCC), EAM (IfA)
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-03-14 02:36:28 $
+ *  @version $Revision: 1.5.8.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-07 20:17:28 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -282,9 +282,27 @@
                 out->maxNum++;
             } else {
-                // If this is a uniform histogram, determining the correct
-                // number is trivial.
+                // If this is a uniform histogram, determining the correct bin
+                // number is almost trivial.  start with a guess from the uniform scale.
                 if (out->uniform == true) {
-                    float binSize = out->bounds->data.F32[1] - out->bounds->data.F32[0]; // Histogram bin size
+                    double binSize = out->bounds->data.F32[1] - out->bounds->data.F32[0]; // Histogram bin size
                     binNum = (inF32->data.F32[i] - out->bounds->data.F32[0]) / binSize;
+		    binNum = PS_MAX (binNum, 0);
+		    binNum = PS_MIN (binNum, numBins - 1);
+
+		    // we may slightly overshoot or undershoot.  creep up or down on the true bin
+		    if (inF32->data.F32[i] < out->bounds->data.F32[binNum]) {
+			psTrace("psLib.math", 6, "missed target bin, adjusting: %f vs %f to %f\n", inF32->data.F32[i], out->bounds->data.F32[binNum], out->bounds->data.F32[binNum+1]);
+			while ((inF32->data.F32[i] < out->bounds->data.F32[binNum]) && (binNum > 0)) {
+			    binNum --;
+			}
+			
+		    }
+		    if (inF32->data.F32[i] > out->bounds->data.F32[binNum+1]) {
+			psTrace("psLib.math", 6, "missed target bin, adjusting: %f vs %f to %f\n", inF32->data.F32[i], out->bounds->data.F32[binNum], out->bounds->data.F32[binNum+1]);
+			while ((inF32->data.F32[i] > out->bounds->data.F32[binNum+1]) && (binNum < numBins - 1)) {
+			    binNum ++;
+			}
+		    }
+
                     if (errorsF32) {
                         if (!UpdateHistogramBins(binNum, out, inF32->data.F32[i], errorsF32->data.F32[i])) {
