Ejemplo n.º 1
0
        /// <summary>
        /// Removes the supplied range of integers from the valid range collection. The valid range collection
        /// is updated as appropriate to remove the invalid integers
        /// </summary>
        /// <param name="invalidRange">The range of integers to remove from the valid integer collection</param>
        private void RemoveFromValidRange(Range<double> invalidRange)
        {
            foreach (Range<double> validRange in m_validRanges)
            {
                if (invalidRange.IsSubRangeOf(validRange))
                {
                    //check for matching boundaries. If we have some, we don't need to split the existing valid range
                    if (!(invalidRange.Min == validRange.Min || invalidRange.Max == validRange.Max))
                    {
                        //no matching boundaries, so need to split validRange. Add new valid range at high end of existing
                        //valid range
                        m_validRanges.Add(new Range<double>(invalidRange.Max + 1, validRange.Max));
                        validRange.Max = invalidRange.Min - 1;

                        break;
                    }

                }
                
                if (invalidRange.OverlapsHighEndOf(validRange))
                {
                    //reduce max of valid range
                    if (invalidRange.Min > 0)
                    {
                        validRange.Max = invalidRange.Min - 1;
                    }
                }

                if (invalidRange.OverlapsLowEndOf(validRange))
                {
                    //increase min of valid range
                    if (invalidRange.Max < Int32.MaxValue)
                    {
                        validRange.Min = invalidRange.Max + 1;
                    }
                }

            }
        }