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
3ee460da
Commit
3ee460da
authored
Jun 03, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added set_rect_area()
parent
5bc1792d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
+81
-0
drectangle.h
dlib/geometry/drectangle.h
+24
-0
drectangle_abstract.h
dlib/geometry/drectangle_abstract.h
+17
-0
rectangle.h
dlib/geometry/rectangle.h
+23
-0
rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+17
-0
No files found.
dlib/geometry/drectangle.h
View file @
3ee460da
...
...
@@ -441,6 +441,30 @@ namespace dlib
return
shrink_rect
(
rect
,
-
width
,
-
height
);
}
inline
drectangle
set_rect_area
(
const
drectangle
&
rect
,
double
area
)
{
DLIB_ASSERT
(
area
>=
0
,
"drectangle can't have a negative area."
);
if
(
area
==
0
)
return
drectangle
(
dcenter
(
rect
));
if
(
rect
.
area
()
==
0
)
{
// In this case we will make the output rectangle a square with the requested
// area.
double
scale
=
std
::
sqrt
(
area
);
return
centered_drect
(
rect
,
scale
,
scale
);
}
else
{
double
scale
=
std
::
sqrt
(
area
/
rect
.
area
());
return
centered_drect
(
rect
,
rect
.
width
()
*
scale
,
rect
.
height
()
*
scale
);
}
}
inline
drectangle
set_aspect_ratio
(
const
drectangle
&
rect
,
double
ratio
...
...
dlib/geometry/drectangle_abstract.h
View file @
3ee460da
...
...
@@ -585,6 +585,23 @@ namespace dlib
(i.e. grows the given drectangle by expanding its border)
!*/
// ----------------------------------------------------------------------------------------
drectangle
set_rect_area
(
const
drectangle
&
rect
,
double
area
);
/*!
requires
- area >= 0
ensures
- Returns a rectangle R such that:
- center(R) == center(rect)
- R has the same aspect ratio as rect. If rect.area() == 0 then the
returned rect has a 1:1 aspect ratio.
- R.area() == area
!*/
// ----------------------------------------------------------------------------------------
drectangle
set_aspect_ratio
(
...
...
dlib/geometry/rectangle.h
View file @
3ee460da
...
...
@@ -726,6 +726,29 @@ namespace dlib
return
rectangle
(
x
,
y
,
x
+
rect
.
width
()
-
1
,
y
+
rect
.
height
()
-
1
);
}
// ----------------------------------------------------------------------------------------
inline
rectangle
set_rect_area
(
const
rectangle
&
rect
,
unsigned
long
area
)
{
DLIB_ASSERT
(
area
>
0
);
if
(
rect
.
area
()
==
0
)
{
// In this case we will make the output rectangle a square with the requested
// area.
unsigned
long
scale
=
std
::
round
(
std
::
sqrt
(
area
));
return
centered_rect
(
rect
,
scale
,
scale
);
}
else
{
double
scale
=
std
::
sqrt
(
area
/
(
double
)
rect
.
area
());
return
centered_rect
(
rect
,
(
long
)
std
::
round
(
rect
.
width
()
*
scale
),
(
long
)
std
::
round
(
rect
.
height
()
*
scale
));
}
}
// ----------------------------------------------------------------------------------------
inline
rectangle
set_aspect_ratio
(
...
...
dlib/geometry/rectangle_abstract.h
View file @
3ee460da
...
...
@@ -487,6 +487,23 @@ namespace dlib
and height)
!*/
// ----------------------------------------------------------------------------------------
inline
rectangle
set_rect_area
(
const
rectangle
&
rect
,
unsigned
long
area
);
/*!
requires
- area > 0
ensures
- Returns a rectangle R such that:
- center(R) == center(rect)
- R has the same aspect ratio as rect. If rect.area() == 0 then the
returned rect has a 1:1 aspect ratio.
- R.area() == area
!*/
// ----------------------------------------------------------------------------------------
inline
rectangle
set_aspect_ratio
(
...
...
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