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.
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.
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/>.
18 * @file PolarPointComparatorBy2x2DetComputer.ih
19 * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in PolarPointComparatorBy2x2DetComputer.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
40 // ------------------------------------------------------------------------
41 template <typename TPoint, typename TDetComputer>
43 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
44 ::PolarPointComparatorBy2x2DetComputer()
45 : myPole( NumberTraits<Coordinate>::ZERO, NumberTraits<Coordinate>::ZERO ),
51 // ------------------------------------------------------------------------
52 template <typename TPoint, typename TDetComputer>
54 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
55 ::PolarPointComparatorBy2x2DetComputer(const Point& aPoint)
62 // ------------------------------------------------------------------------
63 template <typename TPoint, typename TDetComputer>
65 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
66 ::PolarPointComparatorBy2x2DetComputer( const PolarPointComparatorBy2x2DetComputer & other )
67 : myPole( other.myPole ),
68 myDetComputer( other.myDetComputer ),
69 myThresholder( other.myThresholder )
73 // ------------------------------------------------------------------------
74 template <typename TPoint, typename TDetComputer>
76 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>&
77 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
78 ::operator=( const PolarPointComparatorBy2x2DetComputer & other )
82 myPole = other.myPole;
83 myDetComputer = other.myDetComputer;
84 myThresholder = other.myThresholder;
89 // ------------------------------------------------------------------------
90 template <typename TPoint, typename TDetComputer>
93 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
94 ::setPole ( const Point& aPole )
99 // ------------------------------------------------------------------------
100 template <typename TPoint, typename TDetComputer>
103 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
104 ::selfDisplay ( std::ostream & out ) const
106 out << "[PolarPointComparatorBy2x2DetComputer]";
109 // ------------------------------------------------------------------------
110 template <typename TPoint, typename TDetComputer>
113 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
119 // ------------------------------------------------------------------------
120 template <typename TPoint, typename TDetComputer>
123 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
124 ::isBefore( const Vector& aU, const Vector& aV) const
126 //the two y-coordinates must have the same sign
127 //the y-coordinate of aU must not be zero
128 ASSERT( ( (aU[1] > NumberTraits<Coordinate>::ZERO) &&
129 (aV[1] >= NumberTraits<Coordinate>::ZERO) ) ||
130 ( (aU[1] < NumberTraits<Coordinate>::ZERO) &&
131 (aV[1] <= NumberTraits<Coordinate>::ZERO) ) );
133 ResultInteger det = myDetComputer( aU[0], aU[1], aV[0], aV[1] );
135 if ( det == NumberTraits<ResultInteger>::ZERO )
136 { //aU is before aV iff the norm of aU is smaller than the one of aV.
137 //we compute the determinant of
138 // aV[1]+aU[1] , aV[0]-aU[0] , -aV[0]-aU[0] , aV[1]-aU[1]
139 //which is equal to aV[0]*aV[0] + aV[1]*aV[1] - aU[0]*aU[0] - aU[1]*aU[1]
140 return myThresholder( myDetComputer( aV[1]+aU[1] , aV[0]-aU[0] , -aV[0]-aU[0] , aV[1]-aU[1] ) );
144 return myThresholder( det );
148 // ------------------------------------------------------------------------
149 template <typename TPoint, typename TDetComputer>
152 DGtal::functors::PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer>
153 ::operator()(const Point& aPoint1, const Point& aPoint2) const
155 Vector u = aPoint1 - myPole;
156 Vector v = aPoint2 - myPole;
158 if ( u[1] == NumberTraits<Coordinate>::ZERO )
160 if ( v[1] == NumberTraits<Coordinate>::ZERO )
162 if ( u[0] >= NumberTraits<Coordinate>::ZERO )
164 return ( ( v[0] < NumberTraits<Coordinate>::ZERO )
169 return (v[0] < u[0]);
172 else if ( v[1] > NumberTraits<Coordinate>::ZERO )
174 return ( u[0] >= NumberTraits<Coordinate>::ZERO );
181 else if ( u[1] > NumberTraits<Coordinate>::ZERO )
183 if ( v[1] == NumberTraits<Coordinate>::ZERO )
185 return ( v[0] < NumberTraits<Coordinate>::ZERO );
187 else if ( v[1] > NumberTraits<Coordinate>::ZERO )
189 return isBefore(u, v);
198 if ( v[1] < NumberTraits<Coordinate>::ZERO )
200 return isBefore(u, v);
209 ///////////////////////////////////////////////////////////////////////////////
210 // Implementation of inline functions //
212 template <typename TPoint, typename TDetComputer>
215 DGtal::functors::operator<< ( std::ostream & out,
216 const PolarPointComparatorBy2x2DetComputer<TPoint,TDetComputer> & object )
218 object.selfDisplay( out );
223 ///////////////////////////////////////////////////////////////////////////////