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
183a3de5
Commit
183a3de5
authored
Feb 08, 2014
by
Davis King
Browse files
Added set_aspect_ratio()
parent
bff364dc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
dlib/geometry/rectangle.h
dlib/geometry/rectangle.h
+35
-0
dlib/geometry/rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+18
-0
No files found.
dlib/geometry/rectangle.h
View file @
183a3de5
...
...
@@ -602,6 +602,41 @@ namespace dlib
return
rectangle
(
x
,
y
,
x
+
rect
.
width
()
-
1
,
y
+
rect
.
height
()
-
1
);
}
// ----------------------------------------------------------------------------------------
inline
rectangle
set_aspect_ratio
(
const
rectangle
&
rect
,
double
ratio
)
{
DLIB_ASSERT
(
ratio
>
0
,
"
\t
rectangle set_aspect_ratio()"
<<
"
\n\t
ratio: "
<<
ratio
<<
"
\n\t
this: "
<<
this
);
// aspect ratio is w/h
// we need to find the rectangle that is nearest to rect in area but
// with an aspect ratio of ratio.
// w/h == ratio
// w*h == rect.area()
if
(
ratio
>=
1
)
{
const
long
h
=
static_cast
<
long
>
(
std
::
sqrt
(
rect
.
area
()
/
ratio
)
+
0.5
);
const
long
w
=
static_cast
<
long
>
(
h
*
ratio
+
0.5
);
return
centered_rect
(
rect
,
w
,
h
);
}
else
{
const
long
w
=
static_cast
<
long
>
(
std
::
sqrt
(
rect
.
area
()
*
ratio
)
+
0.5
);
const
long
h
=
static_cast
<
long
>
(
w
/
ratio
+
0.5
);
return
centered_rect
(
rect
,
w
,
h
);
}
}
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/geometry/rectangle_abstract.h
View file @
183a3de5
...
...
@@ -477,6 +477,24 @@ namespace dlib
and height)
!*/
// ----------------------------------------------------------------------------------------
inline
rectangle
set_aspect_ratio
(
const
rectangle
&
rect
,
double
ratio
);
/*!
requires
- ratio > 0
ensures
- This function reshapes the given rectangle so that it has the given aspect
ratio. In particular, this means we return a rectangle R such that the
following equations are as true as possible:
- R.width()/R.height() == ratio
- R.area() == rect.area()
- center(rect) == center(R)
!*/
// ----------------------------------------------------------------------------------------
inline
rectangle
intersect
(
...
...
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