-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.cpp
71 lines (67 loc) · 1.89 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
#include "Rectangle.h"
Rectangle::Rectangle(double startX, double startY, double width, double height, const char* color, unsigned int ID) :Shapes(startX, startY, color, ID)
{
this->width = width;
this->height = height;
}
double Rectangle::GetWidth()
{
return width;
}
double Rectangle::GetHeight()
{
return height;
}
void Rectangle::SetWidth(double width)
{
this->width = width;
}
void Rectangle::SetHeight(double height)
{
this->height = height;
}
void Rectangle::Print(ostream& strm)
{
strm << " <rect ";
start.Print(strm);
strm << "width=" << '"' << width << '"' << " height=" << '"' << height << '"' << " ";
strm << "fill=" << '"' << color << '"' << " " << "/>";
strm << endl;
}
void Rectangle::Print()
{
cout << ID << ". rectangle, ";
start.Print();
cout << ", " << width << ", " << height << ", ";
cout << color;
cout << endl;
}
bool Rectangle::WithinRectangle(double startX, double startY, double width, double height)
{
Point LeftUpperCorner(start.GetX() + this->GetWidth(), start.GetY() + this->GetHeight());
Point RightUpperCorner(start.GetX(), start.GetY() + this->GetHeight());
Point LeftBottomCorner(start.GetX() + this->GetWidth(), start.GetY());
if (start.WithinRectangle(startX, startY, width, height) && LeftUpperCorner.WithinRectangle(startX, startY, width, height) && RightUpperCorner.WithinRectangle(startX, startY, width, height) && LeftBottomCorner.WithinRectangle(startX, startY, width, height))
{
this->Print(cout);
return true;
}
else
return false;
}
bool Rectangle::WithinCircle(double startX, double startY, double radius)
{
}
void Rectangle::Translate(double horizontal, double vertical)
{
start.SetX(start.GetX() + horizontal);
start.SetY(start.GetY() + horizontal);
}
double Area(double width, double height)
{
return width*height;
}
Shapes* Rectangle::clone()
{
return new Rectangle(*this);
}