| 467 | // ---------------------------------------------------------------------------------------- |
| 468 | |
| 469 | inline size_t nearest_rect ( |
| 470 | const std::vector<rectangle>& rects, |
| 471 | const point& p |
| 472 | ) |
| 473 | { |
| 474 | DLIB_ASSERT(rects.size() > 0); |
| 475 | size_t idx = 0; |
| 476 | double best_dist = std::numeric_limits<double>::infinity(); |
| 477 | |
| 478 | for (size_t i = 0; i < rects.size(); ++i) |
| 479 | { |
| 480 | if (rects[i].contains(p)) |
| 481 | { |
| 482 | return i; |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | double dist = (nearest_point(rects[i],p)-p).length(); |
| 487 | if (dist < best_dist) |
| 488 | { |
| 489 | best_dist = dist; |
| 490 | idx = i; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | return idx; |
| 495 | } |
| 496 | |
| 497 | // ---------------------------------------------------------------------------------------- |
| 498 |
no test coverage detected