DGtal 1.3.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>::~ClosedIntegerHalfPlane()
45{}
46//-----------------------------------------------------------------------------
47template <typename TSpace>
48inline
49DGtal::ClosedIntegerHalfPlane<TSpace>::
50ClosedIntegerHalfPlane( const Vector & aN, const Integer & aC )
51 : N( aN ), c( aC )
52{}
53//-----------------------------------------------------------------------------
54template <typename TSpace>
55inline
56bool
57DGtal::ClosedIntegerHalfPlane<TSpace>::
58operator()( const Point & p ) const
59{
60 return N.dot( p ) <= c;
61}
62//-----------------------------------------------------------------------------
63template <typename TSpace>
64inline
65bool
66DGtal::ClosedIntegerHalfPlane<TSpace>::
67isOnBoundary( const Point & p ) const
68{
69 return N.dot( p ) == c;
70}
71//-----------------------------------------------------------------------------
72template <typename TSpace>
73inline
74typename DGtal::ClosedIntegerHalfPlane<TSpace>::Vector
75DGtal::ClosedIntegerHalfPlane<TSpace>::
76tangent() const
77{
78 return Vector( -N[ 1 ], N[ 0 ] );
79}
80//-----------------------------------------------------------------------------
81template <typename TSpace>
82inline
83void
84DGtal::ClosedIntegerHalfPlane<TSpace>::
85negate()
86{
87 N.negate(); // = Point( -N[ 0 ], -N[ 1 ] );
88 c = -c;
89}
90//-----------------------------------------------------------------------------
91//-----------------------------------------------------------------------------
92template <typename TSpace>
93inline
94DGtal::ClosedIntegerHalfPlane<TSpace>::
95ClosedIntegerHalfPlane( 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
114///////////////////////////////////////////////////////////////////////////////
115// Interface - public :
116
117/**
118 * Writes/Displays the object on an output stream.
119 * @param out the output stream where the object is written.
120 */
121template <typename TSpace>
122inline
123void
124DGtal::ClosedIntegerHalfPlane<TSpace>::selfDisplay ( std::ostream & out ) const
125{
126 out << "[ClosedIntegerHalfPlane N=" << N << " c=" << c << " ]";
127}
128
129/**
130 * Checks the validity/consistency of the object.
131 * @return 'true' if the object is valid, 'false' otherwise.
132 */
133template <typename TSpace>
134inline
135bool
136DGtal::ClosedIntegerHalfPlane<TSpace>::isValid() const
137{
138 return true;
139}
140
141
142
143///////////////////////////////////////////////////////////////////////////////
144// Implementation of inline functions //
145
146template <typename TSpace>
147inline
148std::ostream&
149DGtal::operator<< ( std::ostream & out,
150 const ClosedIntegerHalfPlane<TSpace> & object )
151{
152 object.selfDisplay( out );
153 return out;
154}
155
156// //
157///////////////////////////////////////////////////////////////////////////////
158
159