private Point2DDouble[] CalcDistributionDataPoints(double[] valArr) { // Square root is a fairly good choice for automatically determining the category count based on number of values being analysed. // See http://en.wikipedia.org/wiki/Histogram (section: Number of bins and width). int categoryCount = (int)Math.Sqrt(valArr.Length); FrequencyDistributionData fdd = Utilities.CalculateDistribution(valArr, categoryCount); // Create array of distribution plot points. Point2DDouble[] pointArr = new Point2DDouble[fdd.FrequencyArray.Length]; double incr = fdd.Increment; double x = fdd.Min + (incr/2.0); for(int i=0; i<fdd.FrequencyArray.Length; i++, x+=incr) { pointArr[i].X = x; pointArr[i].Y = fdd.FrequencyArray[i]; } return pointArr; }
/// <summary> /// Updates an Point2DDouble array by sorting an array of values and copying the sorted values over the existing values in pointArr. /// Optionally creates the Point2DDouble array if it is null or is the wrong size. /// </summary> private void UpdateRankedDataPoints(double[] valArr, ref Point2DDouble[] pointArr) { // Sort values (largest first). Array.Sort(valArr, delegate(double x, double y) { if(x > y) { return -1; } if(x < y) { return 1; } return 0; }); // Ensure point cache is ready. if(null == pointArr || pointArr.Length != valArr.Length) { pointArr = new Point2DDouble[valArr.Length]; for(int i=0; i<valArr.Length; i++) { pointArr[i].X = i; pointArr[i].Y = valArr[i]; } } else { // Copy sorted values into _specieSizePointArray. for(int i=0; i<valArr.Length; i++) { pointArr[i].Y = valArr[i]; } } }