Search code examples
androidrect

Android: Rect actually represents two rectangles


A Rect has parameters left, top, right and bottom to represent a rectangle, but it actually represents two rectangles. See the diagram below:

enter image description here

When i rotated the rectangle on the left using:

matrix.setRotate(45,myRect.exactCenterX(), myRect.exactCenterY());
matrix.mapRect(myRect);

I was expecting the rectangle in Red color, but I got the one in Blue color. Because the same parameters (left, top, right, bottom) represents two rectangles.

Is this a problem with Android's Rect? How can I get the rectangle in the Red color?


Solution

  • Rect holds four integer coordinates for a rectangle. The rectangle is represented by the coordinates of its 4 edges (left, top, right bottom).

    The Rect class is basically just a set of the coordinates for left/top and right/bottom corner. It has no concept of rotation whatsoever.