Commit 22d368f4 authored by Davis King's avatar Davis King

Added the distance_to_rect_edge() routine.

parent 03de84fa
......@@ -353,6 +353,30 @@ namespace dlib
return result;
}
// ----------------------------------------------------------------------------------------
inline long distance_to_rect_edge (
const rectangle& rect,
const point& p
)
{
using std::max;
using std::min;
using std::abs;
const long dist_x = min(abs(p.x()-rect.left()), abs(p.x()-rect.right()));
const long dist_y = min(abs(p.y()-rect.top()), abs(p.y()-rect.bottom()));
if (rect.contains(p))
return min(dist_x,dist_y);
else if (rect.left() <= p.x() && p.x() <= rect.right())
return dist_y;
else if (rect.top() <= p.y() && p.y() <= rect.bottom())
return dist_x;
else
return dist_x + dist_y;
}
// ----------------------------------------------------------------------------------------
inline const point nearest_point (
......
......@@ -607,6 +607,17 @@ namespace dlib
- returns the point in rect that is closest to p
!*/
// ----------------------------------------------------------------------------------------
inline long distance_to_rect_edge (
const rectangle& rect,
const point& p
);
/*!
ensures
- returns the Manhattan distance between the edge of rect and p.
!*/
// ----------------------------------------------------------------------------------------
template <
......
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