Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RayS2.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/RayS2.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_RAYS2_H
52 #define CGAL_RAYS2_H
53 
54 #include <CGAL/SimpleCartesian/PointS2.h>
56 
58 
59 template < class FT >
60 class RayS2
61 {
62 public:
63  RayS2() {};
64  RayS2(const PointS2<FT>& sp,
65  const PointS2<FT>& secondp) : s(sp), t(secondp) {};
66  RayS2(const PointS2<FT>& sp,
67  const DirectionS2<FT>& d);
68 
69 
70  bool operator==(const RayS2<FT>& r) const;
71  bool operator!=(const RayS2<FT>& r) const;
72 
73  const PointS2<FT>& start() const;
74  const PointS2<FT>& source() const;
75 
76  PointS2<FT> point(int i) const;
77  PointS2<FT> second_point() const;
78 
79  DirectionS2<FT> direction() const;
81  RayS2<FT> opposite() const;
82 
84 
85  bool is_horizontal() const;
86  bool is_vertical() const;
87  bool is_degenerate() const;
88  bool has_on(const PointS2<FT>& p) const;
89  bool collinear_has_on(const PointS2<FT>& p) const;
90 
91 // private:
94 };
95 
96 
97 template < class FT >
100 { s = sp; t = sp + d.vector(); }
101 
102 template < class FT >
104 bool
106 { return ((source() == r.source()) && (direction() == r.direction()) ); }
107 
108 template < class FT >
109 bool
111 { return !(*this == r); }
112 
113 template < class FT >
114 inline
115 const PointS2<FT>&
117 { return s; }
118 
119 template < class FT >
120 inline
121 const PointS2<FT>&
123 { return s; }
124 
125 template < class FT >
126 inline
129 { return t; }
130 
131 template < class FT >
134 RayS2<FT>::point(int i) const
135 {
136  CGAL_kernel_precondition( i >= 0 );
137  if (i == 0)
138  return s;
139 
140  if (i == 1)
141  return t;
142 
143  return source() + FT(i) * (second_point() - source());
144 }
145 
146 template < class FT >
147 inline
150 { return DirectionS2<FT>( second_point() - source() ); }
151 
152 template < class FT >
153 inline
155 { return LineS2<FT>(*this); }
156 
157 template < class FT >
158 inline
160 { return RayS2<FT>( source(), - direction() ); }
161 
162 
163 template < class FT >
165 RayS2<FT>
167 { return RayS2<FT>(t.transform(source()), t.transform(second_point())); }
168 
169 
170 template < class FT >
172 bool
174 { return (source().y() == second_point().y()); }
175 
176 template < class FT >
178 bool
180 { return (source().x() == second_point().x()); }
181 
182 template < class FT >
184 bool
186 { return (source() == second_point()); }
187 
188 template < class FT >
190 bool
192 {
193  return ( p == source()
194  || ( collinear(source(), p, second_point())
195  && ( DirectionS2<FT>(p - source()) == direction() )));
196 }
197 
198 template < class FT >
200 bool
202 {
203  switch(compare_x(source(), second_point())){
204  case SMALLER:
205  return compare_x(source(), p) != LARGER;
206  case LARGER:
207  return compare_x(p, source()) != LARGER;
208  default:
209  switch(compare_y(source(), second_point())){
210  case SMALLER:
211  return compare_y(source(), p) != LARGER;
212  case LARGER:
213  return compare_y(p, source()) != LARGER;
214  default:
215  return true; // p == source()
216  }
217  }
218 }
219 
220 
221 #ifndef CGAL_NO_OSTREAM_INSERT_RAYS2
222 template < class FT >
223 std::ostream& operator<<(std::ostream &os, const RayS2<FT> &r)
224 {
225  switch(os.iword(IO::mode)) {
226  case IO::ASCII :
227  return os << r.source() << ' ' << r.direction();
228  case IO::BINARY :
229  return os << r.source() << r.direction();
230  default:
231  return os << "RayS2(" << r.source() << ", " << r.direction() << ")";
232  }
233 }
234 #endif // CGAL_NO_OSTREAM_INSERT_RAYS2
235 
236 #ifndef CGAL_NO_ISTREAM_EXTRACT_RAYS2
237 template < class FT >
238 std::istream& operator>>(std::istream &is, RayS2<FT> &r)
239 {
240  PointS2<FT> p;
242 
243  is >> p >> d;
244 
245  r = RayS2<FT>(p, d);
246  return is;
247 }
248 #endif // CGAL_NO_ISTREAM_EXTRACT_RAYS2
249 
250 
251 
253 
254 #endif
RayS2(const PointS2< FT > &sp, const PointS2< FT > &secondp)
Definition: RayS2.h:64
#define CGAL_KERNEL_CTOR_INLINE
Definition: kernel_basic.h:57
Comparison_result compare_y(const Point_2< R > &p, const Point_2< R > &q)
const NT & d
void int int REAL REAL * y
Definition: read.cpp:74
LineS2< FT > supporting_line() const
Definition: RayS2.h:154
double s
Definition: blastest.C:80
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
bool is_vertical() const
Definition: RayS2.h:179
bool operator!=(const RayS2< FT > &r) const
Definition: RayS2.h:110
Definition: enum.h:96
#define CGAL_KERNEL_MEDIUM_INLINE
Definition: kernel_basic.h:55
DirectionS2< FT > direction() const
Definition: RayS2.h:149
Definition: io.h:64
bool collinear_has_on(const PointS2< FT > &p) const
Definition: RayS2.h:201
PointS2< FT > second_point() const
Definition: RayS2.h:128
Comparison_result compare_x(const Point_2< R > &p, const Point_2< R > &q)
const PointS2< FT > & start() const
Definition: RayS2.h:116
Definition: RayS2.h:60
bool has_on(const PointS2< FT > &p) const
Definition: RayS2.h:191
const PointS2< FT > & source() const
Definition: RayS2.h:122
bool collinear(const Point_2< R > &p, const Point_2< R > &q, const Point_2< R > &r)
bool is_horizontal() const
Definition: RayS2.h:173
VectorS2< FT > vector() const
Definition: DirectionS2.h:177
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
static int mode
Definition: io.h:63
Definition: io.h:64
PointS2< FT > s
Definition: RayS2.h:92
PointS2< FT > point(int i) const
Definition: RayS2.h:134
bool operator==(const RayS2< FT > &r) const
Definition: RayS2.h:105
Definition: LineS2.h:62
PointS2< FT > transform(const PointS2< FT > &p) const
RayS2()
Definition: RayS2.h:63
Definition: enum.h:98
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
PointS2< FT > t
Definition: RayS2.h:93
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
bool is_degenerate() const
Definition: RayS2.h:185
RayS2< FT > opposite() const
Definition: RayS2.h:159
RayS2< FT > transform(const Aff_transformationS2< FT > &t) const
Definition: RayS2.h:166
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
#define CGAL_kernel_precondition(EX)