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
16efd469
Commit
16efd469
authored
Jul 03, 2015
by
Davis King
Browse files
Added a version of set_aspect_ratio() that works for drectangle.
parent
ad9a9e6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
dlib/geometry/drectangle.h
dlib/geometry/drectangle.h
+24
-0
dlib/geometry/drectangle_abstract.h
dlib/geometry/drectangle_abstract.h
+30
-0
No files found.
dlib/geometry/drectangle.h
View file @
16efd469
...
@@ -385,6 +385,15 @@ namespace dlib
...
@@ -385,6 +385,15 @@ namespace dlib
return
drectangle
(
p
.
x
()
-
width
/
2
,
p
.
y
()
-
height
/
2
,
p
.
x
()
+
width
/
2
,
p
.
y
()
+
height
/
2
);
return
drectangle
(
p
.
x
()
-
width
/
2
,
p
.
y
()
-
height
/
2
,
p
.
x
()
+
width
/
2
,
p
.
y
()
+
height
/
2
);
}
}
inline
drectangle
centered_drect
(
const
drectangle
&
rect
,
double
width
,
double
height
)
{
return
centered_drect
(
dcenter
(
rect
),
width
,
height
);
}
inline
const
drectangle
shrink_rect
(
inline
const
drectangle
shrink_rect
(
const
drectangle
&
rect
,
const
drectangle
&
rect
,
double
num
double
num
...
@@ -419,6 +428,21 @@ namespace dlib
...
@@ -419,6 +428,21 @@ namespace dlib
return
shrink_rect
(
rect
,
-
width
,
-
height
);
return
shrink_rect
(
rect
,
-
width
,
-
height
);
}
}
inline
drectangle
set_aspect_ratio
(
const
drectangle
&
rect
,
double
ratio
)
{
DLIB_ASSERT
(
ratio
>
0
,
"
\t
drectangle set_aspect_ratio()"
<<
"
\n\t
ratio: "
<<
ratio
);
const
double
h
=
std
::
sqrt
(
rect
.
area
()
/
ratio
);
const
double
w
=
h
*
ratio
;
return
centered_drect
(
rect
,
w
,
h
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
dlib/geometry/drectangle_abstract.h
View file @
16efd469
...
@@ -503,6 +503,18 @@ namespace dlib
...
@@ -503,6 +503,18 @@ namespace dlib
- R.height() == height
- R.height() == height
!*/
!*/
// ----------------------------------------------------------------------------------------
drectangle
centered_drect
(
const
drectangle
&
rect
,
double
width
,
double
height
);
/*!
ensures
- returns centered_drect(center(rect), width, height)
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
const
drectangle
shrink_rect
(
const
drectangle
shrink_rect
(
...
@@ -554,6 +566,24 @@ namespace dlib
...
@@ -554,6 +566,24 @@ namespace dlib
(i.e. grows the given drectangle by expanding its border)
(i.e. grows the given drectangle by expanding its border)
!*/
!*/
// ----------------------------------------------------------------------------------------
drectangle
set_aspect_ratio
(
const
drectangle
&
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 true:
- R.width()/R.height() == ratio
- R.area() == rect.area()
- dcenter(rect) == dcenter(R)
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
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