DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ClosedIntegerHalfPlane.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
41 //-----------------------------------------------------------------------------
42 template <typename TSpace>
43 inline
45 {}
46 //-----------------------------------------------------------------------------
47 template <typename TSpace>
48 inline
50 ClosedIntegerHalfPlane( const Vector & aN, const Integer & aC )
51  : N( aN ), c( aC )
52 {}
53 //-----------------------------------------------------------------------------
54 template <typename TSpace>
55 inline
56 bool
58 operator()( const Point & p ) const
59 {
60  return N.dot( p ) <= c;
61 }
62 //-----------------------------------------------------------------------------
63 template <typename TSpace>
64 inline
65 bool
67 isOnBoundary( const Point & p ) const
68 {
69  return N.dot( p ) == c;
70 }
71 //-----------------------------------------------------------------------------
72 template <typename TSpace>
73 inline
76 tangent() const
77 {
78  return Vector( -N[ 1 ], N[ 0 ] );
79 }
80 //-----------------------------------------------------------------------------
81 template <typename TSpace>
82 inline
83 void
86 {
87  N.negate(); // = Point( -N[ 0 ], -N[ 1 ] );
88  c = -c;
89 }
90 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
92 template <typename TSpace>
93 inline
95 ClosedIntegerHalfPlane( const Point & A, const Point & B,
96  const Point & inP, IntegerComputer<Integer> & ic )
97 {
98  N[ 0 ] = A[ 1 ] - B[ 1 ];
99  N[ 1 ] = B[ 0 ] - A[ 0 ];
100  ic.getDotProduct( c, N, A );
101  Integer c1;
102  ic.getDotProduct( c1, N, inP );
103  if ( c1 > c )
104  {
105  N.negate();
106  c = -c;
107  }
108  //simplification of the constraint
109  Integer g = ic.gcd( N[ 0 ], N[ 1 ] );
110  N /= g;
111  ic.floorDiv( c, g );
112 }
113 
115 // Interface - public :
116 
121 template <typename TSpace>
122 inline
123 void
125 {
126  out << "[ClosedIntegerHalfPlane N=" << N << " c=" << c << " ]";
127 }
128 
133 template <typename TSpace>
134 inline
135 bool
137 {
138  return true;
139 }
140 
141 
142 
144 // Implementation of inline functions //
145 
146 template <typename TSpace>
147 inline
148 std::ostream&
149 DGtal::operator<< ( std::ostream & out,
150  const ClosedIntegerHalfPlane<TSpace> & object )
151 {
152  object.selfDisplay( out );
153  return out;
154 }
155 
156 // //
158 
159