MCPcopy Create free account
hub / github.com/davisking/dlib / nearest_rect

Function nearest_rect

dlib/geometry/rectangle.h:469–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

tiled_pyramid_to_imageFunction · 0.85

Calls 4

nearest_pointFunction · 0.85
sizeMethod · 0.45
containsMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected