core/vgl/vgl_lineseg_test.h
Go to the documentation of this file.
00001 // This is core/vgl/vgl_lineseg_test.h
00002 #ifndef vgl_lineseg_test_h_
00003 #define vgl_lineseg_test_h_
00004 //:
00005 // \file
00006 // \author fsm
00007 // \verbatim
00008 //  Modifications
00009 //   Nov.2003 - Peter Vanroose - made all functions templated
00010 //   Sep.2005 - Peter Vanroose - bug fix: collinear line segments always "true"
00011 //   Mar.2008 - Ibrahim Eden - bug fix: bool vgl_lineseg_test_line(vgl_line_2d<T> const& l1,vgl_line_segment_2d<T> const& l2)
00012 //   Mar.2009 - Dirk Steckhan - bug fix in vgl_lineseg_test_point (missing sqrt)
00013 // \endverbatim
00014 
00015 #include <vgl/vgl_line_segment_2d.h>
00016 #include <vgl/vgl_line_2d.h>
00017 #include <vgl/vgl_point_2d.h>
00018 #include <vcl_cmath.h> // for std::sqrt()
00019 
00020 // The old signature vgl_lineseg_test() was incorrectly documented. Its
00021 // meaning was the same as the new vgl_lineseg_test_line(). Only you can
00022 // decide which one you want.
00023 
00024 //: true if the line joining [1], [2] meets the linesegment joining [3], [4].
00025 // End points are considered to belong to a line segment.
00026 export template <class T>
00027 bool vgl_lineseg_test_line(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4);
00028 
00029 //: true if the linesegment joining [1], [2] meets the linesegment joining [3], [4].
00030 // End points are considered to belong to a line segment.
00031 export template <class T>
00032 bool vgl_lineseg_test_lineseg(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4);
00033 
00034 //: true if the line meets the linesegment.
00035 // End points are considered to belong to a line segment.
00036 // \relatesalso vgl_line_2d
00037 // \relatesalso vgl_line_segment_2d
00038 template <class T>
00039 inline bool vgl_lineseg_test_line(vgl_line_2d<T> const& l1,
00040                                   vgl_line_segment_2d<T> const& l2)
00041 {
00042   vgl_point_2d<T> l1_p1,l1_p2;
00043   l1.get_two_points(l1_p1,l1_p2);
00044   return vgl_lineseg_test_line(l1_p1.x(),l1_p1.y(),
00045                                l1_p2.x(),l1_p2.y(),
00046                                l2.point1().x(),l2.point1().y(),
00047                                l2.point2().x(),l2.point2().y());
00048 }
00049 
00050 //: true if the point lies on the line segment and is between the endpoints
00051 // \relatesalso vgl_point_2d
00052 // \relatesalso vgl_line_segment_2d
00053 export template <class T>
00054 bool vgl_lineseg_test_point(vgl_point_2d<T> const& p,
00055                             vgl_line_segment_2d<T> const& lseg);
00056 
00057 //: return true if the two linesegments meet.
00058 // End points are considered to belong to a line segment.
00059 // \relatesalso vgl_line_segment_2d
00060 template <class T>
00061 inline bool vgl_lineseg_test_lineseg(vgl_line_segment_2d<T> const& l1,
00062                                      vgl_line_segment_2d<T> const& l2)
00063 {
00064   return vgl_lineseg_test_lineseg(l1.point1().x(),l1.point1().y(),
00065                                   l1.point2().x(),l1.point2().y(),
00066                                   l2.point1().x(),l2.point1().y(),
00067                                   l2.point2().x(),l2.point2().y());
00068 }
00069 
00070 #define VGL_LINESEG_TEST_INSTANTIATE(T) extern "please include vgl/vgl_lineseg_test.txx instead"
00071 
00072 #endif // vgl_lineseg_test_h_