Commit e611d110 authored by Davis King's avatar Davis King

Made the mapping from rectangle -> drectangle -> rectangle invertible.

parent c632db76
......@@ -56,18 +56,18 @@ namespace dlib
drectangle (
const rectangle& rect
) : l(rect.left()),
t(rect.top()),
r(rect.right()),
b(rect.bottom()) {}
) : l(rect.left()-0.5),
t(rect.top()-0.5),
r(rect.right()+0.5),
b(rect.bottom()+0.5) {}
operator rectangle (
) const
{
return rectangle((long)std::floor(l+0.5),
(long)std::floor(t+0.5),
(long)std::floor(r+0.5),
(long)std::floor(b+0.5));
return rectangle((long)std::ceil(l),
(long)std::ceil(t),
(long)std::floor(r),
(long)std::floor(b));
}
double left() const { return l; }
......@@ -334,9 +334,10 @@ namespace dlib
return r + drectangle(p);
}
template <typename T>
inline drectangle translate_rect (
const drectangle& rect,
const dlib::vector<double,2>& p
const dlib::vector<T,2>& p
)
{
drectangle result;
......
......@@ -91,18 +91,27 @@ namespace dlib
);
/*!
ensures
- left() == rect.left()
- top() == rect.top()
- right() == rect.right()
- bottom() == rect.bottom()
- left() == rect.left()-0.5
- top() == rect.top()-0.5
- right() == rect.right()+0.5
- bottom() == rect.bottom()+0.5
- center(*this) == center(rect)
- width() == rect.width()
- height() == rect.height()
!*/
operator rectangle (
) const;
/*!
ensures
- rounds the left, top, right, and bottom coordinates of *this to the
nearest integers and returns the resulting rectangle.
- returns a rectangle R such that:
- R.left() == ceil(left())
- R.top() == ceil(top())
- R.right() == floor(right())
- R.bottom() == floor(bottom())
- This function is designed this way so that converting a rectangle to a
drectangle and then back to a rectangle again results in the original
rectangle.
!*/
double left (
......@@ -435,9 +444,10 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template <typename T>
drectangle translate_rect (
const drectangle& rect,
const vector<double,2>& p
const vector<T,2>& p
);
/*!
ensures
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment