-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.cpp
96 lines (82 loc) · 1.92 KB
/
Rectangle.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
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
/**
* Implementation of the Rectangle class.
*
* @author Francis BISSON
*/
// INCLUDES ////////////////////////////////////////////////////////////////////
#include "Point.hpp"
#include "Rectangle.h"
#include "Types.h"
// IMPLEMENTATION //////////////////////////////////////////////////////////////
Rectangle::Rectangle()
:Drawable()
,m_Position(0, 0)
,m_Width(0)
,m_Height(0)
{
}
Rectangle::Rectangle(const Point& position, Size width, Size height)
:Drawable()
,m_Position(position)
,m_Width(width)
,m_Height(height)
{
}
Rectangle::Rectangle(Coord x, Coord y, Size width, Size height)
:Drawable()
,m_Position(x, y)
,m_Width(width)
,m_Height(height)
{
}
Rectangle::~Rectangle()
{
}
void Rectangle::ResizeTo(Size width, Size height)
{
m_Width = width;
m_Height = height;
}
void Rectangle::ResizeBy(Size width, Size height)
{
m_Width += width;
m_Height += height;
}
void Rectangle::ResizeBy(double xFactor, double yFactor)
{
m_Width = (Size)(m_Width * xFactor);
m_Height = (Size)(m_Height * yFactor);
}
bool Rectangle::Contains(const Point& point) const
{
if((point.GetX() >= GetX()) && (point.GetX() <= (GetX() + GetWidth())))
{
if((point.GetY() >= GetY()) && (point.GetY() <= (GetY() + GetHeight())))
{
return true;
}
}
return false;
}
bool Rectangle::Contains(const Rectangle& rect) const
{
if(((rect.GetX() + rect.GetWidth()) >= GetX()) && (rect.GetX() <= (GetX() + GetWidth())))
{
if(((rect.GetY() + rect.GetHeight()) >= GetY()) && (rect.GetY() <= (GetY() + GetHeight())))
{
return true;
}
}
return false;
}
bool Rectangle::ContainsCompletely(const Rectangle& rect) const
{
if((rect.GetX() >= GetX()) && ((rect.GetX() + rect.GetWidth()) <= (GetX() + GetWidth())))
{
if((rect.GetY() >= GetY()) && ((rect.GetY() + rect.GetHeight()) <= (GetY() + GetHeight())))
{
return true;
}
}
return false;
}