mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added nearest_rect()
This commit is contained in:
parent
0ac2197c74
commit
bb60d061c4
@ -463,6 +463,36 @@ namespace dlib
|
||||
return temp;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
inline size_t nearest_rect (
|
||||
const std::vector<rectangle>& rects,
|
||||
const point& p
|
||||
)
|
||||
{
|
||||
DLIB_ASSERT(rects.size() > 0);
|
||||
size_t idx = 0;
|
||||
double best_dist = std::numeric_limits<double>::infinity();
|
||||
|
||||
for (size_t i = 0; i < rects.size(); ++i)
|
||||
{
|
||||
if (rects[i].contains(p))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
double dist = (nearest_point(rects[i],p)-p).length();
|
||||
if (dist < best_dist)
|
||||
{
|
||||
best_dist = dist;
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T, typename U>
|
||||
|
@ -704,6 +704,22 @@ namespace dlib
|
||||
- returns the point in rect that is closest to p
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
inline size_t nearest_rect (
|
||||
const std::vector<rectangle>& rects,
|
||||
const point& p
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
- rects.size() > 0
|
||||
ensures
|
||||
- returns the index of the rectangle that is closest to the point p. In
|
||||
particular, this function returns an IDX such that:
|
||||
length(nearest_point(rects[IDX],p) - p)
|
||||
is minimized.
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
inline long distance_to_rect_edge (
|
||||
|
Loading…
Reference in New Issue
Block a user