positive.hh 2.76 KB
Newer Older
1
2
// Copyright (C) 2007, 2008, 2009, 2011, 2014 EPITA Research and
// Development Laboratory (LRDE).
3
//
4
// This file is part of Olena.
5
//
6
7
8
9
10
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
11
12
13
14
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
16
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
17
18
//
// As a special exception, you may use this file as part of a free
19
// software project without restriction.  Specifically, if other files
20
// instantiate templates or use macros or inline functions from this
21
22
23
24
25
// 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
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
26
27
28
29

#ifndef MLN_TEST_POSITIVE_HH
# define MLN_TEST_POSITIVE_HH

30
/// \file
31
///
32
33
/// Test if an image only contains positive or null
/// (i.e. ``non-negative'') values.
34
35
36
37

# include <mln/test/predicate.hh>
# include <mln/pw/all.hh>
# include <mln/fun/v2v/id.hh>
38
# include <mln/literal/zero.hh>
39
40
41
42
43
44
45
46


namespace mln
{

  namespace test
  {

47
48
49
50
51
52
53
    /// \brief Test if an image only contains positive or null
    /// (i.e. ``non-negative'') values.
    ///
    /// This routine checks whether all the values of an image are
    /// non-negative, thus considering includes 0 as a valid value
    /// (which is usually not the case of the term ``positive'' in
    /// English).
54
55
56
57
58
59
60
    template <typename I>
    bool positive(const Image<I>& input);

  
# ifndef MLN_INCLUDE_ONLY

    template <typename I>
61
    inline
62
63
    bool positive(const Image<I>& input_)
    {
Guillaume Lazzara's avatar
Guillaume Lazzara committed
64
      mln_trace("test::positive");
65

66
      const I& input = exact(input_);
67
      mln_precondition(input.is_valid());
68
69
70
      /* FIXME: Below the '>=' op should properly work with
	 signed/unsigned without warnings; so we really need to
	 overload ops for functions when literals are involved.  */
71
      mln_value(I) zero_ = literal::zero;
72
73
      bool res = test::predicate(input.domain(),
				 pw::value(input) >= pw::cst(zero_));
74
      /* FIXME: test the version below.  */
75
76
//       return test::predicate(input,
// 			     fun::v2v::id<mln_value(I)>() >= pw::cst(0));
77
78

      return res;
79
80
81
82
83
84
85
86
87
88
    }

# endif // ! MLN_INCLUDE_ONLY

  } // end of namespace mln::test

} // end of namespace mln


#endif // ! MLN_TEST_POSITIVE_HH