Question

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?

Was it helpful?

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.

OTHER TIPS

Try setting the rect before you rotate:

Instead of this:

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

Try this:

matrix.mapRect(myRect);    
matrix.setRotate(45,myRect.exactCenterX(), myRect.exactCenterY());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top