* mln/core/site_set/p_line2d.hh (mln::p_line2d::has(const psite&)):
Remove a too strict precondition.
* mln/draw/dashed_line.hh (mln::draw::dashed_line):
Rework implementation to make it more like mln::draw::line's.
Clean up a bit.
* tests/draw/dashed_line.cc: New test.
* tests/draw/Makefile.am (check_PROGRAMS): Add dashed_line.
---
milena/ChangeLog | 12 ++++++++
milena/mln/core/site_set/p_line2d.hh | 1 -
milena/mln/draw/dashed_line.hh | 18 +++++++-----
milena/tests/draw/Makefile.am | 4 +--
.../binary_2d/subsample.cc => draw/dashed_line.cc} | 29 ++++++++++++--------
5 files changed, 42 insertions(+), 22 deletions(-)
copy milena/tests/{world/binary_2d/subsample.cc => draw/dashed_line.cc} (75%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index add0a55..04622e7 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,15 @@
+2013-07-25 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Fix and improve mln::draw::dashed_line.
+
+ * mln/core/site_set/p_line2d.hh (mln::p_line2d::has(const psite&)):
+ Remove a too strict precondition.
+ * mln/draw/dashed_line.hh (mln::draw::dashed_line):
+ Rework implementation to make it more like mln::draw::line's.
+ Clean up a bit.
+ * tests/draw/dashed_line.cc: New test.
+ * tests/draw/Makefile.am (check_PROGRAMS): Add dashed_line.
+
2013-07-04 Roland Levillain <roland(a)lrde.epita.fr>
Work around a Clang 3.0 bug.
diff --git a/milena/mln/core/site_set/p_line2d.hh b/milena/mln/core/site_set/p_line2d.hh
index 1cbd3f6..e1ed059 100644
--- a/milena/mln/core/site_set/p_line2d.hh
+++ b/milena/mln/core/site_set/p_line2d.hh
@@ -240,7 +240,6 @@ namespace mln
bool
p_line2d::has(const psite& p) const
{
- mln_precondition(p.target_() == this); // FIXME: Refine.
if (! has(p.index()))
return false;
mln_invariant(p.to_site() == (*this)[p.index()]);
diff --git a/milena/mln/draw/dashed_line.hh b/milena/mln/draw/dashed_line.hh
index d26559b..1b76cfe 100644
--- a/milena/mln/draw/dashed_line.hh
+++ b/milena/mln/draw/dashed_line.hh
@@ -17,7 +17,7 @@
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
-// instantiate templates or use macros or indashed_line functions from this
+// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
@@ -29,15 +29,16 @@
/// \file
///
-/// \brief Draw a dashed_line in an image.
-/// \todo Add specializations for horizontal dashed_lines (use
+/// \brief Draw a dashed line in an image.
+/// \todo Add specializations for horizontal dashed lines (use
/// pointers/memset).
# include <mln/core/concept/function.hh>
# include <mln/core/concept/image.hh>
# include <mln/core/site_set/p_line2d.hh>
# include <mln/core/image/imorph/safe.hh>
-# include <mln/data/fill.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/data/paste.hh>
# include <mln/pw/image.hh>
# include <mln/pw/cst.hh>
@@ -52,8 +53,8 @@ namespace mln
between the points \p beg and \p end.
\param[in,out] ima The image to be drawn.
- \param[in] beg The start point to drawn dashed_line.
- \param[in] end The end point to drawn dashed_line.
+ \param[in] beg The start point to drawn dashed line.
+ \param[in] end The end point to drawn dashed line.
\param[in] v The value to assign to all drawn pixels.
\pre \p ima has to be initialized.
@@ -103,7 +104,10 @@ namespace mln
if (! ima.has(end))
mln_trace_warning("End site is not part of the given image.");
- data::fill(((ima | p_line2d(beg, end)).rw() | internal::dashed_line_f<I,
1>()).rw(), v);
+ data::paste(pw::cst(v)
+ | p_line2d(beg, end)
+ | internal::dashed_line_f<I, 1>(),
+ safe(ima).rw());
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/tests/draw/Makefile.am b/milena/tests/draw/Makefile.am
index 0ef96b5..3c1e8f5 100644
--- a/milena/tests/draw/Makefile.am
+++ b/milena/tests/draw/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
+# Copyright (C) 2007, 2008, 2009, 2010, 2013 EPITA Research and Development
# Laboratory (LRDE)
#
# This file is part of Olena.
@@ -18,8 +18,8 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
+ dashed_line \
line \
graph
-
TESTS = $(check_PROGRAMS)
diff --git a/milena/tests/world/binary_2d/subsample.cc b/milena/tests/draw/dashed_line.cc
similarity index 75%
copy from milena/tests/world/binary_2d/subsample.cc
copy to milena/tests/draw/dashed_line.cc
index f7aa4ef..86ebad9 100644
--- a/milena/tests/world/binary_2d/subsample.cc
+++ b/milena/tests/draw/dashed_line.cc
@@ -24,25 +24,30 @@
// executable file might be covered by the GNU General Public License.
/// \file
-/// Exercise mln::world::binary_2d::subsample.
+/// \brief Exercise mln::draw::dashed_line.
#include <mln/core/image/image2d.hh>
-#include <mln/value/int_u8.hh>
-#include <mln/world/binary_2d/subsample.hh>
-
-#include <mln/io/pbm/load.hh>
-#include <mln/io/pgm/save.hh>
-
-#include "tests/data.hh"
+#include <mln/draw/line.hh>
+#include <mln/draw/dashed_line.hh>
+#include <mln/data/fill.hh>
+#include <mln/data/compare.hh>
int main()
{
using namespace mln;
- using value::int_u8;
- image2d<bool> input = io::pbm::load(MLN_IMG_DIR "/small.pbm");
- image2d<int_u8> output = world::binary_2d::subsample(input, 3);
- io::pgm::save(output, "subsample-small.pgm");
+ point2d p1 = point2d(2,3);
+ point2d p2 = point2d(2,3);
+
+ image2d<bool> ima1(10,10);
+ data::fill(ima1, false);
+ draw::dashed_line(ima1, p1, p2, true);
+
+ image2d<bool> ima2(10,10);
+ data::fill(ima2, false);
+ draw::line(ima2, p1, p2, true);
+
+ mln_assertion(ima1 <= ima2);
}
--
1.7.10.4