Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
bb60d061
Commit
bb60d061
authored
Aug 28, 2016
by
Davis King
Browse files
Added nearest_rect()
parent
0ac2197c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
dlib/geometry/rectangle.h
dlib/geometry/rectangle.h
+30
-0
dlib/geometry/rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+16
-0
No files found.
dlib/geometry/rectangle.h
View file @
bb60d061
...
@@ -463,6 +463,36 @@ namespace dlib
...
@@ -463,6 +463,36 @@ namespace dlib
return
temp
;
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
>
template
<
typename
T
,
typename
U
>
...
...
dlib/geometry/rectangle_abstract.h
View file @
bb60d061
...
@@ -704,6 +704,22 @@ namespace dlib
...
@@ -704,6 +704,22 @@ namespace dlib
- returns the point in rect that is closest to p
- 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
(
inline
long
distance_to_rect_edge
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment