setTopLeftAndBottomRight method

void setTopLeftAndBottomRight(
  1. Coordinate point1,
  2. Coordinate point2
)

The order of the input parameters does not matter, coordinates are sorted based on comparison.

  • It is important that each of the four coordinates are ordered based on value, as a Rect never has negative width or height.

Implementation

void setTopLeftAndBottomRight(Coordinate point1, Coordinate point2)
{
  left = Math.min(point1.x, point2.x);
  top = Math.min(point1.y, point2.y);
  width = Math.max(point1.x, point2.x) - left;
  height = Math.max(point1.y, point2.y) - top;
}