Commit 8f5c5a3c authored by Davis King's avatar Davis King

Refined drectangle a little.

parent 53168ba4
......@@ -95,7 +95,8 @@ namespace dlib
double width (
) const
{
if (is_empty())
// if either the width or height would be 0.
if (t >= b || l >= r)
return 0;
else
return r - l;
......@@ -104,7 +105,8 @@ namespace dlib
double height (
) const
{
if (is_empty())
// if either the width or height would be 0.
if (t >= b || l >= r)
return 0;
else
return b - t;
......
......@@ -95,7 +95,7 @@ namespace dlib
- top() == rect.top()-0.5
- right() == rect.right()+0.5
- bottom() == rect.bottom()+0.5
- center(*this) == center(rect)
- dcenter(*this) == dcenter(rect)
- width() == rect.width()
- height() == rect.height()
!*/
......
......@@ -772,6 +772,29 @@ namespace
}
}
// ----------------------------------------------------------------------------------------
void test_rect_to_drect()
{
print_spinner();
dlib::rand rnd;
for (int i = 0; i < 5000; ++i)
{
rectangle rect = centered_rect(rnd.get_random_32bit_number()%100,
rnd.get_random_32bit_number()%100,
rnd.get_random_32bit_number()%100,
rnd.get_random_32bit_number()%100);
drectangle drect = rect;
rectangle rect2 = drect;
DLIB_TEST(rect2 == rect);
DLIB_TEST(rect.width() == drect.width());
DLIB_TEST(rect.height() == drect.height());
DLIB_TEST(dcenter(rect) == dcenter(drect));
}
}
// ----------------------------------------------------------------------------------------
class geometry_tester : public tester
......@@ -786,6 +809,7 @@ namespace
void perform_test (
)
{
test_rect_to_drect();
geometry_test();
test_border_enumerator();
test_find_affine_transform();
......
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