示例#1
0
        /// <summary>
        /// builds a range collection from two bounds and steps in between
        /// </summary>
        /// <param name="lowBound"></param>
        /// <param name="highBound"></param>
        /// <param name="rangeSteps"></param>
        /// <returns></returns>
        public static List <RangeBuilder> BuildRange(int lowBound, int highBound, int rangeSteps)
        {
            bool lowNegative = false;

            if (lowBound < 0)
            {
                lowBound   *= -1;
                lowNegative = true;
            }

            if ((lowBound / rangeSteps) > (2 * rangeSteps))
            {
                throw new CekaException("You should reconsider your rangeStep choice! " + (lowBound / rangeSteps) + " ranges yet alone from lowerBounds is too much!");
            }

            if ((highBound / rangeSteps + rangeSteps) > (2 * rangeSteps)) // +rangeSteps because we add it below via +(i * 1)
            {
                throw new CekaException("You should reconsider your rangeStep choice! " + (highBound / rangeSteps) + " ranges yet alone from upperBounds is too much!");
            }

            List <RangeBuilder> r = new List <RangeBuilder>();

            int          l  = 0;
            int          u  = 0;
            RangeBuilder rb = null;

            if (lowNegative)
            {
                lowBound *= -1;
            }
            int xv     = lowBound;
            int circle = 0;

            while (xv < highBound)
            {
                l   = xv + circle;
                xv += rangeSteps;
                u   = xv + circle;

                rb = new Helpers.RangeBuilder(l, u);
                r.Add(rb);
                circle++;
            }

            Helpers.Utils.Debug(string.Format("Built {0} ranges!", r.Count));

            return(r);
        }
示例#2
0
        /// <summary>
        /// builds a range collection from two bounds and steps in between
        /// </summary>
        /// <param name="lowBound"></param>
        /// <param name="highBound"></param>
        /// <param name="rangeSteps"></param>
        /// <returns></returns>
        public static List<RangeBuilder> BuildRange(int lowBound, int highBound, int rangeSteps)
        {
            bool lowNegative = false;
            if (lowBound < 0)
            {
                lowBound *= -1;
                lowNegative = true;
            }

            if ((lowBound / rangeSteps) > (2 * rangeSteps))
                throw new CekaException("You should reconsider your rangeStep choice! " + (lowBound / rangeSteps) + " ranges yet alone from lowerBounds is too much!");

            if ((highBound / rangeSteps + rangeSteps) > (2 * rangeSteps)) // +rangeSteps because we add it below via +(i * 1)
                throw new CekaException("You should reconsider your rangeStep choice! " + (highBound / rangeSteps) + " ranges yet alone from upperBounds is too much!");

            List<RangeBuilder> r = new List<RangeBuilder>();

            int l = 0;
            int u = 0;
            RangeBuilder rb = null;
            if(lowNegative)
                lowBound *= - 1;
            int xv = lowBound;
            int circle = 0;
            while (xv < highBound)
            {
                l = xv + circle;
                xv += rangeSteps;
                u = xv + circle;

                rb = new Helpers.RangeBuilder(l, u);
                r.Add(rb);
                circle++;
            }

            Helpers.Utils.Debug(string.Format("Built {0} ranges!", r.Count));

            return r;
        }