PageRenderTime 23ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Axes/Numeric/NumericConversion.cs

#
C# | 38 lines | 31 code | 7 blank | 0 comment | 0 complexity | fb651af8eb8b96c747e2ff248abab7a5 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Microsoft.Research.DynamicDataDisplay.Charts.Axes.Numeric
  6. {
  7. internal sealed class NumericConversion
  8. {
  9. private readonly double min;
  10. private readonly double length;
  11. private readonly double minValue;
  12. private readonly double valueLength;
  13. public NumericConversion(double min, double minValue, double max, double maxValue)
  14. {
  15. this.min = min;
  16. this.length = max - min;
  17. this.minValue = minValue;
  18. this.valueLength = maxValue - minValue;
  19. }
  20. public double FromDouble(double value)
  21. {
  22. double ratio = (value - min) / length;
  23. return minValue + ratio * valueLength;
  24. }
  25. public double ToDouble(double value)
  26. {
  27. double ratio = (value - minValue) / valueLength;
  28. return min + length * ratio;
  29. }
  30. }
  31. }