-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolygon.cpp
58 lines (49 loc) · 1.16 KB
/
polygon.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
/*
* polygon.cpp
* 4/13/2016
*
* CS 372 Sp16
* Group Project 2: Postscript Generator
*/
#include "polygon.h"
/**
* @brief generates ps code for drawing a polygon
* @details returns a string containing the ps code for drawing any equilateral polygon
* @return string containing ps code
*/
string Polygon::draw() const
{
return draw(x_,y_);
}
/**
* @brief generates ps code for drawing a polygon
* @details returns a string containing the ps code for drawing any equilateral polygon
*
* @param x x position of center
* @param y y position of center
*
* @return string containing ps code
*/
string Polygon::draw(int x,int y) const{
stringstream ss;
ss << psHeader(x,y);
double vertexX = calcX(0,numOfSides_,sideLength_);
double vertexY = calcY(0,numOfSides_,sideLength_);
ss << psMove(vertexX,vertexY);
for(int i = 1; i < numOfSides_; i++){
vertexX = calcX(i,numOfSides_,sideLength_);
vertexY = calcY(i,numOfSides_,sideLength_);
ss << psLine(vertexX,vertexY);
}
ss << psFooter();
return ss.str();
}
int Polygon::numOfSides(){
return numOfSides_;
}
double Polygon::sideLength(){
return sideLength_;
}
double Polygon::radius(){
return radius_;
}