Ejemplo n.º 1
0
        private doubleME ShrinkInterval(doubleME interval)
        {
            // go from 5 --> 2 --> 1 --> .5 --> .2 --> .1 etc
            switch (interval.Mantissa)
            {
            case 5:
                return(new doubleME(interval.Exponent, 2));

            case 2:
                return(new doubleME(interval.Exponent, 1));

            case 1:
                return(new doubleME(interval.Exponent - 1, 5));
            }
            throw new Exception();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a set of <see cref="MagicGridSpacings"/> based upon the provided inputs.
        /// </summary>
        /// <returns>A set of <see cref="MagicGridSpacings"/>.</returns>
        public MagicGridSpacings GetGridSpacings()
        {
            if (MinValue == MaxValue)
            {
                return(new MagicGridSpacings(MinValue - 1, 2 / MaxLines, MinValue + 1));
            }

            //find largest order of magnitude.
            int largestOrderOfMag = Math.Max(OrderOfMagnitude(MinValue),
                                             OrderOfMagnitude(MaxValue));

            doubleME interval = new doubleME(largestOrderOfMag + 1, 1);

            double upperLimit = 0, lowerLimit = 0;
            int    loopCount = 0;

            while (true)
            {
                var nextInterval = ShrinkInterval(interval);

                var nextUpperLimit = RoundUpTo(MaxValue, nextInterval.theDouble);
                var nextLowerLimit = RoundDownTo(MinValue, nextInterval.theDouble);

                var numNextIntervalsInRange = (nextUpperLimit - nextLowerLimit) / nextInterval.theDouble;

                if (numNextIntervalsInRange > MaxLines)
                {
                    //wrap it up.
                    if (loopCount == 0)
                    {
                        interval = new doubleME(interval.Exponent + 1, interval.Mantissa);
                        continue;
                    }
                    return(new MagicGridSpacings(lowerLimit, interval.theDouble, upperLimit));
                }

                //tighten it all up.
                interval   = nextInterval;
                upperLimit = nextUpperLimit;
                lowerLimit = nextLowerLimit;

                if (++loopCount > 100)
                {
                    throw new Exception();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a set of <see cref="MagicGridSpacings"/> based upon the provided inputs.
        /// </summary>
        /// <returns>A set of <see cref="MagicGridSpacings"/>.</returns>
        public MagicGridSpacings GetGridSpacings()
        {
            if (MinValue == MaxValue)
            {
                return new MagicGridSpacings(MinValue - 1, 2 / MaxLines, MinValue + 1);
            }

            //find largest order of magnitude.
            int largestOrderOfMag = Math.Max(OrderOfMagnitude(MinValue),
                                                OrderOfMagnitude(MaxValue));

            doubleME interval = new doubleME(largestOrderOfMag + 1, 1);

            double upperLimit = 0, lowerLimit = 0;
            int loopCount = 0;
            while (true)
            {
                var nextInterval = ShrinkInterval(interval);

                var nextUpperLimit = RoundUpTo(MaxValue, nextInterval.theDouble);
                var nextLowerLimit = RoundDownTo(MinValue, nextInterval.theDouble);

                var numNextIntervalsInRange = (nextUpperLimit - nextLowerLimit) / nextInterval.theDouble;

                if (numNextIntervalsInRange > MaxLines)
                {
                    //wrap it up.
                    if (loopCount == 0)
                    {
                        interval = new doubleME(interval.Exponent + 1, interval.Mantissa);
                        continue;
                    }
                    return new MagicGridSpacings(lowerLimit, interval.theDouble, upperLimit);
                }

                //tighten it all up.
                interval = nextInterval;
                upperLimit = nextUpperLimit;
                lowerLimit = nextLowerLimit;

                if (++loopCount > 100)
                    throw new Exception();
            }
        }
Ejemplo n.º 4
0
 private doubleME ShrinkInterval(doubleME interval)
 {
     // go from 5 --> 2 --> 1 --> .5 --> .2 --> .1 etc
     switch (interval.Mantissa)
     {
         case 5:
             return new doubleME(interval.Exponent, 2);
         case 2:
             return new doubleME(interval.Exponent, 1);
         case 1:
             return new doubleME(interval.Exponent - 1, 5);
     }
     throw new Exception();
 }