public static NumericSequence CalculateUnits(int min, int max, int?interval, int?intervalOffset, int[] steps, int maxCount) { maxCount = Math.Max(maxCount, 1); maxCount = Math.Min(maxCount, 1000); if (min == max) { max = min + 1; } int num1 = max - min; int num2 = 0; int num3 = 0; if (interval.HasValue) { int?nullable1 = interval; if ((nullable1.GetValueOrDefault() != 0 ? 0 : (nullable1.HasValue ? 1 : 0)) == 0) { int num4 = num1; int?nullable2 = interval; int?nullable3 = nullable2.HasValue ? new int?(num4 / nullable2.GetValueOrDefault()) : new int?(); if ((nullable3.GetValueOrDefault() <= 1000 ? 0 : (nullable3.HasValue ? 1 : 0)) == 0) { num3 = interval.Value; num2 = num1 / num3; goto label_12; } } } for (int index = 0; index < steps.Length; ++index) { num3 = steps[index]; int num4 = num1 / num3; if (num1 % num3 != 0) { ++num4; } if (num4 <= maxCount) { break; } } label_12: int num5 = -min; if (intervalOffset.HasValue) { num5 += intervalOffset.Value; } int num6 = num5 % num3; NumericSequence numericSequence = new NumericSequence(); int num7 = min + num6; while (true) { numericSequence._sequence.Add((DoubleR10)num7); if (num7 < max) { num7 += num3; } else { break; } } numericSequence.Interval = (DoubleR10)num3; numericSequence.IntervalOffset = (DoubleR10)num6; numericSequence.Minimum = numericSequence._sequence[0]; numericSequence.Maximum = numericSequence._sequence[numericSequence._sequence.Count - 1]; numericSequence.ExtendToCover((DoubleR10)min, (DoubleR10)max); return(numericSequence); }
public static NumericSequence Calculate(NumericRangeInfo range, double?interval = null, double?intervalOffset = null, int maxCount = 10, int minPower = -2147483648, DoubleR10[] steps = null, bool useZeroRefPoint = true, double maxAllowedMargin = 1.0) { NumericSequence numericSequence = new NumericSequence(); if (steps == null) { steps = NumericSequence.DefaultGridSteps; } long num1 = 0L; numericSequence._maxAllowedMargin = (DoubleR10)maxAllowedMargin; if (range.ForsedSingleStop.HasValue) { DoubleR10 doubleR10 = range.ForsedSingleStop.Value; numericSequence._interval = range.Maximum - range.Minimum; numericSequence._intervalOffset = doubleR10; numericSequence._min = range.Minimum; numericSequence._max = range.Maximum; numericSequence._sequence.Add(doubleR10); numericSequence.ExtendToCover(range.Minimum, range.Maximum); return(numericSequence); } numericSequence._interval = interval.HasValue ? (DoubleR10)Math.Abs(interval.Value) : DoubleR10.Zero; numericSequence._intervalOffset = intervalOffset.HasValue ? (DoubleR10)intervalOffset.Value : DoubleR10.MinValue; numericSequence._min = DoubleR10.Zero; numericSequence._max = DoubleR10.Zero; maxCount = Math.Max(maxCount, 1); maxCount = Math.Min(maxCount, 1000); numericSequence._canExtendMin = maxAllowedMargin > 0.0 && range.HasDataRange && !range.HasMin && range.Minimum != 0; numericSequence._canExtendMax = maxAllowedMargin > 0.0 && range.HasDataRange && !range.HasMax && range.Maximum != 0; if (interval.HasValue && numericSequence._interval != 0 && intervalOffset.HasValue) { num1 = (long)(range.Size / numericSequence._interval); numericSequence._min = range.Minimum; numericSequence._max = range.Minimum + (DoubleR10)num1 * numericSequence._interval; } else { int num2 = !(numericSequence._interval != 0) ? (!(range.Size != 0) ? range.Maximum.Log10() : range.Size.Log10()) : numericSequence._interval.Log10() + 1; int num3 = steps[0].Log10(); int num4 = num2 - num3 - 1 - ((DoubleR10)maxCount - (DoubleR10)1).Log10(); if (minPower != int.MinValue) { num4 = Math.Max(num4, minPower - num3); } if (numericSequence._interval != 0) { NumericRangeInfo numericRangeInfo = new NumericRangeInfo(DoubleR10.Floor(range.Minimum, num4), DoubleR10.Ceiling(range.Maximum, num4)); numericRangeInfo.ShrinkByStep(range, numericSequence._interval, useZeroRefPoint); numericSequence._min = numericRangeInfo.Minimum; numericSequence._max = numericRangeInfo.Maximum; num1 = DoubleR10.CountSteps(numericRangeInfo.Size, numericSequence._interval); } else { for (int index1 = 0; index1 < 3; ++index1) { int exp = num4 + index1; DoubleR10 doubleR10 = DoubleR10.Pow10(exp); DoubleR10 minimum = DoubleR10.Floor(range.Minimum, exp); DoubleR10 maximum = DoubleR10.Ceiling(range.Maximum, exp); for (int index2 = 0; index2 < steps.Length; ++index2) { DoubleR10 step = steps[index2] * doubleR10; step.Normalize(); NumericRangeInfo roundRange = new NumericRangeInfo(minimum, maximum); if (steps == NumericSequence.DefaultGridSteps) { roundRange.ShrinkByStepQuick(range, step); } else { roundRange.ShrinkByStep(range, step, useZeroRefPoint); } if (numericSequence._canExtendMin && range.Minimum == roundRange.Minimum && maxAllowedMargin >= 1.0) { roundRange.Minimum -= step; } if (numericSequence._canExtendMax && range.Maximum == roundRange.Maximum && maxAllowedMargin >= 1.0) { roundRange.Maximum += step; } num1 = NumericSequence.GetCount(range, roundRange, step, numericSequence._canExtendMin, numericSequence._canExtendMin, maxAllowedMargin, (long)maxCount); if (num1 <= (long)maxCount || index1 == 2 && index2 == steps.Length - 1) { numericSequence._interval = step; numericSequence._min = roundRange.Minimum; numericSequence._max = roundRange.Maximum; break; } } if (numericSequence._interval != 0) { break; } } } } if (num1 > (long)(maxCount * 32)) { num1 = (long)(maxCount * 32); numericSequence._interval = numericSequence.Size / (DoubleR10)num1; } if (intervalOffset.HasValue) { numericSequence._intervalOffset = numericSequence._intervalOffset % numericSequence._interval; DoubleR10 doubleR10 = range.Minimum + numericSequence._intervalOffset - numericSequence._min; numericSequence._min = numericSequence._min + doubleR10; numericSequence._max = numericSequence._max + doubleR10; } else { numericSequence._intervalOffset = numericSequence._min - range.Minimum; } numericSequence.FixDoubleOverflow(range); numericSequence._sequence = (IList <DoubleR10>) new List <DoubleR10>(); DoubleR10 doubleR10_1 = numericSequence._min; numericSequence._sequence.Add(doubleR10_1); for (int index = 0; (long)index < num1; ++index) { doubleR10_1 = doubleR10_1.Add(ref numericSequence._interval); if (!doubleR10_1.IsDoubleInfinity()) { numericSequence._sequence.Add(doubleR10_1); } } numericSequence.ExtendToCover(range.Minimum, range.Maximum); return(numericSequence); }