/// <summary>
        /// Constructor - takes in the min and max values for the domain segment
        /// </summary>
        /// <param name="random">The random number generator implementation</param>
        /// <param name="min">The minimum value for the segment</param>
        /// <param name="max">The maximum value for the segment</param>
        /// <param name="increment">The "increment" of the range, e.g. min: 2, max: 9, step: 2, return 2, 4, 6, 8</param>
        public RangeDomainSegment(IRandom800_90 random, int min, int max, int increment = 1)
        {
            if (min >= max)
            {
                throw new ArgumentException($"{nameof(min)} must be less than {nameof(max)}");
            }
            if (increment < 1)
            {
                throw new ArgumentException($"{nameof(increment)} must be 1 or greater.");
            }
            if (max - min < increment)
            {
                throw new ArgumentException($"{nameof(increment)} cannot exceed the difference between {nameof(min)} and {nameof(max)}");
            }
            if ((max - min) % increment != 0)
            {
                throw new ArgumentException($"{nameof(min)} - {nameof(max)} mod {nameof(increment)} must be 0.");
            }

            _min = min;
            _max = max;

            _increment = increment;
            _random    = random;

            _originalMinMax = new RangeMinMax()
            {
                Minimum   = _min,
                Increment = _increment,
                Maximum   = _max
            };
        }
示例#2
0
        /// <summary>
        /// Gets the minimum and maximum for the entire <see cref="MathDomain"/> as <see cref="RangeMinMax"/>
        /// </summary>
        /// <returns></returns>
        public RangeMinMax GetDomainMinMax()
        {
            RangeMinMax minMax = null;

            foreach (var segment in DomainSegments)
            {
                var segmentMinMax = segment.RangeMinMax;

                if (minMax == null)
                {
                    minMax = new RangeMinMax()
                    {
                        Minimum   = segmentMinMax.Minimum,
                        Maximum   = segmentMinMax.Maximum,
                        Increment = segmentMinMax.Increment
                    };

                    continue;
                }

                if (segmentMinMax.Minimum < minMax.Minimum)
                {
                    minMax.Minimum = segmentMinMax.Minimum;
                }

                if (segmentMinMax.Maximum > minMax.Maximum)
                {
                    minMax.Maximum = segmentMinMax.Maximum;
                }
            }

            return(minMax);
        }