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
22d368f4
Commit
22d368f4
authored
Jun 19, 2011
by
Davis King
Browse files
Added the distance_to_rect_edge() routine.
parent
03de84fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
dlib/geometry/rectangle.h
dlib/geometry/rectangle.h
+24
-0
dlib/geometry/rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+11
-0
No files found.
dlib/geometry/rectangle.h
View file @
22d368f4
...
...
@@ -353,6 +353,30 @@ namespace dlib
return
result
;
}
// ----------------------------------------------------------------------------------------
inline
long
distance_to_rect_edge
(
const
rectangle
&
rect
,
const
point
&
p
)
{
using
std
::
max
;
using
std
::
min
;
using
std
::
abs
;
const
long
dist_x
=
min
(
abs
(
p
.
x
()
-
rect
.
left
()),
abs
(
p
.
x
()
-
rect
.
right
()));
const
long
dist_y
=
min
(
abs
(
p
.
y
()
-
rect
.
top
()),
abs
(
p
.
y
()
-
rect
.
bottom
()));
if
(
rect
.
contains
(
p
))
return
min
(
dist_x
,
dist_y
);
else
if
(
rect
.
left
()
<=
p
.
x
()
&&
p
.
x
()
<=
rect
.
right
())
return
dist_y
;
else
if
(
rect
.
top
()
<=
p
.
y
()
&&
p
.
y
()
<=
rect
.
bottom
())
return
dist_x
;
else
return
dist_x
+
dist_y
;
}
// ----------------------------------------------------------------------------------------
inline
const
point
nearest_point
(
...
...
dlib/geometry/rectangle_abstract.h
View file @
22d368f4
...
...
@@ -607,6 +607,17 @@ namespace dlib
- returns the point in rect that is closest to p
!*/
// ----------------------------------------------------------------------------------------
inline
long
distance_to_rect_edge
(
const
rectangle
&
rect
,
const
point
&
p
);
/*!
ensures
- returns the Manhattan distance between the edge of rect and p.
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
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