mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-18 21:27:56 +00:00
util/geometry.h: test (in)equality of rectangles
The operators == and != make the 'Rect' consistent with 'Point' and 'Area'. The patch also adds the 'Rect::clamp' method, which is generally useful for sanitizing input. Issue #5352
This commit is contained in:
parent
7579fe5749
commit
88dc4c878f
@ -224,10 +224,26 @@ struct Genode::Rect
|
||||
*/
|
||||
Point center(Area const area) const
|
||||
{
|
||||
return Point((CT(w()) - CT(area.w))/2,
|
||||
(CT(h()) - CT(area.h))/2) + at;
|
||||
return Point { .x = (CT(w()) - CT(area.w))/2,
|
||||
.y = (CT(h()) - CT(area.h))/2 } + at;
|
||||
}
|
||||
|
||||
Point clamp(Point const p) const
|
||||
{
|
||||
return Point { .x = max(x1(), min(x2(), p.x)),
|
||||
.y = max(y1(), min(y2(), p.y)) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator for testing non-equality of two rectangled
|
||||
*/
|
||||
bool operator != (Rect const &r) const { return r.at != at || r.area != area; }
|
||||
|
||||
/**
|
||||
* Operator for testing equality of two rectangles
|
||||
*/
|
||||
bool operator == (Rect const &r) const { return r.at == at && r.area == area; }
|
||||
|
||||
/**
|
||||
* Print rectangle coordinates
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user