-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCcircle.cpp
More file actions
95 lines (84 loc) · 2.66 KB
/
Ccircle.cpp
File metadata and controls
95 lines (84 loc) · 2.66 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
#include"Ccircle.h"
Ccircle::Ccircle(Point c, Point rad, GfxInfo FigureGfxInfo):CFigure(FigureGfxInfo)
{
radiuspoint = rad;
center = c;
}
Ccircle::Ccircle()
{
}
void Ccircle::Draw(Output* pOut) const
{
//Call Output::Drawcircle to draw a rectangle on the screen
pOut->drawcircle(center,radiuspoint, FigGfxInfo, Selected);
}
bool Ccircle::isinside(int x, int y)
{
double radius = sqrt(pow(center.x - radiuspoint.x, 2) + pow(center.y - radiuspoint.y, 2));
double distance = sqrt(pow(center.x - x, 2) + pow(center.y - y, 2));
if (radius >= distance)
{
return true;
}
return false;
}
void Ccircle::SaveFigure(ofstream& save) // save its local data into a file given to the func by saveaction
{
save << "Circle" << "\t\t" << ID << "\t" << to_string(center.x) << "\t" << to_string(center.y) << "\t" << to_string(radiuspoint.x) << "\t" << to_string(radiuspoint.y) << "\t" << ConvertColor_to_string(FigGfxInfo.DrawClr, 0) << "\t" << ConvertColor_to_string(FigGfxInfo.FillClr, 1) << endl;
}
void Ccircle::LoadFigure(ifstream& load) // load its local data from a file given to the func by loadaction
{
string word;
load >> word;
ID = stoi(word);
load >> word;
center.x = stoi(word);
load >> word;
center.y = stoi(word);
load >> word;
radiuspoint.x = stoi(word);
load >> word;
radiuspoint.y = stoi(word);
load >> word;
Selected = false;
FigGfxInfo.DrawClr = ConvertString_to_color(word);
load >> word;
FigGfxInfo.FillClr = ConvertString_to_color(word);
}
Point Ccircle::GetCenter()
{
return center;
}
void Ccircle::Resize_Me(Point cornerpoint)
{
radiuspoint.x = cornerpoint.x;
radiuspoint.y = cornerpoint.y;
}
bool Ccircle::Am_I_Corner(Point cornerpoint)
{
float cornerradius = distance_bet_2_points(cornerpoint, center);
float actual_radius = distance_bet_2_points(radiuspoint, center);
if ((cornerradius < (actual_radius + 15)) && (cornerradius > (actual_radius - 15)))
return true;
else return false;
}
void Ccircle::PrintInfo(Output* pOut)
{
string id = to_string(ID);
string radius = to_string(sqrt(pow(center.x - radiuspoint.x, 2) + pow(center.y - radiuspoint.y, 2)));
string xcenterpoint = to_string(center.x);
string ycenterpoint = to_string(center.y);
string xradpoint = to_string(radiuspoint.x);
string yradpoint = to_string((radiuspoint.y));
string message = "Selected circle info: ID: " + id + " radius:" + radius + " center point:(" + xcenterpoint + "," + ycenterpoint + ")";
message+=" other point:(" + xradpoint + "," + yradpoint + ")";
pOut->PrintMessage(message);
}
void Ccircle::movefig(Point z)
{
int xtranslation =( z.x - center.x);
int ytranslation =(z.y - center.y);
center = z;
radiuspoint.x += xtranslation;
radiuspoint.y += ytranslation;
}