Commit 1d22526d authored by Davis King's avatar Davis King

Added functions to grow and shrink the border of rectangle objects.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403027
parent f0846be6
...@@ -395,6 +395,26 @@ namespace dlib ...@@ -395,6 +395,26 @@ namespace dlib
return centered_rect((rect.left()+rect.right())/2, (rect.top()+rect.bottom())/2, width, height); return centered_rect((rect.left()+rect.right())/2, (rect.top()+rect.bottom())/2, width, height);
} }
// ----------------------------------------------------------------------------------------
inline const rectangle shrink_rect (
const rectangle& rect,
long num
)
{
return rectangle(rect.left()+num, rect.top()+num, rect.right()-num, rect.bottom()-num);
}
// ----------------------------------------------------------------------------------------
inline const rectangle grow_rect (
const rectangle& rect,
long num
)
{
return shrink_rect(rect, -num);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
inline const rectangle translate_rect ( inline const rectangle translate_rect (
......
...@@ -456,6 +456,30 @@ namespace dlib ...@@ -456,6 +456,30 @@ namespace dlib
and height) and height)
!*/ !*/
// ----------------------------------------------------------------------------------------
inline const rectangle shrink_rect (
const rectangle& rect,
long num
);
/*!
ensures
- returns rectangle(rect.left()+num, rect.top()+num, rect.right()-num, rect.bottom()-num)
(i.e. shrinks the given rectangle by shrinking its border by num)
!*/
// ----------------------------------------------------------------------------------------
inline const rectangle grow_rect (
const rectangle& rect,
long num
);
/*!
ensures
- return shrink_rect(rect, -num)
(i.e. grows the given rectangle by expanding its border by num)
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
const rectangle translate_rect ( const rectangle translate_rect (
......
...@@ -294,6 +294,37 @@ namespace ...@@ -294,6 +294,37 @@ namespace
DLIB_TEST(rot(point(0,1)) == point(-1,0)); DLIB_TEST(rot(point(0,1)) == point(-1,0));
} }
{
rectangle rect;
rect = grow_rect(rect,1);
DLIB_TEST(rect.width() == 2);
DLIB_TEST(rect.height() == 2);
DLIB_TEST(rect.left() == -1);
DLIB_TEST(rect.top() == -1);
DLIB_TEST(rect.right() == 0);
DLIB_TEST(rect.bottom() == 0);
}
{
rectangle rect;
rect = grow_rect(rect,2);
DLIB_TEST(rect.width() == 4);
DLIB_TEST(rect.height() == 4);
DLIB_TEST(rect.left() == -2);
DLIB_TEST(rect.top() == -2);
DLIB_TEST(rect.right() == 1);
DLIB_TEST(rect.bottom() == 1);
rect = shrink_rect(rect,1);
DLIB_TEST(rect.width() == 2);
DLIB_TEST(rect.height() == 2);
DLIB_TEST(rect.left() == -1);
DLIB_TEST(rect.top() == -1);
DLIB_TEST(rect.right() == 0);
DLIB_TEST(rect.bottom() == 0);
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment