-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.cpp
More file actions
83 lines (66 loc) · 1.94 KB
/
Rectangle.cpp
File metadata and controls
83 lines (66 loc) · 1.94 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
#define _CRT_SECURE_NO_WARNINGS
#include "Rectangle.h"
#include <iostream>
using namespace std;
int Rectangle::m_count = 0;
//C'tor
Rectangle::Rectangle(double left, double top, double width, double height, int color)
{
//Defining the points of the rectangle and color
TopLeft.setX(left);
TopLeft.setY(top);
BottomRight.setX((left + width));
BottomRight.setY((top + height));
setColor(color);
++m_count;
}
//return rectangle color
int Rectangle::getColor() const
{
return reColor;
}
//Returns the top left point
Point& Rectangle::getTopLeftPoint()
{
return TopLeft;
}
//Returns the bottom right point
Point& Rectangle::getBottomRightPoint()
{
return BottomRight;
}
//set the color of the rectangle
void Rectangle::setColor(int color)
{
reColor = color;
}
//Checks if the point is inside the rectangle
bool Rectangle::contains(const Point& p)
{
bool res = false;
if ((TopLeft.getX() <= p.getX() && p.getX() <= BottomRight.getX()) && (TopLeft.getY() <= p.getY() && p.getY() <= BottomRight.getY()))
{
res = true;
}
return res;
}
//Moves the rectangle in space according to the values given to it
void Rectangle::moveRect(double deltaLeft, double deltaTop)
{
TopLeft.setX((TopLeft.getX() + deltaLeft));
TopLeft.setY((TopLeft.getY() + deltaTop));
BottomRight.setX((BottomRight.getX() + deltaLeft));
BottomRight.setY((BottomRight.getY() + deltaTop));
}
//Expansion and contraction of the rectangle according to new height and width
void Rectangle::scaleRect(double rectWidth, double rectHeight)
{
//Calculation of current height and length
double currentW = BottomRight.getX() - TopLeft.getX();
double currentH = BottomRight.getY() - TopLeft.getY();
//Placement of a new scale in points
TopLeft.setScaleX(rectWidth/ currentW);
BottomRight.setScaleX(rectWidth / currentW);
TopLeft.setScaleY(rectHeight /currentH);
BottomRight.setScaleY(rectHeight / currentH);
}