-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshape.hpp
165 lines (144 loc) · 4.65 KB
/
shape.hpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Matt Perry, Tailon Russell, Chenyi Ling, McKade Sorensen
// Based on Dr. Hartmans CPS2020 example
#ifndef SHAPE_HPP
#define SHAPE_HPP
#include <iostream>
#include <memory>
#include <initializer_list>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
//Enum for handling Angles.
enum class Angle { R90, R180, R270 };
class Shape {
public:
virtual ~Shape() = default;
virtual double getHeight() const = 0;
virtual double getWidth() const = 0;
virtual void genPostScript(std::ostream& os) const = 0;
};
//helper function for printing post script definition in shape.cpp
void printPostScript(std::ostream & os, const std::shared_ptr<Shape> & shape);
//Basic Shapes
std::shared_ptr<Shape> makeCircle(double radius);
std::shared_ptr<Shape> makeRectangle(double width, double height);
std::shared_ptr<Shape> makePolygon(int numSides, double length);
std::shared_ptr<Shape> makeTriangle(double length);
std::shared_ptr<Shape> makeSquare(double length);
std::shared_ptr<Shape> makeSpacer(double width, double height);
//Fancy Shapes
std::shared_ptr<Shape> makeRotatedShape(std::shared_ptr<Shape> s, Angle a);
std::shared_ptr<Shape> makeScaledShape(std::shared_ptr<Shape> s, double sx, double sy);
std::shared_ptr<Shape> makeLayeredShape(std::initializer_list<std::shared_ptr<Shape>> i);
std::shared_ptr<Shape> makeVerticalShape(std::initializer_list<std::shared_ptr<Shape>> i);
std::shared_ptr<Shape> makeHorizontalShape(std::initializer_list<std::shared_ptr<Shape>> i);
std::shared_ptr<Shape> makeCustom(double faceRadius, double eyesRadius, double mouthRadius);
class Custom : public Shape {
public:
Custom(double faceRadius, double eyesRadius, double mouthRadius);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
double _fRadius;
double _eRadius;
double _mRadius;
};
class Circle : public Shape {
public:
Circle(double radius);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
double _radius;
};
class Rectangle : public Shape {
public:
Rectangle(double width, double height);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
double _width;
double _height;
};
class Polygon : public Shape {
public:
Polygon(int numSides, double length);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
int _numSides;
double _length;
};
class Triangle : public Shape {
public:
Triangle(double length);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
double _length;
};
class Spacer : public Shape {
public:
Spacer(double width, double height);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
double _width;
double _height;
};
class RotatedShape : public Shape {
public:
RotatedShape(std::shared_ptr<Shape> s, Angle a);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
std::shared_ptr<Shape> _s;
int _a;
};
class ScaledShape : public Shape {
public:
ScaledShape(std::shared_ptr<Shape> s, double xscale, double yscale);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
std::shared_ptr<Shape> _s;
double _xscale;
double _yscale;
};
class LayeredShape : public Shape {
public:
LayeredShape(std::initializer_list<std::shared_ptr<Shape>> i);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
std::vector<std::shared_ptr<Shape>> _shapes;
};
class VerticalShape : public Shape {
public:
VerticalShape(std::initializer_list<std::shared_ptr<Shape>> i);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
std::vector<std::shared_ptr<Shape>> _shapes;
};
class HorizontalShape : public Shape {
public:
HorizontalShape(std::initializer_list<std::shared_ptr<Shape>> i);
double getHeight() const override;
double getWidth() const override;
void genPostScript(std::ostream& os) const override;
private:
std::vector<std::shared_ptr<Shape>> _shapes;
};
#endif