DGtal  1.5.beta
ClosedIntegerHalfPlane.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file ClosedIntegerHalfPlane.ih
19  * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20  * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
21  *
22  * @date 2012/04/27
23  *
24  * Implementation of inline methods defined in ClosedIntegerHalfPlane.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 //////////////////////////////////////////////////////////////////////////////
33 
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
40 
41 //-----------------------------------------------------------------------------
42 template <typename TSpace>
43 inline
44 DGtal::ClosedIntegerHalfPlane<TSpace>::
45 ClosedIntegerHalfPlane( const Vector & aN, const Integer & aC )
46  : N( aN ), c( aC )
47 {}
48 //-----------------------------------------------------------------------------
49 template <typename TSpace>
50 inline
51 bool
52 DGtal::ClosedIntegerHalfPlane<TSpace>::
53 operator()( const Point & p ) const
54 {
55  return N.dot( p ) <= c;
56 }
57 //-----------------------------------------------------------------------------
58 template <typename TSpace>
59 inline
60 bool
61 DGtal::ClosedIntegerHalfPlane<TSpace>::
62 isOnBoundary( const Point & p ) const
63 {
64  return N.dot( p ) == c;
65 }
66 //-----------------------------------------------------------------------------
67 template <typename TSpace>
68 inline
69 typename DGtal::ClosedIntegerHalfPlane<TSpace>::Vector
70 DGtal::ClosedIntegerHalfPlane<TSpace>::
71 tangent() const
72 {
73  return Vector( -N[ 1 ], N[ 0 ] );
74 }
75 //-----------------------------------------------------------------------------
76 template <typename TSpace>
77 inline
78 void
79 DGtal::ClosedIntegerHalfPlane<TSpace>::
80 negate()
81 {
82  N.negate(); // = Point( -N[ 0 ], -N[ 1 ] );
83  c = -c;
84 }
85 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
87 template <typename TSpace>
88 inline
89 DGtal::ClosedIntegerHalfPlane<TSpace>::
90 ClosedIntegerHalfPlane( const Point & A, const Point & B,
91  const Point & inP, IntegerComputer<Integer> & ic )
92 {
93  N[ 0 ] = A[ 1 ] - B[ 1 ];
94  N[ 1 ] = B[ 0 ] - A[ 0 ];
95  ic.getDotProduct( c, N, A );
96  Integer c1;
97  ic.getDotProduct( c1, N, inP );
98  if ( c1 > c )
99  {
100  N.negate();
101  c = -c;
102  }
103  //simplification of the constraint
104  Integer g = ic.gcd( N[ 0 ], N[ 1 ] );
105  N /= g;
106  ic.floorDiv( c, g );
107 }
108 
109 ///////////////////////////////////////////////////////////////////////////////
110 // Interface - public :
111 
112 /**
113  * Writes/Displays the object on an output stream.
114  * @param out the output stream where the object is written.
115  */
116 template <typename TSpace>
117 inline
118 void
119 DGtal::ClosedIntegerHalfPlane<TSpace>::selfDisplay ( std::ostream & out ) const
120 {
121  out << "[ClosedIntegerHalfPlane N=" << N << " c=" << c << " ]";
122 }
123 
124 /**
125  * Checks the validity/consistency of the object.
126  * @return 'true' if the object is valid, 'false' otherwise.
127  */
128 template <typename TSpace>
129 inline
130 bool
131 DGtal::ClosedIntegerHalfPlane<TSpace>::isValid() const
132 {
133  return true;
134 }
135 
136 
137 
138 ///////////////////////////////////////////////////////////////////////////////
139 // Implementation of inline functions //
140 
141 template <typename TSpace>
142 inline
143 std::ostream&
144 DGtal::operator<< ( std::ostream & out,
145  const ClosedIntegerHalfPlane<TSpace> & object )
146 {
147  object.selfDisplay( out );
148  return out;
149 }
150 
151 // //
152 ///////////////////////////////////////////////////////////////////////////////
153 
154