PageRenderTime 22ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 0ms 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
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5
 6namespace Microsoft.Research.DynamicDataDisplay.Charts.Axes.Numeric
 7{
 8	internal sealed class NumericConversion
 9	{
10		private readonly double min;
11		private readonly double length;
12		private readonly double minValue;
13		private readonly double valueLength;
14
15		public NumericConversion(double min, double minValue, double max, double maxValue)
16		{
17			this.min = min;
18			this.length = max - min;
19
20			this.minValue = minValue;
21			this.valueLength = maxValue - minValue;
22		}
23
24		public double FromDouble(double value)
25		{
26			double ratio = (value - min) / length;
27
28			return minValue + ratio * valueLength;
29		}
30
31		public double ToDouble(double value)
32		{
33			double ratio = (value - minValue) / valueLength;
34
35			return min + length * ratio;
36		}
37	}
38}