Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DirectionS2.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 1999 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 // release : CGAL-2.2
33 // release_date : 2000, September 30
34 //
35 // source : webS2/S2.lw
36 // file : include/CGAL/SimpleCartesian/DirectionS2.h
37 // package : S2 (1.7)
38 // revision : 1.6
39 // revision_date : 27 Jun 2000
40 // author(s) : Stefan Schirra
41 // based on code by
42 // Andreas Fabri and
43 // Herve Brönnimann
44 //
45 // coordinator : MPI, Saarbrücken
46 // email : contact@cgal.org
47 // www : http://www.cgal.org
48 //
49 // ======================================================================
50 
51 #ifndef CGAL_DIRECTIONS2_H
52 #define CGAL_DIRECTIONS2_H
53 
54 #include <CGAL/SimpleCartesian/VectorS2.h>
55 
57 
58 template < class FT >
60 {
61 public:
62  DirectionS2();
63  DirectionS2(const VectorS2<FT>& v);
64  DirectionS2(const FT& x, const FT &y);
65 
66  bool operator==(const DirectionS2<FT>& d) const;
67  bool operator!=(const DirectionS2<FT>& d) const;
68  bool operator>=(const DirectionS2<FT>& d) const;
69  bool operator<=(const DirectionS2<FT>& d) const;
70  bool operator>(const DirectionS2<FT>& d) const;
71  bool operator<(const DirectionS2<FT>& d) const;
73  const DirectionS2<FT>& d2) const;
74 
75  VectorS2<FT> vector() const;
76 
79 
80  DirectionS2<FT> operator-() const;
81 
82  FT delta(int i) const;
83  FT dx() const;
84  FT dy() const;
85 
86 // private:
87  FT e0;
88  FT e1;
89 };
90 
91 
92 template < class FT >
95 
96 template < class FT >
99 { e0 = v.e0; e1 = v.e1; }
100 
101 template < class FT >
103 DirectionS2<FT>::DirectionS2(const FT& x, const FT &y)
104 { e0 = x; e1 = y; }
105 
106 template < class FT >
107 bool
109 {
110 // Use a S2 predicate for that ?
111  return (CGAL_NTS sign(dx()) == CGAL_NTS sign(d.dx()))
112  && (CGAL_NTS sign(dy()) == CGAL_NTS sign(d.dy()))
113  && (dy()*d.dx() == d.dy()*dx());
114 }
115 
116 template < class FT >
117 inline
118 bool
120 { return !( *this == d ); }
121 
122 template < class FT >
124 bool
126 {
127  int quadrant_this = (dx() >= FT(0)) ? ((dy() >= FT(0))?1:4)
128  : ((dy() >= FT(0))?2:3);
129  int quadrant_d = (d.dx() >= FT(0)) ? ((d.dy() >= FT(0))?1:4)
130  : ((d.dy() >= FT(0))?2:3);
131 
132  if(quadrant_this < quadrant_d)
133  return true;
134  else if (quadrant_this > quadrant_d)
135  return false;
136  else
137  return dy() * d.dx() < d.dy() * dx();
138 }
139 
140 template < class FT >
142 bool
144 { return d < *this ; }
145 
146 template < class FT >
148 bool
150 { return (d < *this) || (d == *this) ; }
151 
152 template < class FT >
154 bool
156 { return (*this < d) || (d == *this) ; }
157 
158 template < class FT >
160 bool
162  const DirectionS2<FT>& d2) const
163 {
164  if ( d1 < *this)
165  {
166  return ( *this < d2 )||( d2 <= d1 );
167  }
168  else
169  {
170  return ( *this < d2 )&&( d2 <= d1 );
171  }
172 }
173 
174 template < class FT >
175 inline
178 { return VectorS2<FT>(*this); }
179 
180 template < class FT >
184 {
186  if (o == COUNTERCLOCKWISE)
187  return DirectionS2<FT>(-dy(), dx());
188  else
189  return DirectionS2<FT>(dy(), -dx());
190 }
191 
192 template < class FT >
195 { return t.transform(*this); }
196 
197 template < class FT >
198 inline
200 { return DirectionS2<FT>(-dx(), -dy()); }
201 
202 
203 
204 template < class FT >
206 FT
208 {
209  CGAL_kernel_precondition( ( i == 0 ) || ( i == 1 ) );
210  return (i==0) ? dx() : dy();
211 }
212 
213 
214 template < class FT >
215 inline
216 FT
218 { return e0; }
219 
220 template < class FT >
221 inline
222 FT
224 { return e1; }
225 
226 
227 #ifndef CGAL_NO_OSTREAM_INSERT_DIRECTIONS2
228 template < class FT >
229 std::ostream
230 &operator<<(std::ostream& os, const DirectionS2<FT> &d)
231 {
232  VectorS2<FT> v = d.vector();
233  switch(os.iword(IO::mode)) {
234  case IO::ASCII :
235  return os << v.x() << ' ' << v.y();
236  case IO::BINARY :
237  write(os, v.x());
238  write(os, v.y());
239  return os;
240  default:
241  return os << "DirectionS2(" << v.x() << ", " << v.y() << ')';
242  }
243 }
244 #endif // CGAL_NO_OSTREAM_INSERT_DIRECTIONS2
245 
246 #ifndef CGAL_NO_ISTREAM_EXTRACT_DIRECTIONS2
247 
248 template < class FT >
249 std::istream
250 &operator>>(std::istream& is, DirectionS2<FT> &p)
251 {
252  FT x, y;
253  switch(is.iword(IO::mode)) {
254  case IO::ASCII :
255  is >> x >> y;
256  break;
257  case IO::BINARY :
258  read(is, x);
259  read(is, y);
260  break;
261  default:
262  std::cerr << std::endl << "Stream must be in ascii or binary mode" << std::endl;
263  break;
264  }
265  p = DirectionS2<FT>(x, y);
266  return is;
267 }
268 #endif // CGAL_NO_ISTREAM_EXTRACT_DIRECTIONS2
269 
270 
271 
273 
274 #endif
bool operator>(const DirectionS2< FT > &d) const
Definition: DirectionS2.h:143
#define CGAL_KERNEL_CTOR_INLINE
Definition: kernel_basic.h:57
DirectionS2< FT > operator-() const
Definition: DirectionS2.h:199
static SURF_BEGIN_NAMESPACE double sign(double x)
const NT & d
void int int REAL REAL * y
Definition: read.cpp:74
NT dx
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
const Orientation COUNTERCLOCKWISE
Definition: enum.h:70
bool operator==(const DirectionS2< FT > &d) const
Definition: DirectionS2.h:108
bool operator>=(const DirectionS2< FT > &d) const
Definition: DirectionS2.h:149
bool operator!=(const DirectionS2< FT > &d) const
Definition: DirectionS2.h:119
#define CGAL_KERNEL_MEDIUM_INLINE
Definition: kernel_basic.h:55
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
Definition: io.h:64
FT dx() const
Definition: DirectionS2.h:217
Sign
Definition: enum.h:57
DirectionS2< FT > perpendicular(const Orientation &o) const
Definition: DirectionS2.h:183
bool operator<(const DirectionS2< FT > &d) const
Definition: DirectionS2.h:125
bool operator<=(const DirectionS2< FT > &d) const
Definition: DirectionS2.h:155
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
VectorS2< FT > vector() const
Definition: DirectionS2.h:177
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
FT dy() const
Definition: DirectionS2.h:223
bool counterclockwise_in_between(const DirectionS2< FT > &d1, const DirectionS2< FT > &d2) const
Definition: DirectionS2.h:161
DirectionS2< FT > transform(const Aff_transformationS2< FT > &t) const
Definition: DirectionS2.h:194
static int mode
Definition: io.h:63
Definition: io.h:64
PointS2< FT > transform(const PointS2< FT > &p) const
NT dy
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
#define CGAL_NTS
FT delta(int i) const
Definition: DirectionS2.h:207
const Orientation COLLINEAR
Definition: enum.h:72
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
#define CGAL_kernel_precondition(EX)