SuperMap.WindowsPhone.Core.Rectangle2D.Intersect C# (CSharp) Method

Intersect() public method

${WP_core_Rectangle2D_method_intersect_D}
public Intersect ( Rectangle2D rect ) : Rectangle2D
rect Rectangle2D ${WP_core_Rectangle2D_method_intersect_param_rect}
return Rectangle2D
        public Rectangle2D Intersect(Rectangle2D rect)
        {
            if (!this.IntersectsWith(rect))
            {
                return Rectangle2D.Empty;
            }
            else
            {
                Rectangle2D clone = this.Clone();
                double maxLeft = Math.Max(this.Left, rect.Left);
                double maxBottom = Math.Max(this.Bottom, rect.Bottom);
                clone._width = Math.Max((Math.Min(this.Right, rect.Right) - maxLeft), (double)0.0);
                clone._height = Math.Max((Math.Min(this.Top, rect.Top) - maxBottom), (double)0.0);
                clone._x = maxLeft;
                clone._y = maxBottom;
                return clone;
            }
        }

Usage Example

Example #1
0
        //由bounds获取tile的起始和结束行列号
        //[startColumn,startRow,endColumn,endRow] //Returns [0,0,-1,-1] if fails
        private int[] GetTileSpanWithin(Rectangle2D bounds, double resolution)
        {
            Rectangle2D temp = bounds.Intersect(this.Bounds);
            if (!Rectangle2D.IsNullOrEmpty(temp))
            {
                double x = this.Origin.X;
                double y = this.Origin.Y;

                int startColumn = (int)Math.Floor((double)(((temp.Left - x) + (resolution * 0.5)) / (resolution * this.TileSize)));
                int startRow = (int)Math.Floor((double)(((y - temp.Top) + (resolution * 0.5)) / (resolution * this.TileSize)));
                int endColumn = (int)Math.Floor((double)(((temp.Right - x) - (resolution * 0.5)) / (resolution * this.TileSize)));
                int endRow = (int)Math.Floor((double)(((y - temp.Bottom) - (resolution * 0.5)) / (resolution * this.TileSize)));
                return new int[] { startColumn, startRow, endColumn, endRow };

            }
            return new int[4] { 0, 0, -1, -1 };
        }