Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Axes/DateTime/DateTimeToDoubleConversion.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 981 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace Microsoft.Research.DynamicDataDisplay.Charts
7{
8  internal sealed class DateTimeToDoubleConversion
9  {
10    public DateTimeToDoubleConversion(double min, DateTime minDate, double max, DateTime maxDate)
11    {
12      this.min = min;
13      this.length = max - min;
14      this.ticksMin = minDate.Ticks;
15      this.ticksLength = maxDate.Ticks - ticksMin;
16    }
17
18    private double min;
19    private double length;
20    private long ticksMin;
21    private long ticksLength;
22
23    internal DateTime FromDouble(double d)
24    {
25      double ratio = (d - min) / length;
26      long tick = (long)(ticksMin + ticksLength * ratio);
27
28      tick = MathHelper.Clamp(tick, DateTime.MinValue.Ticks, DateTime.MaxValue.Ticks);
29
30      return new DateTime(tick);
31    }
32
33    internal double ToDouble(DateTime dt)
34    {
35      double ratio = (dt.Ticks - ticksMin) / (double)ticksLength;
36      return min + ratio * length;
37    }
38  }
39}
Note: See TracBrowser for help on using the repository browser.