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
0e1d8756
Commit
0e1d8756
authored
Aug 24, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a function for computing the center of a rectangle.
parent
20a79481
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
rectangle.h
dlib/geometry/rectangle.h
+18
-0
rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+12
-2
geometry.cpp
dlib/test/geometry.cpp
+15
-0
No files found.
dlib/geometry/rectangle.h
View file @
0e1d8756
...
...
@@ -353,6 +353,24 @@ namespace dlib
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
(
...
...
dlib/geometry/rectangle_abstract.h
View file @
0e1d8756
...
...
@@ -402,6 +402,16 @@ namespace dlib
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
(
...
...
@@ -412,6 +422,7 @@ namespace dlib
/*!
ensures
- returns a rectangle R such that:
- center(R) == p
- if (width == 0 || height == 0)
- R.width() == 0
- R.height() == 0
...
...
@@ -419,7 +430,6 @@ namespace dlib
- R.width() == width
- R.height() == height
- 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
/*!
ensures
- returns a rectangle R such that:
- center(R) == p
- if (width == 0 || height == 0)
- R.width() == 0
- R.height() == 0
...
...
@@ -440,7 +451,6 @@ namespace dlib
- R.width() == width
- R.height() == height
- 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
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