-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.h
More file actions
55 lines (49 loc) · 1.36 KB
/
Copy pathShape.h
File metadata and controls
55 lines (49 loc) · 1.36 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
//
// Shape.h
//
#ifndef SHAPE_H
#define SHAPE_H
#include "Point.h"
#include <iostream>
class Circle;
class Rectangle;
class Shape
{
public:
virtual ~Shape(void) {}
virtual bool overlaps(const Shape& s) const = 0;
virtual bool overlaps(const Circle& r) const = 0;
virtual bool overlaps(const Rectangle& r) const = 0;
virtual bool fits_in(const Rectangle& r) const = 0;
virtual void draw(void) const = 0;
};
class Rectangle : public Shape
{
public:
Rectangle(void): position(Point(0,0)), width(0), height(0) {}
Rectangle(Point p, int w, int h) :
position(p), width(w), height(h) {}
virtual ~Rectangle(void);
virtual bool overlaps(const Shape& s) const;
virtual bool overlaps(const Circle& r) const;
virtual bool overlaps(const Rectangle& r) const;
virtual bool fits_in(const Rectangle& r) const;
virtual void draw(void) const;
const Point position; // position of the lower left corner
const int width, height;
};
class Circle : public Shape
{
public:
Circle(void): center(Point(0,0)), radius(0) {}
Circle(Point c, int r) : center(c),radius(r) {}
virtual ~Circle(void);
virtual bool overlaps(const Shape& s) const;
virtual bool overlaps(const Circle& r) const;
virtual bool overlaps(const Rectangle& r) const;
virtual bool fits_in(const Rectangle& r) const;
virtual void draw(void) const;
Point center;
int radius;
};
#endif