Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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());
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top