Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
below code is given for me to test. it shows error that it cannot resolve rect.x, rect.y, rect.width, rect.height. how to solve it?



static Rectangle2D rotateRect (RectangularShape rect, int angle, Point2D pivot = null )
{



if (pivot == null)
{
pivot = new Point2D.Double(rect.x + (int) Math.round(rect.width / 2d), rect.y + (int) Math.round(rect.height / 2d));
}

double rad = angle * Math.PI / 180;
double diffX = rect.x - pivot.x;
double diffY = rect.y - pivot.y;
int x = (int) Math.round(rect.x - diffX + (diffX * Math.cos(rad)) + (diffY * Math.sin(rad)));
int y = (int) Math.round(rect.y - diffY + (diffY * Math.cos(rad)) - (diffX * Math.sin(rad)));

return new Rectangle2D.Double(x, y, rect.width, rect.height);
}

What I have tried:

I tried tried to declare x and y but even it shows error
Posted
Updated 10-Dec-19 0:51am

The RectangularShape[^] class has not such properties. However it does provide the getX and getY methods. As an alternative (depending upon your needs) you might call the getBounds method, which returns a Rectangle which, in turn, provides the X, Y properties.
 
Share this answer
 
Please do not repost the same question. Here is another link so you can see why these fields cannot be resolved. RectangularShape (Java Platform SE 7 )[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900