-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRect.cpp
More file actions
178 lines (155 loc) · 6.99 KB
/
Copy pathRect.cpp
File metadata and controls
178 lines (155 loc) · 6.99 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "Rect.h"
#include <iostream>
using namespace std;
Rect::Rect(): _x(0),
_y(0),
_width(0),
_height(0),
_bordered(false),
_border_size(0),
_active_border_size(0),
bordered_left(0.0f),
bordered_right(0.0f),
bordered_top(0.0f),
bordered_bottom(0.0f),
top(0.0f),
bottom(0.0f),
left(0.0f),
right(0.0f)
{
full_update();
}
Rect::Rect(double xval, double yval, double widthval, double heightval,bool borderedval, double bordersizeval): _x(xval),
_y(yval),
_width(widthval),
_height(heightval),
_bordered(borderedval),
_border_size(bordersizeval),
_active_border_size(0),
bordered_left(0.0f),
bordered_right(0.0f),
bordered_top(0.0f),
bordered_bottom(0.0f),
top(0.0f),
bottom(0.0f),
left(0.0f),
right(0.0f)
{
_bordered ? _active_border_size = _border_size : _active_border_size = 0.0f;
full_update();
}
Rect::Rect(double widthval, double heightval, bool borderedval, double bordersizeval): _x(0),
_y(0),
_width(widthval),
_height(heightval),
_bordered(borderedval),
_border_size(bordersizeval),
_active_border_size(0),
bordered_left(0.0f),
bordered_right(0.0f),
bordered_top(0.0f),
bordered_bottom(0.0f),
top(0.0f),
bottom(0.0f),
left(0.0f),
right(0.0f)
{
_bordered ? _active_border_size = _border_size : _active_border_size = 0.0f;
full_update();
}
Rect::Rect(bool borderedval, double bordersizeval) : _x(0),
_y(0),
_width(0),
_height(0),
_bordered(borderedval),
_border_size(bordersizeval),
_active_border_size(0),
bordered_left(0.0f),
bordered_right(0.0f),
bordered_top(0.0f),
bordered_bottom(0.0f),
top(0.0f),
bottom(0.0f),
left(0.0f),
right(0.0f)
{
_bordered ? _active_border_size = _border_size : _active_border_size = 0.0f;
full_update();
}
void Rect::x(const double value)
{
_x = value;
// update rect boundaries
left = _x;
right = _x +_width;
bordered_left = _x - _active_border_size;
bordered_right = right + _active_border_size;
}
void Rect::x_adjust(const double value)
{
_x+= value;
// update rect boundaries
left = _x;
right += value;
bordered_left += value;
bordered_right += value;
}
void Rect::y(const double value)
{
_y = value;
// update rect boundaries
top = _y;
bottom = _y +_height;
bordered_top = _y - _active_border_size;
bordered_bottom = bottom + _active_border_size;
}
void Rect::y_adjust(const double value)
{
_y+= value;
// update rect boundaries
top = _y;
bottom += value;
bordered_top += value;
bordered_bottom += value;
}
void Rect::width(const double value)
{
_width = value;
// update rect boundaries
right = _x +_width;
bordered_right = right + _active_border_size;
}
void Rect::height(const double value)
{
_height = value;
// update rect boundaries
bottom = _y +_height;
bordered_bottom = bottom + _active_border_size;
}
void Rect::bordered(const bool value)
{
_bordered = value;
full_update();
}
void Rect::border_size(const double value)
{
_border_size = value;
full_update();
}
bool Rect::is_clashing_with(Rect* item)
{
return !((bordered_bottom < item->top) || (bordered_top > item->bottom) || (bordered_left > item->right) || (bordered_right < item->left));
}
void Rect::full_update()
{
// update rect boundaries
left = _x;
right = _x +_width;
top = _y;
bottom = _y +_height;
//update border boundaries
bordered_left = _x - _active_border_size;
bordered_right = right + _active_border_size;
bordered_top = _y - _active_border_size;
bordered_bottom = bottom + _active_border_size;
}