intersect static method
Creates a new rectangle that is the intersection of a
and b
.
.----------.
| a |
| .--------+----.
| | result | b |
| | | |
'-+--------' |
| |
'-------------'
Implementation
static Rect intersect(Rect a, Rect b) {
final left = math.max(a.left, b.left);
final right = math.min(a.right, b.right);
final top = math.max(a.top, b.top);
final bottom = math.min(a.bottom, b.bottom);
final width = math.max(0, right - left);
final height = math.max(0, bottom - top);
return Rect(left, top, width, height);
}