public void BinLowerTest() { UnitGroup ug = new UnitGroup(VolumeUnit.ImperialBeerBarrel, AreaUnit.SquareInch, LengthUnit.Foot, LengthUnit.Meter); Histogram rTest1 = new Histogram(20, 1); Assert.AreEqual(rTest1.BinLower(0, ug).As(ug.VertUnit), -10); Assert.AreEqual(rTest1.BinLower(19, ug).As(ug.VertUnit), 9); Histogram rTest2 = new Histogram(1, decimal.MaxValue); Assert.AreEqual(rTest2.BinLower(0, ug).As(ug.VertUnit), (double)decimal.MinValue); Assert.AreEqual(rTest2.BinLower(1, ug).As(ug.VertUnit), 0); }
public void ReadWriteFileSpecialCaseTest() { // Write to a file then read it to see if we get the same thing Histogram rTest1 = new Histogram(1, decimal.MaxValue); //Add some fake values into the mix rTest1.AddBinVal(-5); rTest1.AddBinVal(7.123); // First try it with a real file using (ITempDir tmp = TempDir.Create()) { UnitGroup ug = new UnitGroup(VolumeUnit.CubicMeter, AreaUnit.SquareMeter, LengthUnit.Meter, LengthUnit.Meter); Area cellArea = Area.From(0.2 * 0.3, ug.ArUnit); FileInfo fPath = new FileInfo(Path.Combine(tmp.Name, "myHistogram.csv")); rTest1.WriteFile(fPath, cellArea, ug); Histogram rTestRead = new Histogram(fPath); // Make sure the two histograms have the same edges and width Assert.AreEqual(rTest1.Count, rTest1.Count); Assert.AreEqual(rTest1.HistogramLower(ug).Meters, rTest1.HistogramLower(ug).Meters); Assert.AreEqual(rTest1.HistogramUpper(ug).Meters, rTest1.HistogramUpper(ug).Meters); Assert.AreEqual(rTest1._binWidth, rTest1._binWidth); // Now go bin-by-bin to make sure we end up with the same numbers everywhere for (int bid = 0; bid < rTestRead.Count; bid++) { Assert.AreEqual(rTest1.BinCounts[bid], rTestRead.BinCounts[bid]); Assert.AreEqual(rTest1.BinArea(bid, cellArea).SquareMeters, rTestRead.BinArea(bid, cellArea).SquareMeters); Assert.AreEqual(rTest1.BinLower(bid, ug).Meters, rTestRead.BinLower(bid, ug).Meters); } } }
public void UpdateDisplay(bool bArea, GCDConsoleLib.GCD.UnitGroup displayUnits = null) { // Store the display units so that the user can switch between area and volume easily if (displayUnits != null) { DisplayUnits = displayUnits; } // Go recalc our values GetDisplayValues(bArea); Chart.Series.FindByName(EROSION).Points.DataBindXY(histoData.Values, "Elevation", histoData.Values, "Erosion"); Chart.Series.FindByName(DEPOSITION).Points.DataBindXY(histoData.Values, "Elevation", histoData.Values, "Deposition"); Chart.Series.FindByName(RAW).Points.DataBindXY(histoData.Values, "Elevation", histoData.Values, "Raw"); double binWidth = _thrHist.BinWidth(Project.ProjectManager.Project.Units).As(DisplayUnits.VertUnit); Axis axisX = Chart.ChartAreas[0].AxisX; axisX.Title = string.Format("Elevation Change ({0})", UnitsNet.Length.GetAbbreviation(DisplayUnits.VertUnit)); axisX.Minimum = _thrHist.BinLower(_thrHist.FirstBinId, Project.ProjectManager.Project.Units).As(DisplayUnits.VertUnit); axisX.Maximum = _thrHist.BinLower(_thrHist.LastBinId, Project.ProjectManager.Project.Units).As(DisplayUnits.VertUnit) + binWidth; axisX.MajorGrid.Interval = 10 * binWidth; axisX.MajorGrid.IntervalOffset = binWidth; axisX.Interval = 10 * binWidth; axisX.IntervalOffset = binWidth; axisX.MinorGrid.Interval = binWidth; if (bArea) { Chart.ChartAreas[0].AxisY.Title = string.Format("Area ({0})", UnitsNet.Area.GetAbbreviation(DisplayUnits.ArUnit)); } else { Chart.ChartAreas[0].AxisY.Title = string.Format("Volume ({0})", UnitsNet.Volume.GetAbbreviation(DisplayUnits.VolUnit)); } Chart.ChartAreas[0].RecalculateAxesScale(); Chart.ChartAreas[0].AxisY.RoundAxisValues(); }