Go to the documentation of this file.00001
00002 #ifndef vgl_lineseg_test_h_
00003 #define vgl_lineseg_test_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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 <vgl/vgl_tolerance.h>
00019 #include <vcl_cmath.h>
00020
00021
00022
00023
00024
00025
00026
00027 export template <class T>
00028 bool vgl_lineseg_test_line(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4);
00029
00030
00031
00032 export template <class T>
00033 bool vgl_lineseg_test_lineseg(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4);
00034
00035
00036
00037
00038
00039 template <class T>
00040 inline bool vgl_lineseg_test_line(vgl_line_2d<T> const& l1,
00041 vgl_line_segment_2d<T> const& l2)
00042 {
00043 vgl_point_2d<T> l1_p1,l1_p2;
00044 l1.get_two_points(l1_p1,l1_p2);
00045 return vgl_lineseg_test_line(l1_p1.x(),l1_p1.y(),
00046 l1_p2.x(),l1_p2.y(),
00047 l2.point1().x(),l2.point1().y(),
00048 l2.point2().x(),l2.point2().y());
00049 }
00050
00051
00052
00053
00054 template <class T>
00055 inline bool vgl_lineseg_test_point(vgl_point_2d<T> const& p,
00056 vgl_line_segment_2d<T> const& lseg)
00057 {
00058 vgl_point_2d<T> p1 = lseg.point1(), p2 = lseg.point2();
00059 T x1 = p1.x(), y1 = p1.y(),
00060 x2 = p2.x(), y2 = p2.y(),
00061 xp = p.x(), yp = p.y();
00062
00063 T d1p = (xp-x1)*(xp-x1) + (yp-y1)*(yp-y1);
00064 T d2p = (xp-x2)*(xp-x2) + (yp-y2)*(yp-y2);
00065 T d12 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
00066 double diff = vcl_sqrt(d1p) + vcl_sqrt(d2p) - vcl_sqrt(d12);
00067
00068 return diff <= vgl_tolerance<double>::position;
00069 }
00070
00071
00072
00073
00074 template <class T>
00075 inline bool vgl_lineseg_test_lineseg(vgl_line_segment_2d<T> const& l1,
00076 vgl_line_segment_2d<T> const& l2)
00077 {
00078 return vgl_lineseg_test_lineseg(l1.point1().x(),l1.point1().y(),
00079 l1.point2().x(),l1.point2().y(),
00080 l2.point1().x(),l2.point1().y(),
00081 l2.point2().x(),l2.point2().y());
00082 }
00083
00084 #define VGL_LINESEG_TEST_INSTANTIATE(T) extern "please include vgl/vgl_lineseg_test.txx instead"
00085
00086 #endif // vgl_lineseg_test_h_