Commit 12599d07 authored by Davis King's avatar Davis King

Added a get_rect() for array2d objects.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403168
parent c00e5225
......@@ -8,6 +8,7 @@
#include "../interfaces/enumerable.h"
#include "../serialize.h"
#include "../memory_manager.h"
#include "../geometry/rectangle.h"
namespace dlib
{
......@@ -302,6 +303,11 @@ namespace dlib
}
}
template < typename T >
const rectangle get_rect (
const array2d_kernel_1<T>& item
) { return rectangle(0, 0, item.nc()-1, item.nr()-1); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
......
......@@ -6,6 +6,7 @@
#include "../interfaces/enumerable.h"
#include "../serialize.h"
#include "../memory_manager/memory_manager_kernel_abstract.h"
#include "../geometry/rectangle_abstract.h"
namespace dlib
{
......@@ -239,6 +240,18 @@ namespace dlib
provides deserialization support
!*/
template <
typename T
>
const rectangle get_rect (
const array2d<T>& item
);
/*!
ensures
- returns rectangle(0, 0, item.nc()-1, item.nr()-1)
(i.e. returns a rectangle that has the same dimensions as
the array2d item)
!*/
}
#endif // DLIB_ARRAY2D_KERNEl_ABSTRACT_
......
......@@ -200,6 +200,11 @@ namespace dlib
}
}
template < typename array2d_base >
const rectangle get_rect (
const array2d_kernel_c<array2d_base>& item
) { return rectangle(0, 0, item.nc()-1, item.nr()-1); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
......
......@@ -38,6 +38,7 @@ namespace
long nc, nr;
DLIB_TEST(get_rect(test).is_empty());
enumerable<unsigned long>& e = test;
DLIB_TEST(e.at_start() == true);
......@@ -67,6 +68,7 @@ namespace
DLIB_TEST(e.current_element_valid() == false);
DLIB_TEST(get_rect(test).is_empty());
......@@ -116,6 +118,7 @@ namespace
test.set_size(0,0);
DLIB_TEST(get_rect(test).is_empty());
DLIB_TEST(test.at_start() == true);
......@@ -184,6 +187,11 @@ namespace
test.set_size(nr,nc);
DLIB_TEST(get_rect(test).left() == 0);
DLIB_TEST(get_rect(test).top() == 0);
DLIB_TEST(get_rect(test).right() == nc-1);
DLIB_TEST(get_rect(test).bottom() == nr-1);
DLIB_TEST(test.size() == static_cast<unsigned long>(nc*nr));
DLIB_TEST(test.nr() == nr);
DLIB_TEST(test.nc() == nc);
......
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