diff --git a/Distance_3/include/CGAL/Distance_3/Ray_3_Line_3.h b/Distance_3/include/CGAL/Distance_3/Ray_3_Line_3.h index d4b51b59cbe..ed431f63128 100644 --- a/Distance_3/include/CGAL/Distance_3/Ray_3_Line_3.h +++ b/Distance_3/include/CGAL/Distance_3/Ray_3_Line_3.h @@ -77,26 +77,28 @@ squared_distance(const typename K::Line_3& line, return squared_distance(ray, line, k); } +template +typename K::Comparison_result +compare_squared_distance(const typename K::Ray_3& ray, + const typename K::Line_3& line, + const K& k, + const typename K::FT& d2) +{ + return compare(squared_distance(ray, line, k), d2); +} + +template +typename K::Comparison_result +compare_squared_distance(const typename K::Line_3& line, + const typename K::Ray_3& ray, + const K& k, + const typename K::FT& d2) +{ + return compare_squared_distance(ray, line, k, d2); +} + } // namespace internal -template -inline -typename K::FT -squared_distance(const Line_3& line, - const Ray_3& ray) -{ - return K().compute_squared_distance_3_object()(line, ray); -} - -template -inline -typename K::FT -squared_distance(const Ray_3& ray, - const Line_3& line) -{ - return K().compute_squared_distance_3_object()(ray, line); -} - } // namespace CGAL #endif // CGAL_DISTANCE_3_RAY_3_LINE_3_H diff --git a/Distance_3/include/CGAL/Distance_3/Ray_3_Plane_3.h b/Distance_3/include/CGAL/Distance_3/Ray_3_Plane_3.h index bdc9a956146..eb2a4810a32 100644 --- a/Distance_3/include/CGAL/Distance_3/Ray_3_Plane_3.h +++ b/Distance_3/include/CGAL/Distance_3/Ray_3_Plane_3.h @@ -72,26 +72,28 @@ squared_distance(const typename K::Plane_3& plane, return squared_distance(ray, plane, k); } +template +typename K::Comparison_result +compare_squared_distance(const typename K::Ray_3& ray, + const typename K::Plane_3& plane, + const K& k, + const typename K::FT& d2) +{ + return compare(squared_distance(ray, plane, k), d2); +} + +template +typename K::Comparison_result +compare_squared_distance(const typename K::Plane_3& plane, + const typename K::Ray_3& ray, + const K& k, + const typename K::FT& d2) +{ + return compare_squared_distance(ray, plane, k, d2); +} + } // namespace internal -template -inline -typename K::FT -squared_distance(const Ray_3& ray, - const Plane_3& plane) -{ - return K().compute_squared_distance_3_object()(ray, plane); -} - -template -inline -typename K::FT -squared_distance(const Plane_3& plane, - const Ray_3& ray) -{ - return K().compute_squared_distance_3_object()(plane, ray); -} - } // namespace CGAL #endif // CGAL_DISTANCE_3_RAY_3_PLANE_3_H diff --git a/Distance_3/include/CGAL/Distance_3/Ray_3_Ray_3.h b/Distance_3/include/CGAL/Distance_3/Ray_3_Ray_3.h index 8ca1eca308c..9367e095e92 100644 --- a/Distance_3/include/CGAL/Distance_3/Ray_3_Ray_3.h +++ b/Distance_3/include/CGAL/Distance_3/Ray_3_Ray_3.h @@ -117,6 +117,16 @@ squared_distance(const typename K::Ray_3& ray1, } } +template +typename K::Comparison_result +compare_squared_distance(const typename K::Ray_3& ray1, + const typename K::Ray_3& ray2, + const K& k, + const typename K::FT& d2) +{ + return compare(squared_distance(ray1, ray2, k), d2); +} + } // namespace internal template @@ -129,15 +139,6 @@ ray_ray_squared_distance_parallel(const Vector_3& ray1dir, return internal::ray_ray_squared_distance_parallel(ray1dir, ray2dir, s1_min_s2, K()); } -template -inline -typename K::FT -squared_distance(const Ray_3& ray1, - const Ray_3& ray2) -{ - return K().compute_squared_distance_3_object()(ray1, ray2); -} - } // namespace CGAL #endif // CGAL_DISTANCE_3_RAY_3_RAY_3_H diff --git a/Distance_3/include/CGAL/Distance_3/Segment_3_Line_3.h b/Distance_3/include/CGAL/Distance_3/Segment_3_Line_3.h index 5781c5ceb74..6fa52ef1f4e 100644 --- a/Distance_3/include/CGAL/Distance_3/Segment_3_Line_3.h +++ b/Distance_3/include/CGAL/Distance_3/Segment_3_Line_3.h @@ -38,6 +38,8 @@ squared_distance(const typename K::Segment_3& seg, typename K::Construct_vector_3 vector = k.construct_vector_3_object(); typename K::Compute_squared_distance_3 sq_dist = k.compute_squared_distance_3_object(); + //Probably writable with less if than currently + const Point_3& linepoint = line.point(); const Point_3& start = seg.source(); const Point_3& end = seg.target(); @@ -60,26 +62,31 @@ squared_distance(const typename K::Segment_3& seg, const RT sdm_ss2l = wdot(perpend2line, start_min_lp, k); const RT sdm_se2l = wdot(perpend2line, end_min_lp, k); - if(sdm_ss2l < RT(0)) { - crossing = (sdm_se2l >= RT(0)); - } else { - if(sdm_se2l <= RT(0)) { - crossing = true; - } else { - crossing = (sdm_ss2l == RT(0)); - } - } + // if(sdm_ss2l < RT(0)) { + // crossing = (sdm_se2l >= RT(0)); + // } else { + // if(sdm_se2l <= RT(0)) { + // crossing = true; + // } else { + // crossing = (sdm_ss2l == RT(0)); + // } + // } + crossing = (sdm_ss2l*sdm_se2l) <= RT(0); - if(crossing) { + // if(crossing) { + // return squared_distance_to_plane(normal, start_min_lp, k); + // } else { + // const RT dm = distance_measure_sub(sdm_ss2l, sdm_se2l, start_min_lp, end_min_lp, k); + // if(dm <= RT(0)) { + // return squared_distance_to_line(linedir, start_min_lp, k); + // } else { + // return squared_distance_to_line(linedir, end_min_lp, k); + // } + // } + if(crossing) return squared_distance_to_plane(normal, start_min_lp, k); - } else { - const RT dm = distance_measure_sub(sdm_ss2l, sdm_se2l, start_min_lp, end_min_lp, k); - if(dm <= RT(0)) { - return squared_distance_to_line(linedir, start_min_lp, k); - } else { - return squared_distance_to_line(linedir, end_min_lp, k); - } - } + else + return min(squared_distance_to_line(linedir, start_min_lp, k), squared_distance_to_line(linedir, end_min_lp, k)); } template @@ -91,25 +98,77 @@ squared_distance(const typename K::Line_3& line, return squared_distance(seg, line, k); } +template +typename K::Comparison_result +compare_squared_distance(const typename K::Segment_3& seg, + const typename K::Line_3& line, + const K& k, + const typename K::FT& d2) +{ + // typedef typename K::RT RT; + // typedef typename K::Point_3 Point_3; + // typedef typename K::Vector_3 Vector_3; + + // typename K::Construct_vector_3 vector = k.construct_vector_3_object(); + // typename K::Compare_squared_distance_3 csq_dist = k.compare_squared_distance_3_object(); + + // const Point_3& linepoint = line.point(); + // const Point_3& start = seg.source(); + // const Point_3& end = seg.target(); + + // if(start == end) + // return csq_dist(start, line, d2); + + // const Vector_3 linedir = line.direction().vector(); + // const Vector_3 segdir = seg.direction().vector(); + // const Vector_3 normal = wcross(segdir, linedir, k); + + // if(is_null(normal, k)) + // return compare(squared_distance_to_line(linedir, vector(linepoint,start), k), d2); + + // bool crossing; + + // const Vector_3 perpend2line = wcross(linedir, normal, k); + // const Vector_3 start_min_lp = vector(linepoint, start); + // const Vector_3 end_min_lp = vector(linepoint, end); + // const RT sdm_ss2l = wdot(perpend2line, start_min_lp, k); + // const RT sdm_se2l = wdot(perpend2line, end_min_lp, k); + + // if(sdm_ss2l < RT(0)) { + // crossing = (sdm_se2l >= RT(0)); + // } else { + // if(sdm_se2l <= RT(0)) { + // crossing = true; + // } else { + // crossing = (sdm_ss2l == RT(0)); + // } + // } + + // if(crossing) { + // return squared_distance_to_plane(normal, start_min_lp, k); + // } else { + // const RT dm = distance_measure_sub(sdm_ss2l, sdm_se2l, start_min_lp, end_min_lp, k); + // if(dm <= RT(0)) { + // return squared_distance_to_line(linedir, start_min_lp, k); + // } else { + // return squared_distance_to_line(linedir, end_min_lp, k); + // } + // } + return compare(squared_distance(seg, line, k), d2); +} + +template +typename K::Comparison_result +compare_squared_distance(const typename K::Line_3& line, + const typename K::Segment_3& seg, + const K& k, + const typename K::FT& d2) +{ + return compare_squared_distance(seg, line, k, d2); +} + } // namespace internal -template -inline -typename K::FT -squared_distance(const Segment_3& seg, - const Line_3& line) -{ - return K().compute_squared_distance_3_object()(seg, line); -} - -template -inline -typename K::FT -squared_distance(const Line_3& line, - const Segment_3& seg) -{ - return K().compute_squared_distance_3_object()(line, seg); -} } // namespace CGAL diff --git a/Distance_3/include/CGAL/Distance_3/Segment_3_Plane_3.h b/Distance_3/include/CGAL/Distance_3/Segment_3_Plane_3.h index 1c8d6799556..4b46049940c 100644 --- a/Distance_3/include/CGAL/Distance_3/Segment_3_Plane_3.h +++ b/Distance_3/include/CGAL/Distance_3/Segment_3_Plane_3.h @@ -37,12 +37,13 @@ squared_distance(const typename K::Segment_3 &seg, typedef typename K::Point_3 Point_3; typename K::Construct_vector_3 vector = k.construct_vector_3_object(); + typename K::Compute_squared_distance_3 sq_dist = k.compute_squared_distance_3_object(); const Point_3& start = seg.start(); const Point_3& end = seg.end(); if (start == end) - return squared_distance(start, plane, k); + return sq_dist(start, plane); const Point_3& planepoint = plane.point(); const Vector_3 start_min_pp = vector(planepoint, start); @@ -83,26 +84,28 @@ squared_distance(const typename K::Plane_3& plane, return squared_distance(seg, plane, k); } +template +typename K::Comparison_result +compare_squared_distance(const typename K::Segment_3 &seg, + const typename K::Plane_3 &plane, + const K& k, + const typename K::FT& d2) +{ + return compare(squared_distance(seg, plane, k), d2); +} + +template +inline typename K::Comparison_result +compare_squared_distance(const typename K::Plane_3& plane, + const typename K::Segment_3& seg, + const K& k, + const typename K::FT& d2) +{ + return compare_squared_distance(seg, plane, k, d2); +} + } // namespace internal -template -inline -typename K::FT -squared_distance(const Segment_3& seg, - const Plane_3& plane) -{ - return K().compute_squared_distance_3_object()(seg, plane); -} - -template -inline -typename K::FT -squared_distance(const Plane_3& plane, - const Segment_3& seg) -{ - return K().compute_squared_distance_3_object()(plane, seg); -} - } // namespace CGAL #endif // CGAL_DISTANCE_3_SEGMENT_3_PLANE_3_H diff --git a/Distance_3/include/CGAL/Distance_3/Segment_3_Ray_3.h b/Distance_3/include/CGAL/Distance_3/Segment_3_Ray_3.h index f787fc11056..be3d14ba4f2 100644 --- a/Distance_3/include/CGAL/Distance_3/Segment_3_Ray_3.h +++ b/Distance_3/include/CGAL/Distance_3/Segment_3_Ray_3.h @@ -168,6 +168,16 @@ squared_distance(const typename K::Ray_3& ray, return squared_distance(seg, ray, k); } +template +typename K::Comparison_result +compare_squared_distance(const typename K::Ray_3& ray, + const typename K::Segment_3& seg, + const K& k, + const typename K::FT& d2) +{ + return compare(squared_distance(ray, seg, k), d2); +} + template typename K::Comparison_result compare_squared_distance(const typename K::Segment_3& seg, @@ -175,99 +185,7 @@ compare_squared_distance(const typename K::Segment_3& seg, const K& k, const typename K::FT& d2) { - typedef typename K::RT RT; - typedef typename K::FT FT; - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - - typename K::Construct_vector_3 vector = k.construct_vector_3_object(); - typename K::Compute_squared_distance_3 sq_dist = k.compute_squared_distance_3_object(); - - const Point_3& ss = seg.source(); - const Point_3& se = seg.target(); - - if(ss == se) - return sq_dist(ss, ray); - - const Vector_3 raydir = ray.direction().vector(); - const Vector_3 segdir = seg.direction().vector(); - const Vector_3 normal = wcross(segdir, raydir, k); - - if(is_null(normal, k)) - return squared_distance_parallel(seg, ray, k); - - bool crossing1, crossing2; - - const Vector_3 perpend2seg = wcross(segdir, normal, k); - const Vector_3 perpend2ray = wcross(raydir, normal, k); - const Vector_3 ss_min_rs = vector(ray.source(), ss); - const Vector_3 se_min_rs = vector(ray.source(), se); - const RT sdm_ss2r = wdot(perpend2ray, ss_min_rs, k); - const RT sdm_se2r = wdot(perpend2ray, se_min_rs, k); - - if(sdm_ss2r < RT(0)) - { - crossing1 = (sdm_se2r >= RT(0)); - } - else - { - if(sdm_se2r <= RT(0)) - crossing1 = true; - else - crossing1 = (sdm_ss2r == RT(0)); - } - - const RT sdm_rs2s = - wdot(perpend2seg, ss_min_rs, k); - const RT sdm_re2s = wdot(perpend2seg, raydir, k); - if(sdm_rs2s < RT(0)) - { - crossing2 = (sdm_re2s >= RT(0)); - } else - { - if(sdm_re2s <= RT(0)) - crossing2 = true; - else - crossing2 = (sdm_rs2s == RT(0)); - } - - if(crossing1) - { - if(crossing2) - return squared_distance_to_plane(normal, ss_min_rs, k); - - return sq_dist(ray.source(), seg); - } - else - { - if(crossing2) - { - const RT dm = distance_measure_sub(sdm_ss2r, sdm_se2r, ss_min_rs, se_min_rs, k); - if(dm < RT(0)) - { - return sq_dist(ss, ray); - } - else - { - if(dm > RT(0)) - return sq_dist(se, ray); - else - // parallel, should not happen (no crossing) - return squared_distance_parallel(seg, ray, k); - } - } - else - { - const RT dm = distance_measure_sub(sdm_ss2r, sdm_se2r, ss_min_rs, se_min_rs, k); - if(dm == RT(0)) - return squared_distance_parallel(seg, ray, k); - - const FT min1 = (dm < RT(0)) ? sq_dist(ss, ray) - : sq_dist(se, ray); - const FT min2 = sq_dist(ray.source(), seg); - - return (min1 < min2) ? min1 : min2; - } - } + return compare_squared_distance(ray, seg, k, d2); } } // namespace internal diff --git a/Distance_3/include/CGAL/Distance_3/Triangle_3_Triangle_3.h b/Distance_3/include/CGAL/Distance_3/Triangle_3_Triangle_3.h index 13ab22eba3c..64e115b13a8 100644 --- a/Distance_3/include/CGAL/Distance_3/Triangle_3_Triangle_3.h +++ b/Distance_3/include/CGAL/Distance_3/Triangle_3_Triangle_3.h @@ -215,13 +215,13 @@ squared_distance(const typename K::Triangle_3& tr1, template typename K::Comparison_result -compare_squared_distance(const typename K::Triangle_3& tr1, - const typename K::Triangle_3& tr2, - const K& k, - const typename K::FT& d2, - bool are_triangles_known_to_be_disjoint) +compare_squared_distance_disjoint(const typename K::Triangle_3& tr1, + const typename K::Triangle_3& tr2, + const K& k, + const typename K::FT& d2) { typedef typename K::FT FT; + typedef typename K::Segment_3 Segment_3; typename K::Construct_vertex_3 vertex = k.construct_vertex_3_object(); typename K::Compare_squared_distance_3 csq_dist = k.compare_squared_distance_3_object(); @@ -235,23 +235,32 @@ compare_squared_distance(const typename K::Triangle_3& tr1, typename K::Comparison_result temp_res_ss=csq_dist(Segment_3(vertex(tr1, i%3), vertex(tr1, (i+1)%3)),Segment_3(vertex(tr2, j%3), vertex(tr2, (j+1)%3)),d2); if(temp_res_ss==SMALLER) return SMALLER; - smaller_of(res, temp_res_ss); + res=smaller_of(res, temp_res_ss); } - typename K::comparison_result temp_res_v_pl= csq_dist(vertex(tr1, i), tr2,d2); + typename K::Comparison_result temp_res_v_pl= csq_dist(vertex(tr1, i), tr2,d2); if(temp_res_v_pl==SMALLER) - return SMALLER; - smaller_of(res, temp_res_v_pl); + return SMALLER; + res=smaller_of(res, temp_res_v_pl); } - - if(!are_triangles_known_to_be_disjoint){ - //TODO check are disjoint - } return res; } +template +typename K::Comparison_result +compare_squared_distance(const typename K::Triangle_3& tr1, + const typename K::Triangle_3& tr2, + const K& k, + const typename K::FT& d2){ + if(tr1.is_degenerate() || tr2.is_degenerate()) + return compare(squared_distance(tr1,tr2, k), d2); + if(do_intersect(tr1, tr2)) + return compare(typename K::FT(0), d2); + return compare_squared_distance_disjoint(tr1, tr2, k, d2); +} + } // namespace internal } // namespace CGAL diff --git a/Distance_3/include/CGAL/global_functions_distance_3.h b/Distance_3/include/CGAL/global_functions_distance_3.h index 68c975be0ea..b4868ddc930 100644 --- a/Distance_3/include/CGAL/global_functions_distance_3.h +++ b/Distance_3/include/CGAL/global_functions_distance_3.h @@ -94,10 +94,21 @@ CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Point_3, Plane_3) CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Point_3, Triangle_3) CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Point_3, Tetrahedron_3) -CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Segment_3, Ray_3) - CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Line_3, Plane_3) +//Not yet modify + +CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Segment_3, Line_3) +CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Segment_3, Ray_3) +CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Segment_3, Plane_3) +// CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Segment_3, Triangle_3) + +CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Ray_3, Line_3) +CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Ray_3, Plane_3) +CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(Ray_3) + + + } //namespace CGAL #endif // CGAL_KERNEL_GLOBAL_FUNCTIONS_DISTANCE_3_H \ No newline at end of file diff --git a/Distance_3/test/Distance_3/test_compare_distance_3.cpp b/Distance_3/test/Distance_3/test_compare_distance_3.cpp index 12f7909a26a..79c995e7497 100644 --- a/Distance_3/test/Distance_3/test_compare_distance_3.cpp +++ b/Distance_3/test/Distance_3/test_compare_distance_3.cpp @@ -148,18 +148,9 @@ private: // std::cout << std::endl << "Test" << std::endl; // std::cout << o1 << std::endl << o2 << std::endl; - // std::cout << CGAL::squared_distance(o1, o2) << std::endl; - // std::cout << CGAL::squared_distance( CGAL::Cartesian_converter()(o1) , - // CGAL::Cartesian_converter()(o2)) << std::endl; - - // if constexpr(std::is_same()){ - // if(expected_result != 0){ - // std::cout << CGAL::squared_distance(o1.supporting_line(), o2.supporting_line()) << std::endl; - // std::cout << CGAL::squared_distance( CGAL::Cartesian_converter()(o1.supporting_line()) , - // CGAL::Cartesian_converter()(o2.supporting_line())) << std::endl; - // } - // } + // std::cout << CGAL::squared_distance(o1, o2) << " " << expected_result << std::endl; // std::cout << CGAL::SMALLER << CGAL::EQUAL << CGAL::LARGER << std::endl; + // std::cout << CGAL::compare_squared_distance(o1, o2, expected_result) << std::endl; const bool res_e_o1o2 = (CGAL::compare_squared_distance(o1, o2, expected_result) == CGAL::EQUAL); const bool res_e_o2o1 = (CGAL::compare_squared_distance(o2, o1, expected_result) == CGAL::EQUAL); @@ -497,31 +488,31 @@ private: check_compare_squared_distance_with_bound(p( -8, -7, 0), R{p(23, -27, 2), p( -17, 16, 2)}, 86.368512613); } -// void R_R() -// { -// // Note : the values are not verified by hand -// std::cout << "Ray - Ray" << std::endl; -// check_compare_squared_distance_with_bound(R{p( 0, 0, 30), p( 0, 30, 30)}, R{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002); -// check_compare_squared_distance(R{p( 1, 0, 0), p( 0, 0, 0)}, R{p( 1, 3, 3), p( 0, 0, 3)}, 9); -// check_compare_squared_distance(R{p( 0, 0, 0), p( 1, 0, 0)}, R{p( 0, 0, 2), p( -1, 0, 2)}, 4); -// } + void R_R() + { + // Note : the values are not verified by hand + std::cout << "Ray - Ray" << std::endl; + check_compare_squared_distance_with_bound(R{p( 0, 0, 30), p( 0, 30, 30)}, R{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002); + check_compare_squared_distance(R{p( 1, 0, 0), p( 0, 0, 0)}, R{p( 1, 3, 3), p( 0, 0, 3)}, 9); + check_compare_squared_distance(R{p( 0, 0, 0), p( 1, 0, 0)}, R{p( 0, 0, 2), p( -1, 0, 2)}, 4); + } -// void S_R() -// { -// // Note : the values are not verified by hand -// std::cout << "Segment - Ray" << std::endl; -// check_compare_squared_distance_with_bound(S{p( 0, 0, 30), p( 0, 30, 30)}, R{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002); -// } + void S_R() + { + // Note : the values are not verified by hand + std::cout << "Segment - Ray" << std::endl; + check_compare_squared_distance_with_bound(S{p( 0, 0, 30), p( 0, 30, 30)}, R{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002); + } -// void R_L() -// { -// // Note : the values are not verified by hand -// std::cout << "Ray - Line" << std::endl; -// check_compare_squared_distance_with_bound(R{p( 0, 0, 30), p( 0, 30, 30)}, L{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002); -// check_compare_squared_distance(R{p(10, 0, 0), p( 20, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 109); -// check_compare_squared_distance(R{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9); -// check_compare_squared_distance(R{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4); -// } + void R_L() + { + // Note : the values are not verified by hand + std::cout << "Ray - Line" << std::endl; + check_compare_squared_distance_with_bound(R{p( 0, 0, 30), p( 0, 30, 30)}, L{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002); + check_compare_squared_distance(R{p(10, 0, 0), p( 20, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 109); + check_compare_squared_distance(R{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9); + check_compare_squared_distance(R{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4); + } void P_L() { @@ -530,14 +521,14 @@ private: check_compare_squared_distance(p( 0, 0, 2), L{p( 0, 0, 0), p( 1, 2, 0)}, 4); } -// void S_L() -// { -// // Note : the values are not verified by hand -// std::cout << "Segment - Line" << std::endl; -// check_compare_squared_distance(S{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9); -// check_compare_squared_distance(S{p(-90, 0, 0), p(-10, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 109); -// check_compare_squared_distance(S{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4); -// } + void S_L() + { + // Note : the values are not verified by hand + std::cout << "Segment - Line" << std::endl; + check_compare_squared_distance(S{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9); + check_compare_squared_distance(S{p(-90, 0, 0), p(-10, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 109); + check_compare_squared_distance(S{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4); + } void L_L() { @@ -554,19 +545,19 @@ private: check_compare_squared_distance(p(2, 5, 3), Pl(0, 1, 0, 0), 25); } -// void S_Pl() -// { -// std::cout << "Segment - Plane" << std::endl; -// check_compare_squared_distance(S{p(2, -3, 3), p( 3,-7, 4)}, pl(0, 1, 0, 0), 9); -// } + void S_Pl() + { + std::cout << "Segment - Plane" << std::endl; + check_compare_squared_distance(S{p(2, -3, 3), p( 3,-7, 4)}, pl(0, 1, 0, 0), 9); + } -// void R_Pl() -// { -// std::cout << "Ray - Plane" << std::endl; -// check_compare_squared_distance(R{p(2, -4, 3), p( 3,-4, 4)}, Pl(0, 1, 0, 0), 16); -// check_compare_squared_distance(R{p(2, -4, 3), p( 3, 4, 4)}, Pl(0, 1, 0, 0), 0); -// check_compare_squared_distance(R{p(2, -4, 3), p( 3,-8, 4)}, Pl(0, 1, 0, 0), 16); -// } + void R_Pl() + { + std::cout << "Ray - Plane" << std::endl; + check_compare_squared_distance(R{p(2, -4, 3), p( 3,-4, 4)}, Pl(0, 1, 0, 0), 16); + check_compare_squared_distance(R{p(2, -4, 3), p( 3, 4, 4)}, Pl(0, 1, 0, 0), 0); + check_compare_squared_distance(R{p(2, -4, 3), p( 3,-8, 4)}, Pl(0, 1, 0, 0), 16); + } void L_Pl() { @@ -587,151 +578,153 @@ private: check_compare_squared_distance(Pl(-2, 1, 1, 0), Pl(2, 1, 3, 0), 0); } -// void T_T() -// { -// std::cout << "Triangle - Triangle" << std::endl; + void T_T() + { + std::cout << "Triangle - Triangle" << std::endl; -// // min between vertices (hardcoded) -// check_compare_squared_distance(T{p(0,0,0), p(1,0,0), p(0,1,0)}, T{p(0,0,2), p(-1,0,2), p(0,-1,2)}, 4); -// check_compare_squared_distance(T{p(0,0,0), p(1,0,0), p(0,1,0)}, T{p(-1,0,2), p(0,0,2), p(0,-1,2)}, 4); + // min between vertices (hardcoded) + check_compare_squared_distance(T{p(0,0,0), p(1,0,0), p(0,1,0)}, T{p(0,0,2), p(-1,0,2), p(0,-1,2)}, 4); + check_compare_squared_distance(T{p(0,0,0), p(1,0,0), p(0,1,0)}, T{p(-1,0,2), p(0,0,2), p(0,-1,2)}, 4); -// check_compare_squared_distance(T{p(1,2,3), P{FT(4.2),FT(5.3),-6}, p(7,-8,9)}, -// T{P{FT(10.1), 12, -10}, p(15, 14, -12), p(19, 45, -20)}, -// CGAL::squared_distance(P{FT(4.2),FT(5.3),-6}, P{FT(10.1), 12, -10})); + check_compare_squared_distance(T{p(1,2,3), P{FT(4.2),FT(5.3),-6}, p(7,-8,9)}, + T{P{FT(10.1), 12, -10}, p(15, 14, -12), p(19, 45, -20)}, + CGAL::squared_distance(P{FT(4.2),FT(5.3),-6}, P{FT(10.1), 12, -10})); -// // min vertex-edge (hardcoded) -// check_compare_squared_distance(T{p(0,0,0), p(1,0,0), p(0,1,0)}, T{p(1,1,0), p(2,1,0), p(1,2,0)}, 0.5); -// check_compare_squared_distance(T{p(0,0,0), p(2,0,0), p(0,2,0)}, T{p(0,-1,1), p(2,0,1), p(2,-1,1)}, 1); + // min vertex-edge (hardcoded) + check_compare_squared_distance(T{p(0,0,0), p(1,0,0), p(0,1,0)}, T{p(1,1,0), p(2,1,0), p(1,2,0)}, 0.5); + check_compare_squared_distance(T{p(0,0,0), p(2,0,0), p(0,2,0)}, T{p(0,-1,1), p(2,0,1), p(2,-1,1)}, 1); -// for(int i=0; i, gte::Triangle3 > GTE_TT_checker; -// gte::Triangle3 gte_tr1{{p0.x(), p0.y(), p0.z()}, {p1.x(), p1.y(), p1.z()}, {p2.x(), p2.y(), p2.z()}}; -// gte::Triangle3 gte_tr2{{p3.x(), p3.y(), p3.z()}, {p4.x(), p4.y(), p4.z()}, {p5.x(), p5.y(), p5.z()}}; -// auto gte_res = GTE_TT_checker(gte_tr1, gte_tr2); + // generic triangles + T tr1{p0, p1, p2}, tr2{p3, p4, p5}; + do_intersect_check(tr1, tr2); -// std::cout << "dist (CGAL) : " << CGAL::squared_distance(tr1, tr2) << std::endl; -// std::cout << "dist (GTE) : " << gte_res.sqrDistance << std::endl; -// std::cout << "diff CGAL GTE : " << (gte_res.sqrDistance - CGAL::squared_distance(tr1, tr2)) << std::endl; +#ifdef CGAL_USE_GTE_AS_SANITY_CHECK + gte::DCPQuery, gte::Triangle3 > GTE_TT_checker; + gte::Triangle3 gte_tr1{{p0.x(), p0.y(), p0.z()}, {p1.x(), p1.y(), p1.z()}, {p2.x(), p2.y(), p2.z()}}; + gte::Triangle3 gte_tr2{{p3.x(), p3.y(), p3.z()}, {p4.x(), p4.y(), p4.z()}, {p5.x(), p5.y(), p5.z()}}; + auto gte_res = GTE_TT_checker(gte_tr1, gte_tr2); -// // don't assert on purpose, GTE has slightly (10^-30 different results, even with an exact NT) -// are_equal(CGAL::squared_distance(tr1, tr2), gte_res.sqrDistance); -// #endif -// } -// } + std::cout << "dist (CGAL) : " << CGAL::squared_distance(tr1, tr2) << std::endl; + std::cout << "dist (GTE) : " << gte_res.sqrDistance << std::endl; + std::cout << "diff CGAL GTE : " << (gte_res.sqrDistance - CGAL::squared_distance(tr1, tr2)) << std::endl; + + // don't assert on purpose, GTE has slightly (10^-30 different results, even with an exact NT) + are_equal(CGAL::squared_distance(tr1, tr2), gte_res.sqrDistance); +#endif + } + } public: void run() @@ -747,18 +740,18 @@ public: P_Tet(); S_S(); - // S_R(); - // S_L(); - // S_Pl(); + S_R(); + S_L(); + S_Pl(); - // R_R(); - // R_L(); - // R_Pl(); + R_R(); + R_L(); + R_Pl(); L_L(); L_Pl(); - // T_T(); + T_T(); Pl_Pl(); }