package uk.ac.liv.comp285.cw1.shapes;
import java.awt.Graphics;
import uk.ac.liv.comp285.cw1.Shape;
public class Rectangle extends Shape {
public Rectangle(float x, float y, float width, float height) {
super();
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
private float x,y,width,height;
@Override
public float getArea() {
return(width*height);
}
@Override
public Point getLowerLeftPoint() {
return((new Point(x,y)).rotate(rotationOrigin, angle));
}
@Override
public Point getUpperRightPoint() {
return ((new Point(x+width,y+height)).rotate(rotationOrigin, angle));
}
@Override
public void render(Graphics g) {
Point p1=new Point(x,y).rotate(rotationOrigin, angle);
Point p2=new Point(x+width,y).rotate(rotationOrigin, angle);
Point p3=new Point(x+width,y+height).rotate(rotationOrigin, angle);
Point p4=new Point(x,y+height).rotate(rotationOrigin, angle);
int y1=(int)(g.getClipRect().height-p1.getY());
int y2=(int)(g.getClipRect().height-p2.getY());
int y3=(int)(g.getClipRect().height-p3.getY());
int y4=(int)(g.getClipRect().height-p4.getY());
g.drawLine((int)p1.getX(),(int) y1,(int)p2.getX(),y2);
g.drawLine((int)p2.getX(),y2,(int)p3.getX(),y3);
g.drawLine((int)p3.getX(),(int) y3,(int)p4.getX(),y4);
g.drawLine((int)p4.getX(),y4,(int)p1.getX(),y1);
}
}