Math Bing映射了如何获得两个位置矩形的公共正方形

Math Bing映射了如何获得两个位置矩形的公共正方形,math,geometry,bing-maps,Math,Geometry,Bing Maps,我有两个矩形,第一个是当前地图边界,第二个是前一个地图边界(移动前): 我怎样才能得到它们的公共平方? 用数学术语(我认为)它意味着它们之间的相交?伪代码: Rectangle { left, top, right, bottom } Rectangle Intersection(Rectangle A, Rectangle B) { return Rectangle { left = max(A.left, B.left),

我有两个矩形,第一个是当前地图边界,第二个是前一个地图边界(移动前):

我怎样才能得到它们的公共平方? 用数学术语(我认为)它意味着它们之间的相交?

伪代码:

Rectangle
{
    left,
    top,
    right,
    bottom
}

Rectangle Intersection(Rectangle A, Rectangle B)
{
    return Rectangle
    {
        left = max(A.left, B.left),
        top = max(A.top, B.top),
        right = min(A.right, B.right),
        bottom = min(A.bottom, B.bottom)
    }
}
这假设Y值从上到下递增。如果相反,只需切换
min
/
max
调用
top
bottom

Rectangle
{
    left,
    top,
    right,
    bottom
}

Rectangle Intersection(Rectangle A, Rectangle B)
{
    return Rectangle
    {
        left = max(A.left, B.left),
        top = max(A.top, B.top),
        right = min(A.right, B.right),
        bottom = min(A.bottom, B.bottom)
    }
}