public ITicksInfo <T> GetTicks(Range <T> range, int ticksCount)
        {
            T            start = range.Min;
            T            end   = range.Max;
            DifferenceIn diff  = Difference;

            start = RoundDown(start, end);
            end   = RoundUp(start, end);

            RoundingInfo bounds = RoundHelper.CreateRoundedRange(
                GetSpecificValue(start, start),
                GetSpecificValue(start, end));

            int delta = (int)(bounds.Max - bounds.Min);

            if (delta == 0)
            {
                return new TicksInfo <T> {
                           Ticks = new T[] { start }
                }
            }
            ;

            int step = delta / ticksCount;

            if (step == 0)
            {
                step = 1;
            }

            T    tick          = GetStart(start, (int)bounds.Min, step);
            bool isMinDateTime = IsMinDate(tick) && step != 1;

            if (isMinDateTime)
            {
                step--;
            }

            List <T> ticks      = new List <T>();
            T        finishTick = AddStep(range.Max, step);

            while (Continue(tick, finishTick))
            {
                ticks.Add(tick);
                tick = AddStep(tick, step);
                if (isMinDateTime)
                {
                    isMinDateTime = false;
                    step++;
                }
            }

            ticks = Trim(ticks, range);

            TicksInfo <T> res = new TicksInfo <T> {
                Ticks = ticks.ToArray(), Info = diff
            };

            return(res);
        }
Exemple #2
0
        public sealed override ITicksInfo <DateTime> GetTicks(Range <DateTime> range, int ticksCount)
        {
            DateTime start  = range.Min;
            DateTime end    = range.Max;
            TimeSpan length = end - start;

            bool         isPositive = length.Ticks > 0;
            DifferenceIn diff       = difference;

            DateTime newStart = isPositive ? RoundDown(start, diff) : SafelyRoundUp(start);
            DateTime newEnd   = isPositive ? SafelyRoundUp(end) : RoundDown(end, diff);

            RoundingInfo bounds = RoundHelper.CreateRoundedRange(GetSpecificValue(newStart, newStart), GetSpecificValue(newStart, newEnd));

            int delta = (int)(bounds.Max - bounds.Min);

            if (delta == 0)
            {
                return new TicksInfo <DateTime> {
                           Ticks = new DateTime[] { newStart }
                }
            }
            ;

            int step = delta / ticksCount;

            if (step == 0)
            {
                step = 1;
            }

            DateTime tick          = GetStart(newStart, (int)bounds.Min, step);
            bool     isMinDateTime = IsMinDate(tick) && step != 1;

            if (isMinDateTime)
            {
                step--;
            }

            List <DateTime> ticks      = new List <DateTime>();
            DateTime        finishTick = AddStep(range.Max, step);

            while (tick < finishTick)
            {
                ticks.Add(tick);
                tick = AddStep(tick, step);
                if (isMinDateTime)
                {
                    isMinDateTime = false;
                    step++;
                }
            }

            TicksInfo <DateTime> res = new TicksInfo <DateTime> {
                Ticks = ticks.ToArray(), Info = diff
            };

            return(res);
        }