Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Line_2_Line_2_intersection.h
Go to the documentation of this file.
1 
2 // ======================================================================
3 //
4 // Copyright (c) 2000 The CGAL Consortium
5 
6 // This software and related documentation is part of the Computational
7 // Geometry Algorithms Library (CGAL).
8 // This software and documentation is provided "as-is" and without warranty
9 // of any kind. In no event shall the CGAL Consortium be liable for any
10 // damage of any kind.
11 //
12 // Every use of CGAL requires a license.
13 //
14 // Academic research and teaching license
15 // - For academic research and teaching purposes, permission to use and copy
16 // the software and its documentation is hereby granted free of charge,
17 // provided that it is not a component of a commercial product, and this
18 // notice appears in all copies of the software and related documentation.
19 //
20 // Commercial licenses
21 // - A commercial license is available through Algorithmic Solutions, who also
22 // markets LEDA (http://www.algorithmic-solutions.de).
23 // - Commercial users may apply for an evaluation license by writing to
24 // Algorithmic Solutions (contact@algorithmic-solutions.com).
25 //
26 // The CGAL Consortium consists of Utrecht University (The Netherlands),
27 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
28 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
29 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
30 // and Tel-Aviv University (Israel).
31 //
32 // ----------------------------------------------------------------------
33 //
34 // release : CGAL-2.2
35 // release_date : 2000, September 30
36 //
37 // file : include/CGAL/Line_2_Line_2_intersection.h
38 // package : Intersections_2 (2.6.3)
39 // source : intersection_2_1.fw
40 // author(s) : Geert-Jan Giezeman
41 //
42 // coordinator : Saarbruecken
43 //
44 // email : contact@cgal.org
45 // www : http://www.cgal.org
46 //
47 // ======================================================================
48 
49 
50 #ifndef CGAL_LINE_2_LINE_2_INTERSECTION_H
51 #define CGAL_LINE_2_LINE_2_INTERSECTION_H
52 
53 #include <CGAL/Line_2.h>
54 #include <CGAL/Point_2.h>
55 #include <CGAL/utils.h>
56 #include <CGAL/number_utils.h>
57 
59 
60 template <class R>
62 public:
65  Line_2_Line_2_pair(Line_2<R> const *line1,
66  Line_2<R> const *line2);
68 
69 #ifndef CGAL_CFG_RETURN_TYPE_BUG_2
71 
72 #else
74 {
75  typedef typename R::RT RT;
76  if (_known)
77  return _result;
78  RT nom1, nom2, denom;
79  // The non const this pointer is used to cast away const.
80  _known = true;
81  denom = _line1->a()*_line2->b() - _line2->a()*_line1->b();
82  if (denom == RT(0)) {
83  if (RT(0) == (_line1->a()*_line2->c() - _line2->a()*_line1->c()) &&
84  RT(0) == (_line1->b()*_line2->c() - _line2->b()*_line1->c()))
85  _result = LINE;
86  else
87  _result = NO;
88  return _result;
89  }
90  nom1 = (_line1->b()*_line2->c() - _line2->b()*_line1->c());
91  if (!::CGAL::is_finite(nom1)) {
92  _result = NO;
93  return _result;
94  }
95  nom2 = (_line2->a()*_line1->c() - _line1->a()*_line2->c());
96  if (!::CGAL::is_finite(nom2)) {
97  _result = NO;
98  return _result;
99  }
100  R dummyR;
102  nom1, nom2, denom, dummyR)){
103  _result = NO;
104  return _result;
105  }
106  _result = POINT;
107  return _result;
108 }
109 
110 #endif // CGAL_CFG_RETURN_TYPE_BUG_2
111 
112  bool intersection(Point_2<R> &result) const;
113  bool intersection(Line_2<R> &result) const;
114 protected:
116  Line_2<R> const * _line2;
117  mutable bool _known;
120 };
121 
122 template <class R>
123 inline bool do_intersect(
124  const Line_2<R> &p1,
125  const Line_2<R> &p2)
126 {
127  typedef Line_2_Line_2_pair<R> pair_t;
128  pair_t pair(&p1, &p2);
129  return pair.intersection_type() != pair_t::NO;
130 }
131 
133 
134 #include <CGAL/Object.h>
135 
137 
138 template <class R>
139 Object
140 intersection(const Line_2<R> &line1, const Line_2<R> &line2)
141 {
142  typedef Line_2_Line_2_pair<R> is_t;
143  is_t linepair(&line1, &line2);
144  switch (linepair.intersection_type()) {
145  case is_t::NO:
146  default:
147  return Object();
148  case is_t::POINT: {
149  Point_2<R> pt;
150  linepair.intersection(pt);
151  return Object(new Wrapper< Point_2<R> >(pt));
152  }
153  case is_t::LINE:
154  return Object(new Wrapper< Line_2<R> >(line1));
155  }
156 }
157 
159 
160 
161 
163 
164 template <class R, class POINT, class RT>
165 bool construct_if_finite(POINT &pt, RT x, RT y, RT w, R &)
166 {
167  typedef typename R::FT FT;
169  && ::CGAL::is_finite(y)
170  && w != RT(0));
171 
172  if (!::CGAL::is_finite(FT(x)/FT(w)) || !::CGAL::is_finite(FT(y)/FT(w)))
173  return false;
174  pt = POINT(x, y, w);
175  return true;
176 }
177 
179 
180 
182 
183 template <class R>
185 {
186  _line1 = 0;
187  _line2 = 0;
188  _known = false;
189 }
190 
191 template <class R>
193  Line_2<R> const *line1, Line_2<R> const *line2)
194 {
195  _line1 = line1;
196  _line2 = line2;
197  _known = false;
198 }
199 
200 #ifndef CGAL_CFG_RETURN_TYPE_BUG_2
201 template <class R>
204 {
205  typedef typename R::RT RT;
206  if (_known)
207  return _result;
208  RT nom1, nom2, denom;
209  // The non const this pointer is used to cast away const.
210  _known = true;
211  denom = _line1->a()*_line2->b() - _line2->a()*_line1->b();
212  if (denom == RT(0)) {
213  if (RT(0) == (_line1->a()*_line2->c() - _line2->a()*_line1->c()) &&
214  RT(0) == (_line1->b()*_line2->c() - _line2->b()*_line1->c()))
215  _result = LINE;
216  else
217  _result = NO;
218  return _result;
219  }
220  nom1 = (_line1->b()*_line2->c() - _line2->b()*_line1->c());
221  if (!::CGAL::is_finite(nom1)) {
222  _result = NO;
223  return _result;
224  }
225  nom2 = (_line2->a()*_line1->c() - _line1->a()*_line2->c());
226  if (!::CGAL::is_finite(nom2)) {
227  _result = NO;
228  return _result;
229  }
230  R dummyR;
231  if (!construct_if_finite(_intersection_point,
232  nom1, nom2, denom, dummyR)){
233  _result = NO;
234  return _result;
235  }
236  _result = POINT;
237  return _result;
238 }
239 
240 #endif // CGAL_CFG_RETURN_TYPE_BUG_2
241 
242 template <class R>
243 bool
245 {
246  if (!_known)
247  intersection_type();
248  if (_result != POINT)
249  return false;
250  pt = _intersection_point;
251  return true;
252 }
253 
254 template <class R>
255 bool
257 {
258  if (!_known)
259  intersection_type();
260  if (_result != LINE)
261  return false;
262  l = *_line1;
263  return true;
264 }
265 
267 
268 
269 
270 #endif
void int int REAL REAL * y
Definition: read.cpp:74
NT p1
CGAL_END_NAMESPACE CGAL_BEGIN_NAMESPACE Object intersection(const Line_2< R > &line1, const Line_2< R > &line2)
bool do_intersect(const Line_2< R > &p1, const Line_2< R > &p2)
CGAL_END_NAMESPACE CGAL_BEGIN_NAMESPACE bool construct_if_finite(POINT &pt, RT x, RT y, RT w, R &)
Intersection_results _result
RT c() const
Definition: Line_2.h:150
bool intersection(Point_2< R > &result) const
void int int REAL * x
Definition: read.cpp:74
bool is_finite(double d)
Definition: double.h:190
Intersection_results intersection_type() const
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
RT b() const
Definition: Line_2.h:145
CGAL_BEGIN_NAMESPACE void const NT NT NT NT & denom
#define CGAL_kernel_precondition(EX)
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
RT a() const
Definition: Line_2.h:140