SourceGrid.Range.Exclude C# (CSharp) Method

Exclude() public method

Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells)
public Exclude ( Range range ) : RangeRegion
range Range
return RangeRegion
        public RangeRegion Exclude(Range range)
        {
            RangeRegion excluded;

            Range intersection = Intersect(range);
            if (intersection.IsEmpty())
            {
                excluded = new RangeRegion(this);
            }
            else
            {
                excluded = new RangeRegion();

                //Top Left
                if (this.Start.Row < intersection.Start.Row &&
                    this.Start.Column < intersection.Start.Column)
                    excluded.Add( new Range(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1) );

                //Top
                if (this.Start.Row < intersection.Start.Row)
                    excluded.Add( new Range(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column) );

                //Top Right
                if (this.Start.Row < intersection.Start.Row &&
                    this.End.Column > intersection.End.Column)
                    excluded.Add( new Range(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row -1, this.End.Column) );

                //----------

                //Left
                if (this.Start.Column < intersection.Start.Column)
                    excluded.Add( new Range(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column -1) );

                //Right
                if (this.End.Column > intersection.End.Column)
                    excluded.Add( new Range(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column) );

                //--------

                //Bottom Left
                if (this.End.Row > intersection.End.Row &&
                    this.Start.Column < intersection.Start.Column)
                    excluded.Add( new Range(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1) );

                //Bottom
                if (this.End.Row > intersection.End.Row)
                    excluded.Add( new Range(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column) );

                //Bottom Right
                if (this.End.Row > intersection.End.Row &&
                    this.End.Column > intersection.End.Column)
                    excluded.Add( new Range(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column) );
            }

            return excluded;
        }