/******************************************
*
* Cedric Pradalier 2001
* mail : http://cedric.pradalier.free.fr/mail.html
*
*****************************************/
#include "Rectangle.h"
#include <stdio.h>
#include <math.h>
void Rectangle::Print(FILE * fp)
{
fprintf(fp,"{ P = (%3.2f,%3.2f) ; Theta = %3.2f ; Width = %3.2f ; Height = %3.2f }\n",
x,y,theta,width,height);
}
Rectangle::Rectangle(FILE *fp)
{
x = y = theta = 0;
width = height = 1;
fscanf(fp,"{ P = (%le,%le) ; Theta = %le ; Width = %le ; Height = %le } ",
&x,&y,&theta,&width,&height);
}
Rectangle::Rectangle(const Rectangle & r, const Transform & t)
{
theta = r.theta + t.getRotationAngle();
width = r.width * t.getXScale();
height = r.height * t.getYScale();
x = r.x + t.getXTrans()*r.width*cos(r.theta)
- t.getYTrans()*r.height*sin(r.theta);
y = r.y + t.getXTrans()*r.width*sin(r.theta)
+ t.getYTrans()*r.height*cos(r.theta);
}
void Rectangle::Draw(XWin * win)
{
double s = sin(theta);
double c = cos(theta);
double wc = width * c, ws = width * s;
double hc = height * c, hs = height * s;
win->DrawLine(y,x,y+ws,x+wc);
win->DrawLine(y,x,y+hc,x-hs);
win->DrawLine(y+hc,x-hs,y+hc+ws,x-hs+wc);
win->DrawLine(y+ws,x+wc,y+hc+ws,x-hs+wc);
}