union method
Adds two rectangles together to create a new GRect object, by
filling in the horizontal and vertical space between the two
rectangles.
Note: The union method ignores rectangles with 0 as the
height or width value, such as:
var rect2:Rectangle = new Rectangle(300,300,50,0);
Implementation
GRect union(GRect toUnion) {
if (width == 0 || height == 0) {
return toUnion.clone();
} else if (toUnion.width == 0 || toUnion.height == 0) {
return clone();
}
final x0 = x > toUnion.x ? toUnion.x : x;
final x1 = right < toUnion.right ? toUnion.right : right;
final y0 = y > toUnion.y ? toUnion.y : y;
final y1 = bottom < toUnion.bottom ? toUnion.bottom : bottom;
return GRect(x0, y0, x1 - x0, y1 - y0);
}