-
Notifications
You must be signed in to change notification settings - Fork 1
/
layered.cpp
131 lines (104 loc) · 2.58 KB
/
layered.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* layered.cpp
* 4/15/2016
*
* CS 372 Sp16
* Group Project 2: Postscript Generator
*/
#include "layered.h"
/**
* @brief Layered constructor
* @details constructs a Layered shape from a list of shapes
*
* @param x x position of center
* @param y y position of center
* @param shapes list of pointers to Shapes
*/
Layered::Layered(int x, int y, initializer_list<Shape*> shapes) : Shape(x,y), shapes_(shapes) {
double width=0,height=0;
for(auto shape: shapes_){
width = max(width,shape->width());
height = max(height,shape->height());
}
boundsWidth_ = width;
boundsHeight_ = height;
}
string Layered::draw() const{
return draw(x_,y_);
}
string Layered::draw(int x, int y) const{
stringstream ss;
ss << psHeader(x,y);
for(auto shape: shapes_){
ss << shape->draw(0,0) << "\n";
}
ss << psFooter();
return ss.str();
}
/**
* @brief Horizontal costructor
* @details constructs a Horizontal shape from a list of Shapes
*
* @param x x position of center
* @param y y position of center
* @param shapes list of pointers to Shapes
*/
Horizontal::Horizontal(int x, int y, initializer_list<Shape*> shapes) : Layered(x,y,shapes){
double width=0,height=0;
for(auto shape: shapes_){
width += shape->width();
height = max(height,shape->height());
}
boundsWidth_ = width;
boundsHeight_ = height;
}
string Horizontal::draw() const{
return draw(x_,y_);
}
string Horizontal::draw(int x, int y) const{
stringstream ss;
ss << psHeader(x,y);
double half = boundsWidth_/2;
for(auto shape: shapes_){
ss << shape->draw( half-(shape->width()/2), 0) << "\n";
half -= shape->width();
}
ss << psFooter();
return ss.str();
}
/**
* @brief Vertical constructor
* @details constructs a Vertical shape from a list of Shapes
*
* @param x x position of center
* @param y y position of center
* @param shapes list of pointers to Shapes
*/
Vertical::Vertical(int x, int y, initializer_list<Shape*> shapes) : Layered(x,y,shapes){
double width=0,height=0;
for(auto shape: shapes_){
width = max(width,shape->width());
height += shape->height();
}
boundsWidth_ = width;
boundsHeight_ = height;
}
string Vertical::draw() const{
return draw(x_,y_);
}
string Vertical::draw(int x, int y) const{
stringstream ss;
ss << psHeader(x,y);
double half = boundsHeight_/2;
for(auto shape: shapes_){
string name = string(typeid(*shape).name()).substr(1);
if(name == "Triangle"){
ss << shape->draw(0, half-(shape->radius())) << "\n";
} else {
ss << shape->draw(0, half-(shape->height()/2) ) << "\n";
}
half -= shape->height();
}
ss << psFooter();
return ss.str();
}