Commit 13d7eaaf authored by Davis King's avatar Davis King

Cleaned up the interface to draw_line()

parent 32f9ab22
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "draw_abstract.h" #include "draw_abstract.h"
#include "../algs.h" #include "../algs.h"
#include "../pixel.h"
#include <cmath> #include <cmath>
namespace dlib namespace dlib
...@@ -13,7 +14,8 @@ namespace dlib ...@@ -13,7 +14,8 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
typename image_type typename image_type,
typename pixel_type
> >
void draw_line ( void draw_line (
long x1, long x1,
...@@ -21,7 +23,7 @@ namespace dlib ...@@ -21,7 +23,7 @@ namespace dlib
long x2, long x2,
long y2, long y2,
image_type& c, image_type& c,
typename image_type::type val const pixel_type& val
) )
{ {
if (x1 == x2) if (x1 == x2)
...@@ -37,7 +39,7 @@ namespace dlib ...@@ -37,7 +39,7 @@ namespace dlib
if (y < 0 || y >= c.nr()) if (y < 0 || y >= c.nr())
continue; continue;
c[y][x1] = val; assign_pixel(c[y][x1], val);
} }
} }
else if (y1 == y2) else if (y1 == y2)
...@@ -54,7 +56,7 @@ namespace dlib ...@@ -54,7 +56,7 @@ namespace dlib
if (x < 0 || x >= c.nc()) if (x < 0 || x >= c.nc())
continue; continue;
c[y1][x] = val; assign_pixel(c[y1][x] , val);
} }
} }
else else
...@@ -97,7 +99,7 @@ namespace dlib ...@@ -97,7 +99,7 @@ namespace dlib
continue; continue;
c[y][x] = val; assign_pixel(c[y][x] , val);
} }
} }
else else
...@@ -136,13 +138,29 @@ namespace dlib ...@@ -136,13 +138,29 @@ namespace dlib
if (y < 0 || y >= c.nr()) if (y < 0 || y >= c.nr())
continue; continue;
c[y][x] = val; assign_pixel(c[y][x] , val);
} }
} }
} }
} }
// ----------------------------------------------------------------------------------------
template <
typename image_type,
typename pixel_type
>
void draw_line (
image_type& c,
const point& p1,
const point& p2,
const pixel_type& val
)
{
draw_line(p1.x(),p1.y(),p2.x(),p2.y(),c,val);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
......
...@@ -10,7 +10,32 @@ namespace dlib ...@@ -10,7 +10,32 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
typename image_type typename image_type,
typename pixel_type
>
void draw_line (
image_type& c,
const point& p1,
const point& p2,
const pixel_type& val
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<pixel_type> is defined
ensures
- #img.nr() == img.nr() && #img.nc() == img.nc()
(i.e. the dimensions of the input image are not changed)
- for all valid r and c that are on the line between point p1 and p2:
- performs assign_pixel(img[r][c], val)
(i.e. it draws the line from p1 to p2 onto the image)
!*/
// ----------------------------------------------------------------------------------------
template <
typename image_type,
typename pixel_type
> >
void draw_line ( void draw_line (
long x1, long x1,
...@@ -18,18 +43,14 @@ namespace dlib ...@@ -18,18 +43,14 @@ namespace dlib
long x2, long x2,
long y2, long y2,
image_type& img, image_type& img,
typename image_type::type val const pixel_type& val
); );
/*! /*!
requires requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h - image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<pixel_type> is defined
ensures ensures
- #img.nr() == img.nr() && #img.nc() == img.nc() - performs draw_line(img, point(x1,y1), point(x2,y2), val)
(i.e. the dimensions of the input image are not chanaged)
- for all valid r and c that are on the line between point (x1,y1)
and point (x2,y2):
- performs img[r][c] = val
(i.e. it draws the line from (x1,y1) to (x2,y2) onto the image)
!*/ !*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -50,8 +71,6 @@ namespace dlib ...@@ -50,8 +71,6 @@ namespace dlib
- fills the area defined by rect in the given image with the given pixel value. - fills the area defined by rect in the given image with the given pixel value.
!*/ !*/
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
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