-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwill_test2.cpp
More file actions
108 lines (81 loc) · 3.07 KB
/
Copy pathwill_test2.cpp
File metadata and controls
108 lines (81 loc) · 3.07 KB
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
// CS 372 Project 2
// CPS: C++ to PostScript
// Noah Betzen, William Showalter, Saira Walia
// main.cpp
// main.cpp is the release suite
// test.cpp is the test/debug suite
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <sstream>
#include <fstream>
using std::stringstream;
using std::ifstream;
using std::ofstream;
#include <cstdio>
using std::remove;
#include <memory>
using std::make_shared;
using std::make_unique;
using std::shared_ptr;
#include "classes/Shape.h"
#include "classes/CompoundShape.h"
#include "classes/Polygon.h"
#include "classes/Rectangle.h"
#include "classes/Circle.h"
#include "classes/ShapeDecorator.h"
#include "classes/Layered.h"
#include "classes/Horizontal.h"
#include "classes/Vertical.h"
void writePostScriptToFile(Shape *shape, string fileName)
{
stringstream shapePostScript(shape->getPostScript());
ofstream outputFile(fileName, std::ios_base::app);
string temp;
while (std::getline(shapePostScript,temp))
{
outputFile << temp << "\n";
}
outputFile << "showpage\n\n";
outputFile.close();
}
int main(int argc, char*argv[])
{
Shape::flipDrawBoundingBox(); // turns on drawing of bounding boxes
Polygon polygon1(9, 72); // 9 sides, each side is 72 in length
Polygon polygon2(13, 72); // 9 sides, each side is 72 in length
Circle circle1(72); // radius is 72
Rectangle rectangle1(72, 144); // width 72, height 144
/*shared_ptr<Shape> layered1 = make_shared<Layered>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72), make_shared<Polygon>(9,72)}));
*/
shared_ptr<Shape> vertical1 = make_shared<Vertical>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72/2), make_shared<Polygon>(9,72/2),
make_shared<Rectangle>(72/2,144/2), make_shared<Polygon>(5,72/2)}));
shared_ptr<Shape> horizontal1 = make_shared<Horizontal>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72/2), make_shared<Polygon>(9,72/2),
make_shared<Rectangle>(72/2,144/2), make_shared<Polygon>(5,72/2)}));
shared_ptr<Shape> vertical2 = make_shared<Vertical>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72/2), make_shared<Polygon>(9,72/2),
make_shared<Rectangle>(72/2,144/2), make_shared<Polygon>(5,72/2)}));
shared_ptr<Shape> horizontal2 = make_shared<Horizontal>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72/2), make_shared<Polygon>(9,72/2),
make_shared<Rectangle>(72/2,144/2), make_shared<Polygon>(5,72/2)}));
/*shared_ptr<Shape> horizontal3 = make_shared<Horizontal>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72/2)}));
*/
shared_ptr<Shape> horizontalVerticalStack =
make_shared<Horizontal>(std::initializer_list<shared_ptr<Shape>>
({horizontal2,vertical2}));
string fileName = "experiment.ps";
if(ifstream(fileName)) // if the file exists
{
remove("experiment.ps"); // delete it
}
writePostScriptToFile(vertical1.get(), fileName);
writePostScriptToFile(horizontal1.get(), fileName);
writePostScriptToFile(horizontalVerticalStack.get(), fileName);
return 0;
}