Add constrain operation for points in regions
This commit is contained in:
parent
847242a59f
commit
1f37a8d04c
11
region.cpp
11
region.cpp
@ -135,6 +135,17 @@ region<T>::overlaps (const region<T> &rhs) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
point2
|
||||||
|
region<T>::constrain (const point2 &p) const {
|
||||||
|
point2 v;
|
||||||
|
v.x = std::min (std::max (static_cast<T> (p.x), x), x + w);
|
||||||
|
v.y = std::min (std::max (static_cast<T> (p.y), y), y + h);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template<typename T>
|
template<typename T>
|
||||||
region<T>
|
region<T>
|
||||||
|
10
region.hpp
10
region.hpp
@ -50,13 +50,15 @@ namespace util {
|
|||||||
|
|
||||||
bool empty (void) const;
|
bool empty (void) const;
|
||||||
|
|
||||||
point<2> base (void) const;
|
point2 base (void) const;
|
||||||
point<2> centre (void) const;
|
point2 centre (void) const;
|
||||||
|
|
||||||
bool includes (const point<2>&) const; // inclusive of borders
|
bool includes (const point2&) const; // inclusive of borders
|
||||||
bool contains (const point<2>&) const; // exclusive of borders
|
bool contains (const point2&) const; // exclusive of borders
|
||||||
bool overlaps (const region<T>&) const; // exclusive of borders
|
bool overlaps (const region<T>&) const; // exclusive of borders
|
||||||
|
|
||||||
|
point2 constrain (const point2&) const;
|
||||||
|
|
||||||
region overlap (const region<T>&) const;
|
region overlap (const region<T>&) const;
|
||||||
|
|
||||||
bool operator ==(const region<T>& rhs) const;
|
bool operator ==(const region<T>& rhs) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user