@@ -129,23 +129,19 @@ namespace litehtml
129
129
{
130
130
using vector = std::vector<position>;
131
131
132
- int x;
133
- int y;
134
- int width;
135
- int height;
136
-
137
- position ()
138
- {
139
- x = y = width = height = 0 ;
140
- }
141
-
142
- position (int x, int y, int width, int height)
143
- {
144
- this ->x = x;
145
- this ->y = y;
146
- this ->width = width;
147
- this ->height = height;
148
- }
132
+ int x = 0 ;
133
+ int y = 0 ;
134
+ int width = 0 ;
135
+ int height = 0 ;
136
+
137
+ position () = default ;
138
+
139
+ position (int _x, int _y, int _width, int _height) :
140
+ x (_x),
141
+ y (_y),
142
+ width (_width),
143
+ height (_height)
144
+ {}
149
145
150
146
int right () const { return x + width; }
151
147
int bottom () const { return y + height; }
@@ -178,12 +174,18 @@ namespace litehtml
178
174
height = sz.height ;
179
175
}
180
176
177
+ bool operator ==(const position& val)
178
+ {
179
+ return x == val.x && y == val.y && width == val.width && height == val.height ;
180
+ }
181
+
181
182
void move_to (int _x, int _y)
182
183
{
183
184
x = _x;
184
185
y = _y;
185
186
}
186
187
188
+ [[nodiscard]]
187
189
bool does_intersect (const position* val) const
188
190
{
189
191
if (!val) return true ;
@@ -200,22 +202,41 @@ namespace litehtml
200
202
val->top () <= bottom () );
201
203
}
202
204
203
- bool empty () const
205
+ [[nodiscard]]
206
+ position intersect (const position& src) const
204
207
{
205
- if (!width && !height)
208
+ position dest;
209
+ int dest_x = std::max (src.x , x);
210
+ int dest_y = std::max (src.y , y);
211
+ int dest_x2 = std::min (src.right (), right ());
212
+ int dest_y2 = std::min (src.bottom (), bottom ());
213
+
214
+ if (dest_x2 > dest_x && dest_y2 > dest_y)
215
+ {
216
+ dest.x = dest_x;
217
+ dest.y = dest_y;
218
+ dest.width = dest_x2 - dest_x;
219
+ dest.height = dest_y2 - dest_y;
220
+ }
221
+ else
206
222
{
207
- return true ;
223
+ dest.width = 0 ;
224
+ dest.height = 0 ;
208
225
}
209
- return false ;
226
+
227
+ return dest;
210
228
}
211
229
230
+ [[nodiscard]]
231
+ bool empty () const
232
+ {
233
+ return !width && !height;
234
+ }
235
+
236
+ [[nodiscard]]
212
237
bool is_point_inside (int _x, int _y) const
213
238
{
214
- if (_x >= left () && _x < right () && _y >= top () && _y < bottom ())
215
- {
216
- return true ;
217
- }
218
- return false ;
239
+ return (_x >= left () && _x < right () && _y >= top () && _y < bottom ());
219
240
}
220
241
};
221
242
0 commit comments