Reputation: 9636
I have 2 rectangles which the first is the current map boundary and the second is the previous map boundary (before movement):
LocationRect currentBounds = map.Bounds; //the first.
LocationRect previousBounds --> //the second.
How can I get the common square of them? In math terms (I think) it means the intersect between them?
Upvotes: 0
Views: 95
Reputation: 79441
Pseudocode:
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)
}
}
This assumes that the Y values increase going from top to bottom. If the opposite is true, simply toggle the min
/max
calls for top
and bottom
.
Upvotes: 2