-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometry.h
More file actions
164 lines (119 loc) · 3.79 KB
/
Geometry.h
File metadata and controls
164 lines (119 loc) · 3.79 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
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
#ifndef GEOMETRY_H_
#define GEOMETRY_H_
#include <iostream>
#include <memory>
class Point; // forward declaration
class Shape {
public:
// Default constructor, just to make this release version compilable.
// If your implementation is correct this should be removed
Shape();
// Constructor specifying the depth of the object.
// If d is negative, throw a std::invalid_argument exception.
Shape(int d);
// Set depth of object to d. If d is negative, return false and
// do not update depth. Otherwise return true
bool setDepth(int d);
// Return the depth of object
int getDepth() const;
// Return the dimension of the object (0, 1 or 2)
int dim() const;
// Translate the object horizontally by x and vertically by y
void translate(float x, float y);
// Rotate the object 90 degrees around its centre
void rotate();
// Scale the object by a factor f relative to its centre.
// If f is zero or negative, throw a std::invalid-argument exception.
void scale(float f);
// Return true if the object contains p and false otherwise.
// Depths are ignored for purpose of comparison
bool contains(const Point& p) const;
// the constant pi
static constexpr double PI = 3.1415926;
protected:
private:
// add any protected/private member variables you need
};
class Point : public Shape {
public:
// Constructor. Depth defaults to 0
Point(float x, float y, int d=0);
// Return basic information (see assignment page)
float getX() const;
float getY() const;
private:
// add any member variables you need
};
class LineSegment : public Shape {
public:
// Constructor.
// If the two points have different depths, or have the same x- and
// y-coordinate, or if the line is not axis-aligned, throw a
// std::invalid_argument exception
LineSegment(const Point& p, const Point& q);
// Return basic information (see assignment page)
float getXmin() const;
float getXmax() const;
float getYmin() const;
float getYmax() const;
// Return the length of the line segment
float length() const;
private:
// add any member variables you need
};
class TwoDShape : public Shape {
public:
// Default constructor.
// Similar comment to Student default constructor applies
TwoDShape();
// Constructor specifying the depth d
TwoDShape(int d);
// Return the area of the object
float area() const;
protected:
private:
// add any protected/private member variables you need
};
class Rectangle : public TwoDShape {
public:
// Constructor.
// If the two points have different depths, or have the same x-
// and/or y-coordinate, throw a std::invalid_argument exception
Rectangle(const Point& p, const Point& q);
// Return basic information (see assignment page)
float getXmin() const;
float getYmin() const;
float getXmax() const;
float getYmax() const;
private:
// add any member variables you need
};
class Circle : public TwoDShape {
public:
// Constructor.
// If r is zero or negative, throw a std::invalid-argument exception.
Circle(const Point& c, float r);
// Return basic information (see assignment page)
float getX() const;
float getY() const;
float getR() const;
private:
// add any member variables you need
};
class Scene {
public:
// Constructor
Scene();
// Add the pointer to the collection of pointers stored
void addObject(std::shared_ptr<Shape> ptr);
// Set the drawing depth to d
void setDrawDepth(int d);
// Constants specifying the size of the drawing area
static constexpr int WIDTH = 60;
static constexpr int HEIGHT = 20;
private:
// add any member variables you need
// Draw objects as specified in the assignment page
friend std::ostream& operator<<(std::ostream& out, const Scene& s);
};
#endif /* GEOMETRY_H_ */