vgl_lineseg_test.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_lineseg_test.h
2 #ifndef vgl_lineseg_test_h_
3 #define vgl_lineseg_test_h_
4 //:
5 // \file
6 // \author fsm
7 // \verbatim
8 // Modifications
9 // Nov.2003 - Peter Vanroose - made all functions templated
10 // Sep.2005 - Peter Vanroose - bug fix: collinear line segments always "true"
11 // Mar.2008 - Ibrahim Eden - bug fix: bool vgl_lineseg_test_line(vgl_line_2d<T> const& l1,vgl_line_segment_2d<T> const& l2)
12 // Mar.2009 - Dirk Steckhan - bug fix in vgl_lineseg_test_point (missing sqrt)
13 // \endverbatim
14 
15 #include <cmath>
17 #include <vgl/vgl_line_2d.h>
18 #include <vgl/vgl_point_2d.h>
19 #ifdef _MSC_VER
20 # include <vcl_msvc_warnings.h>
21 #endif
22 
23 // The old signature vgl_lineseg_test() was incorrectly documented. Its
24 // meaning was the same as the new vgl_lineseg_test_line(). Only you can
25 // decide which one you want.
26 
27 //: true if the line joining [1], [2] meets the linesegment joining [3], [4].
28 // End points are considered to belong to a line segment.
29 template <class T>
30 bool vgl_lineseg_test_line(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4);
31 
32 //: true if the linesegment joining [1], [2] meets the linesegment joining [3], [4].
33 // End points are considered to belong to a line segment.
34 template <class T>
35 bool vgl_lineseg_test_lineseg(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4);
36 
37 //: true if the line meets the linesegment.
38 // End points are considered to belong to a line segment.
39 // \relatesalso vgl_line_2d
40 // \relatesalso vgl_line_segment_2d
41 template <class T>
42 inline bool vgl_lineseg_test_line(vgl_line_2d<T> const& l1,
43  vgl_line_segment_2d<T> const& l2)
44 {
45  vgl_point_2d<T> l1_p1,l1_p2;
46  l1.get_two_points(l1_p1,l1_p2);
47  return vgl_lineseg_test_line(l1_p1.x(),l1_p1.y(),
48  l1_p2.x(),l1_p2.y(),
49  l2.point1().x(),l2.point1().y(),
50  l2.point2().x(),l2.point2().y());
51 }
52 
53 //: true if the point lies on the line segment and is between the endpoints
54 // \relatesalso vgl_point_2d
55 // \relatesalso vgl_line_segment_2d
56 template <class T>
58  vgl_line_segment_2d<T> const& lseg);
59 
60 //: return true if the two linesegments meet.
61 // End points are considered to belong to a line segment.
62 // \relatesalso vgl_line_segment_2d
63 template <class T>
65  vgl_line_segment_2d<T> const& l2)
66 {
67  return vgl_lineseg_test_lineseg(l1.point1().x(),l1.point1().y(),
68  l1.point2().x(),l1.point2().y(),
69  l2.point1().x(),l2.point1().y(),
70  l2.point2().x(),l2.point2().y());
71 }
72 
73 #define VGL_LINESEG_TEST_INSTANTIATE(T) extern "please include vgl/vgl_lineseg_test.hxx instead"
74 
75 #endif // vgl_lineseg_test_h_
bool vgl_lineseg_test_line(vgl_line_2d< T > const &l1, vgl_line_segment_2d< T > const &l2)
true if the line meets the linesegment.
a point in 2D nonhomogeneous space
vgl_point_2d< Type > point2() const
The other end-point of the line segment.
bool vgl_lineseg_test_lineseg(vgl_line_segment_2d< T > const &l1, vgl_line_segment_2d< T > const &l2)
return true if the two linesegments meet.
void get_two_points(vgl_point_2d< Type > &p1, vgl_point_2d< Type > &p2) const
Get two points on the line; normally the intersection with X and Y axes.
Definition: vgl_line_2d.hxx:50
Type & y()
Definition: vgl_point_2d.h:72
vgl_point_2d< Type > point1() const
One end-point of the line segment.
bool vgl_lineseg_test_point(vgl_point_2d< T > const &p, vgl_line_segment_2d< T > const &lseg)
true if the point lies on the line segment and is between the endpoints.
Type & x()
Definition: vgl_point_2d.h:71