DGtal 1.4.0
Loading...
Searching...
No Matches
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//-----------------------------------------------------------------------------
42template <typename TSpace>
43inline
44DGtal::ClosedIntegerHalfPlane<TSpace>::
45ClosedIntegerHalfPlane( const Vector & aN, const Integer & aC )
46 : N( aN ), c( aC )
47{}
48//-----------------------------------------------------------------------------
49template <typename TSpace>
50inline
51bool
52DGtal::ClosedIntegerHalfPlane<TSpace>::
53operator()( const Point & p ) const
54{
55 return N.dot( p ) <= c;
56}
57//-----------------------------------------------------------------------------
58template <typename TSpace>
59inline
60bool
61DGtal::ClosedIntegerHalfPlane<TSpace>::
62isOnBoundary( const Point & p ) const
63{
64 return N.dot( p ) == c;
65}
66//-----------------------------------------------------------------------------
67template <typename TSpace>
68inline
69typename DGtal::ClosedIntegerHalfPlane<TSpace>::Vector
70DGtal::ClosedIntegerHalfPlane<TSpace>::
71tangent() const
72{
73 return Vector( -N[ 1 ], N[ 0 ] );
74}
75//-----------------------------------------------------------------------------
76template <typename TSpace>
77inline
78void
79DGtal::ClosedIntegerHalfPlane<TSpace>::
80negate()
81{
82 N.negate(); // = Point( -N[ 0 ], -N[ 1 ] );
83 c = -c;
84}
85//-----------------------------------------------------------------------------
86//-----------------------------------------------------------------------------
87template <typename TSpace>
88inline
89DGtal::ClosedIntegerHalfPlane<TSpace>::
90ClosedIntegerHalfPlane( 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 */
116template <typename TSpace>
117inline
118void
119DGtal::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 */
128template <typename TSpace>
129inline
130bool
131DGtal::ClosedIntegerHalfPlane<TSpace>::isValid() const
132{
133 return true;
134}
135
136
137
138///////////////////////////////////////////////////////////////////////////////
139// Implementation of inline functions //
140
141template <typename TSpace>
142inline
143std::ostream&
144DGtal::operator<< ( std::ostream & out,
145 const ClosedIntegerHalfPlane<TSpace> & object )
146{
147 object.selfDisplay( out );
148 return out;
149}
150
151// //
152///////////////////////////////////////////////////////////////////////////////
153
154