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
0e1d8756
Commit
0e1d8756
authored
Aug 24, 2011
by
Davis King
Browse files
Added a function for computing the center of a rectangle.
parent
20a79481
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
dlib/geometry/rectangle.h
dlib/geometry/rectangle.h
+18
-0
dlib/geometry/rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+12
-2
dlib/test/geometry.cpp
dlib/test/geometry.cpp
+15
-0
No files found.
dlib/geometry/rectangle.h
View file @
0e1d8756
...
@@ -353,6 +353,24 @@ namespace dlib
...
@@ -353,6 +353,24 @@ namespace dlib
return
result
;
return
result
;
}
}
// ----------------------------------------------------------------------------------------
point
center
(
const
dlib
::
rectangle
&
rect
)
{
point
temp
(
rect
.
left
()
+
rect
.
right
()
+
1
,
rect
.
top
()
+
rect
.
bottom
()
+
1
);
if
(
temp
.
x
()
<
0
)
temp
.
x
()
-=
1
;
if
(
temp
.
y
()
<
0
)
temp
.
y
()
-=
1
;
return
temp
/
2
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
inline
long
distance_to_rect_edge
(
inline
long
distance_to_rect_edge
(
...
...
dlib/geometry/rectangle_abstract.h
View file @
0e1d8756
...
@@ -402,6 +402,16 @@ namespace dlib
...
@@ -402,6 +402,16 @@ namespace dlib
The data in the input stream should be of the form [(left, top) (right, bottom)]
The data in the input stream should be of the form [(left, top) (right, bottom)]
!*/
!*/
// ----------------------------------------------------------------------------------------
point
center
(
const
dlib
::
rectangle
&
rect
);
/*!
ensures
- returns the center of the given rectangle
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
inline
const
rectangle
centered_rect
(
inline
const
rectangle
centered_rect
(
...
@@ -412,6 +422,7 @@ namespace dlib
...
@@ -412,6 +422,7 @@ namespace dlib
/*!
/*!
ensures
ensures
- returns a rectangle R such that:
- returns a rectangle R such that:
- center(R) == p
- if (width == 0 || height == 0)
- if (width == 0 || height == 0)
- R.width() == 0
- R.width() == 0
- R.height() == 0
- R.height() == 0
...
@@ -419,7 +430,6 @@ namespace dlib
...
@@ -419,7 +430,6 @@ namespace dlib
- R.width() == width
- R.width() == width
- R.height() == height
- R.height() == height
- R.tl_corner() == point(p.x()-width/2, p.y()-height/2)
- R.tl_corner() == point(p.x()-width/2, p.y()-height/2)
- The center of R is a the point p
!*/
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -433,6 +443,7 @@ namespace dlib
...
@@ -433,6 +443,7 @@ namespace dlib
/*!
/*!
ensures
ensures
- returns a rectangle R such that:
- returns a rectangle R such that:
- center(R) == p
- if (width == 0 || height == 0)
- if (width == 0 || height == 0)
- R.width() == 0
- R.width() == 0
- R.height() == 0
- R.height() == 0
...
@@ -440,7 +451,6 @@ namespace dlib
...
@@ -440,7 +451,6 @@ namespace dlib
- R.width() == width
- R.width() == width
- R.height() == height
- R.height() == height
- R.tl_corner() == point(x-width/2, y-height/2)
- R.tl_corner() == point(x-width/2, y-height/2)
- The center of R is a the point (x,y)
!*/
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/test/geometry.cpp
View file @
0e1d8756
...
@@ -349,6 +349,21 @@ namespace
...
@@ -349,6 +349,21 @@ namespace
DLIB_TEST
(
rectangle
()
+
point
(
5
,
4
)
+
point
(
10
,
10
)
==
rectangle
(
5
,
4
,
10
,
10
));
DLIB_TEST
(
rectangle
()
+
point
(
5
,
4
)
+
point
(
10
,
10
)
==
rectangle
(
5
,
4
,
10
,
10
));
// make sure the center of a centered rectangle is always right
for
(
long
x
=
-
10
;
x
<=
10
;
++
x
)
{
for
(
long
y
=
-
10
;
y
<=
10
;
++
y
)
{
for
(
long
w
=
0
;
w
<
10
;
++
w
)
{
for
(
long
h
=
0
;
h
<
10
;
++
h
)
{
DLIB_TEST
(
center
(
centered_rect
(
x
,
y
,
w
,
h
))
==
point
(
x
,
y
));
}
}
}
}
}
}
...
...
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