Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SegmentS2.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/SegmentS2.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_SEGMENTS2_H
52 #define CGAL_SEGMENTS2_H
53 
55 
57 
58 template < class FT >
59 class SegmentS2
60 {
61 public:
62  SegmentS2();
63  SegmentS2(const PointS2<FT>& sp,
64  const PointS2<FT>& ep);
65 
66  bool is_horizontal() const;
67  bool is_vertical() const;
68  bool has_on(const PointS2<FT>& p) const;
69  bool collinear_has_on(const PointS2<FT>& p) const;
70 
71  bool operator==(const SegmentS2<FT>& s) const;
72  bool operator!=(const SegmentS2<FT>& s) const;
73  int id() const;
74 
75  const PointS2<FT>& start() const;
76  const PointS2<FT>& end() const;
77 
78  const PointS2<FT>& source() const;
79  const PointS2<FT>& target() const;
80 
81  PointS2<FT> min() const;
82  PointS2<FT> max() const;
83  PointS2<FT> vertex(int i) const;
84  PointS2<FT> point(int i) const;
85  PointS2<FT> operator[](int i) const;
86 
87  FT squared_length() const;
88 
89  DirectionS2<FT> direction() const;
91  SegmentS2<FT> opposite() const;
93 
94  bool is_degenerate() const;
95  Bbox_2 bbox() const;
96 
97 // private:
100 };
101 
102 template < class FT >
105 
106 template < class FT >
109  const PointS2<FT>& ep)
110  : s(sp), t(ep) {}
111 
112 
113 template < class FT >
114 inline
115 bool
117 { return ( (source() == s.source()) && (target() == s.target()) ); }
118 
119 template < class FT >
120 inline
121 bool
123 { return !(*this == s); }
124 
125 template < class FT >
126 inline
127 const PointS2<FT>&
129 { return s; }
130 
131 template < class FT >
132 inline
133 const PointS2<FT>&
135 { return t; }
136 
137 
138 template < class FT >
139 inline
140 const PointS2<FT>&
142 { return s; }
143 
144 template < class FT >
145 inline
146 const PointS2<FT>&
148 { return t; }
149 
150 
151 template < class FT >
155 {
156  return (lexicographically_xy_smaller(source(),target())) ? source()
157  : target();
158 }
159 
160 template < class FT >
164 {
165  return (lexicographically_xy_smaller(source(),target())) ? target()
166  : source();
167 }
168 
169 template < class FT >
173 { return (i%2 ==0) ? source() : target(); }
174 
175 template < class FT >
179 { return (i%2 ==0) ? source() : target(); }
180 
181 template < class FT >
182 inline
185 { return vertex(i); }
186 
187 template < class FT >
189 FT
191 { return squared_distance(source(), target()); }
192 
193 template < class FT >
197 { return DirectionS2<FT>( target() - source() ); }
198 
199 template < class FT >
200 inline
201 LineS2<FT>
203 { return LineS2<FT>(*this); }
204 
205 template < class FT >
206 inline
209 { return SegmentS2<FT>(target(), source()); }
210 
211 template < class FT >
212 inline
215 { return SegmentS2<FT>(t.transform(source()), t.transform(target())); }
216 
217 template < class FT >
219 Bbox_2
221 { return source().bbox() + target().bbox(); }
222 
223 template < class FT >
224 inline
225 bool
227 { return (source() == target()); }
228 
229 
230 #ifndef CGAL_NO_OSTREAM_INSERT_SEGMENTS2
231 template < class FT >
232 std::ostream& operator<<(std::ostream &os, const SegmentS2<FT> &s)
233 {
234  switch(os.iword(IO::mode)) {
235  case IO::ASCII :
236  return os << s.source() << ' ' << s.target();
237  case IO::BINARY :
238  return os << s.source() << s.target();
239  default:
240  return os << "SegmentS2(" << s.source() << ", " << s.target() << ")";
241  }
242 }
243 #endif // CGAL_NO_OSTREAM_INSERT_SEGMENTS2
244 
245 #ifndef CGAL_NO_ISTREAM_EXTRACT_SEGMENTS2
246 template < class FT >
247 std::istream& operator>>(std::istream &is, SegmentS2<FT> &s)
248 {
249  PointS2<FT> p, q;
250 
251  is >> p >> q;
252 
253  s = SegmentS2<FT>(p, q);
254  return is;
255 }
256 #endif // CGAL_NO_ISTREAM_EXTRACT_SEGMENTS2
257 
258 template < class FT >
260 bool
262 { return source().y() == target().y(); }
263 
264 template < class FT >
266 bool
268 { return source().x() == target().x(); }
269 
270 template < class FT >
272 bool
274 {
275  return(( p == source() )
276  || ( p == target() )
277  || ( collinear(source(), p, target())
278  && ( DirectionS2<FT>(p - source())
279  !=
280  DirectionS2<FT>(p - target()))
281  )
282  );
283 }
284 
285 
286 template < class FT >
288 bool
290 {
291  CGAL_kernel_exactness_precondition( collinear(source(), p, target()) );
292  if (CGAL_NTS abs(target().x()-source().x())
293  > CGAL_NTS abs(target().y()-source().y())) {
294  if (p.x() < source().x())
295  return (p.x() >= target().x());
296  if (p.x() <= target().x())
297  return true;
298  return (p.x() == source().x());
299  } else {
300  if (p.y() < source().y())
301  return (p.y() >= target().y());
302  if (p.y() <= target().y())
303  return true;
304  return (p.y() == source().y());
305  }
306 }
307 
308 
310 
311 #endif
PointS2< FT > t
Definition: SegmentS2.h:99
PointS2< FT > max() const
Definition: SegmentS2.h:163
#define CGAL_KERNEL_CTOR_INLINE
Definition: kernel_basic.h:57
PointS2< FT > point(int i) const
Definition: SegmentS2.h:178
void int int REAL REAL * y
Definition: read.cpp:74
double s
Definition: blastest.C:80
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
bool lexicographically_xy_smaller(const Point_2< R > &p, const Point_2< R > &q)
bool has_on(const PointS2< FT > &p) const
Definition: SegmentS2.h:273
#define CGAL_KERNEL_MEDIUM_INLINE
Definition: kernel_basic.h:55
const PointS2< FT > & start() const
Definition: SegmentS2.h:128
bool operator!=(const SegmentS2< FT > &s) const
Definition: SegmentS2.h:122
Definition: io.h:64
PointS2< FT > s
Definition: SegmentS2.h:98
bool operator==(const SegmentS2< FT > &s) const
Definition: SegmentS2.h:116
bool is_degenerate() const
Definition: SegmentS2.h:226
FT squared_distance(const PointS3< FT > &p, const PointS3< FT > &q)
bool collinear(const Point_2< R > &p, const Point_2< R > &q, const Point_2< R > &r)
int id() const
SegmentS2< FT > opposite() const
Definition: SegmentS2.h:208
PointS2< FT > operator[](int i) const
Definition: SegmentS2.h:184
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
PointS2< FT > min() const
Definition: SegmentS2.h:154
static int mode
Definition: io.h:63
bool is_vertical() const
Definition: SegmentS2.h:267
Definition: io.h:64
bool collinear_has_on(const PointS2< FT > &p) const
Definition: SegmentS2.h:289
#define CGAL_kernel_exactness_precondition(EX)
Definition: LineS2.h:62
PointS2< FT > transform(const PointS2< FT > &p) const
const PointS2< FT > & end() const
Definition: SegmentS2.h:134
const PointS2< FT > & source() const
Definition: SegmentS2.h:141
NT q
FT squared_length() const
Definition: SegmentS2.h:190
SegmentS2< FT > transform(const Aff_transformationS2< FT > &t) const
Definition: SegmentS2.h:214
NT abs(const NT &x)
Definition: number_utils.h:130
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
const PointS2< FT > & target() const
Definition: SegmentS2.h:147
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
DirectionS2< FT > direction() const
Definition: SegmentS2.h:196
#define CGAL_NTS
PointS2< FT > vertex(int i) const
Definition: SegmentS2.h:172
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
LineS2< FT > supporting_line() const
Definition: SegmentS2.h:202
Bbox_2 bbox() const
Definition: SegmentS2.h:220
bool is_horizontal() const
Definition: SegmentS2.h:261