コード例 #1
0
            public void TrimOff(ChunkSolutionRect other)
            {
                if (other.HasAll(this))
                {
                    throw new ArgumentException("The other chunk completely encloses this one.  Trimming off intersections, will leave nothing");
                }

                if (this.IsOverlap(other))
                {
                    //how to do a set subtraction, based simply on x,y,w,h of 2 rect...
                    //simply just find which edge intersects with this rectangle and "chop" off in direction of inside the rectangle
                    //var clearright = this.RightCol < other.Col;
                    //var clearbottom = this.BottomRow < other.Row;
                    //var cleartop = this.Row > other.BottomRow;
                    //var clearleft = this.Col > other.RightCol;

                    var topinside    = this.Row < other.Row && other.Row <= this.BottomRow;
                    var bottominside = this.Row <= other.BottomRow && other.BottomRow < this.BottomRow;
                    var leftinside   = this.Col < other.Col && other.Col <= this.RightCol;
                    var rightinside  = this.Col <= other.RightCol && other.RightCol < this.RightCol;

                    if (leftinside) //left edge of other is inside right border, so erase everything of this, right of other's border
                    {
                        this.ColWidth = this.Col - other.Col - 1;
                    }
                    if (topinside)//top edge of other is inside bottom border, so erase everything of this, bottom of other's border
                    {
                        this.RowHeight = this.Row - other.Row - 1;
                    }
                    if (rightinside)
                    {
                        var right = this.RightCol;
                        this.ColWidth = this.RightCol - other.RightCol;
                        this.Col      = other.RightCol + 1; // other.Col - this.ColWidth - 1;
                        System.Diagnostics.Debug.Assert(this.ColWidth > 0, "this is obvious, the width still has to be >0");
                        System.Diagnostics.Debug.Assert(right == this.RightCol, "these should still be the same");
                        System.Diagnostics.Debug.Assert(other.RightCol < this.Col, "the current left edge should be distinct from other's right");
                    }
                    if (bottominside)
                    {
                        var bottom = this.BottomRow;
                        this.RowHeight = this.BottomRow - other.BottomRow;
                        this.Row       = other.BottomRow + 1;
                        System.Diagnostics.Debug.Assert(this.RowHeight > 0, "this is obvious, the height still has to be >0");
                        System.Diagnostics.Debug.Assert(bottom == this.BottomRow, "these should still be the same");
                        System.Diagnostics.Debug.Assert(other.BottomRow < this.Row, "the current top edge should be distinct from other's bottom");
                    }
                }
            }