Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
bb60d061
Commit
bb60d061
authored
Aug 28, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added nearest_rect()
parent
0ac2197c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
rectangle.h
dlib/geometry/rectangle.h
+30
-0
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
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
>
...
...
dlib/geometry/rectangle_abstract.h
View file @
bb60d061
...
...
@@ -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
(
...
...
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