-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrotate.cpp
58 lines (45 loc) · 1.55 KB
/
rotate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* rotate.cpp
* 4/13/2016
*
* CS 372 Sp16
* Group Project 2: Postscript Generator
*/
#include "rotate.h"
Rotated::Rotated(Shape * shape, int angle): Shape(), shape_(shape), angle_(angle){
string name = string(typeid(*shape).name()).substr(1);
if(name == "Circle" || name == "Star"){
boundsWidth_ = shape->width();
boundsHeight_ = shape->height();
} else if (name == "Square" || name == "Rectangle" || name == "Rotated" || name == "Scaled"){
boundsWidth_ = (shape->height() * cos((M_PI/2)-angle*(M_PI/180))) + (shape->width() * sin((M_PI/2)-angle*(M_PI/180)));
boundsHeight_ = (shape->width() * cos((M_PI/2)-angle*(M_PI/180))) + (shape->height() * sin((M_PI/2)-angle*(M_PI/180)));
} else if (name == "Polygon" || name == "Triangle") {
double minX = shape->radius() * cos( angle*(M_PI/180) );
double maxX = minX;
double minY = shape->radius() * sin( angle*(M_PI/180) );
double maxY = minY;
for(int i = 1; i < shape->numOfSides(); i++){
double tempX = shape->radius() * cos( angle*(M_PI/180) + (2*i*M_PI)/shape->numOfSides() );
minX = min(minX,tempX);
maxX = max(maxX,tempX);
double tempY = shape->radius() * sin( angle*(M_PI/180) + (2*i*M_PI)/shape->numOfSides() );
minY = min(minY,tempY);
maxY = max(maxY,tempY);
}
boundsWidth_ = maxX - minX;
boundsHeight_ = maxY - minY;
}
}
string Rotated::draw() const{
return draw(shape_->x(),shape_->y());
}
string Rotated::draw(int x, int y) const
{
stringstream ss;
ss << psHeader(x,y);
ss << angle_ << " rotate\n";
ss << (*shape_)(0,0);
ss << psFooter();
return ss.str();
}