diff --git a/Distance_3/benchmark/Distance_3/bench_thingi10k_3.cpp b/Distance_3/benchmark/Distance_3/bench_thingi10k_3.cpp index f90637b9564..e7f5c160bf3 100644 --- a/Distance_3/benchmark/Distance_3/bench_thingi10k_3.cpp +++ b/Distance_3/benchmark/Distance_3/bench_thingi10k_3.cpp @@ -164,6 +164,10 @@ int main(int argc, char** argv) } average_length/=(3*input_triangles.size()); + std::cout << "Simple_Cartesian" << std::endl; + Test >().run(filename, average_length*average_length/256); + Test >().run(filename, min_sq_length*4); + // Equivalent to EPECK since there are only predicates // Test().run(filename, 100*max/input_points.size()); // std::cout << "EPICK" << std::endl; diff --git a/Distance_3/include/CGAL/Distance_3/Point_3_Triangle_3.h b/Distance_3/include/CGAL/Distance_3/Point_3_Triangle_3.h index 0f5d86f7a06..eae3f4d7326 100644 --- a/Distance_3/include/CGAL/Distance_3/Point_3_Triangle_3.h +++ b/Distance_3/include/CGAL/Distance_3/Point_3_Triangle_3.h @@ -326,7 +326,7 @@ compare_squared_distance_to_triangle(const typename K::Point_3& pt, // Note that in the degenerate case, at most 2 edges cover the full triangle, // and only two distances could be used typename K::Comparison_result res1 = csq_dist(pt, segment(t2, t0), d2); - if(is_certain(res1) && (res1 == SMALLER)) + if(certainly(res1 == SMALLER)) return SMALLER; typename K::Comparison_result res2 = csq_dist(pt, segment(t1, t2), d2); return smaller_of(res1,res2); @@ -334,7 +334,7 @@ compare_squared_distance_to_triangle(const typename K::Point_3& pt, // Compare first the distance to the plane, if larger we can exit early typename K::Comparison_result res_p_pl = compare(squared_distance_to_plane(normal, vector(t0, pt), k), d2); - if(is_certain(res_p_pl) && res_p_pl==LARGER) + if(certainly(res_p_pl==LARGER)) { inside_or_far_to_the_plane=true; return LARGER; @@ -344,7 +344,7 @@ compare_squared_distance_to_triangle(const typename K::Point_3& pt, if(!on_left_of_triangle_edge(pt, normal, t0, t1, k)) { typename K::Comparison_result res_p_s1 = csq_dist(pt, segment(t0, t1), d2); - if(res_p_s1==SMALLER) + if(certainly(res_p_s1==SMALLER)) return SMALLER; if(!on_left_of_triangle_edge(pt, normal, t1, t2, k)) { @@ -370,7 +370,7 @@ compare_squared_distance_to_triangle(const typename K::Point_3& pt, if(!on_left_of_triangle_edge(pt, normal, t1, t2, k)) { typename K::Comparison_result res_p_s2 = csq_dist(pt, segment(t1, t2), d2); - if(res_p_s2 == SMALLER) + if(certainly(res_p_s2 == SMALLER)) return SMALLER; if(!on_left_of_triangle_edge(pt, normal, t2, t0, k)) { 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 be3d14ba4f2..d35fda6d08b 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 @@ -73,7 +73,7 @@ squared_distance(const typename K::Segment_3& seg, const Point_3& ss = seg.source(); const Point_3& se = seg.target(); - //TODO Me semble vachement compliqué pour un truc si simple, est-ce que y'a pas moyen de s'inspirer de Lumelsky pour segment segment + //TODO This seems complicated compared to Segment_3_Segment_3.h. Consider improving by adapting Lumelsky's method for segment-segment intersection. if(ss == se) return sq_dist(ss, ray); diff --git a/Distance_3/include/CGAL/Distance_3/Segment_3_Segment_3.h b/Distance_3/include/CGAL/Distance_3/Segment_3_Segment_3.h index 4bd63cd397d..58b97d9c890 100644 --- a/Distance_3/include/CGAL/Distance_3/Segment_3_Segment_3.h +++ b/Distance_3/include/CGAL/Distance_3/Segment_3_Segment_3.h @@ -104,7 +104,7 @@ squared_distance(const typename K::Segment_3& s1, CGAL_assertion(a > 0 && d < 0); const FT det = a*d - b*c; - if(det == 0) + if(is_zero(det)) res.x = 0; else res.x = boost::algorithm::clamp((e*d - b*f) / det, 0, 1); @@ -209,7 +209,7 @@ compare_squared_distance(const typename K::Segment_3& s1, /* The content of this function is very similar with the one above, the difference is we can exit earlier if the supporting line are farther than d since we do not need the exact distance. */ - +#if 1 const Point_3& p1 = vertex(s1, 0); const Point_3& q1 = vertex(s1, 1); const Point_3& p2 = vertex(s2, 0); @@ -231,7 +231,7 @@ compare_squared_distance(const typename K::Segment_3& s1, // Compare first the distance between the lines, if larger we can exit early typename K::Comparison_result res_ll=csq_dist(s1.supporting_line(), s2.supporting_line(), d2); - if(is_certain(res_ll) && res_ll==LARGER) + if(certainly(res_ll==LARGER)) return LARGER; // Compute the distance between the segments @@ -247,7 +247,7 @@ compare_squared_distance(const typename K::Segment_3& s1, CGAL_assertion(a > 0 && d < 0); const FT det = a*d - b*c; FT res_x; - if(det == 0) + if(is_zero(det)) res_x = 0; else res_x = boost::algorithm::clamp((e*d - b*f) / det, 0, 1); @@ -280,6 +280,10 @@ compare_squared_distance(const typename K::Segment_3& s1, return res_ll; } } +#else + // Faster with Simple_cartesian, a bit slower with EPICK or EPECK specifically if d2 is small + return compare(squared_distance(s1, s2 ,k), d2); +#endif } } // 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 876e0c955ec..6728b2bca61 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 @@ -237,19 +237,19 @@ compare_squared_distance_disjoint(const typename K::Triangle_3& tr1, for(int j=0; j<3; ++j) { 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) + if(certainly(temp_res_ss==SMALLER)) return SMALLER; res=smaller_of(res, temp_res_ss); } //Compare the distance between vertices and triangles typename K::Comparison_result temp_res_v_pl= csq_dist(vertex(tr1, i), tr2,d2); - if(temp_res_v_pl==SMALLER) + if(certainly(temp_res_v_pl==SMALLER)) return SMALLER; res=smaller_of(res, temp_res_v_pl); temp_res_v_pl= csq_dist(vertex(tr2, i), tr1,d2); - if(temp_res_v_pl==SMALLER) + if(certainly(temp_res_v_pl==SMALLER)) return SMALLER; res=smaller_of(res, temp_res_v_pl); } diff --git a/Distance_3/include/CGAL/Distance_3/internal/squared_distance_utils_3.h b/Distance_3/include/CGAL/Distance_3/internal/squared_distance_utils_3.h index 1c367d7fc8b..7aef6144006 100644 --- a/Distance_3/include/CGAL/Distance_3/internal/squared_distance_utils_3.h +++ b/Distance_3/include/CGAL/Distance_3/internal/squared_distance_utils_3.h @@ -26,14 +26,28 @@ namespace CGAL { namespace internal { -template -K_Comparison_result smaller_of(const K_Comparison_result a, const K_Comparison_result b) +inline +Comparison_result smaller_of(const Comparison_result& a, const Comparison_result& b) { - if((a==SMALLER) || (b==SMALLER)) - return SMALLER; - if((a==EQUAL) || (b==EQUAL)) - return EQUAL; - return LARGER; + return (std::min)(a,b); +} + +inline +Uncertain smaller_of(const Uncertain& a, const Uncertain& b) +{ + return Uncertain((std::min)(a.inf(),b.inf()), (std::min)(a.sup(),b.sup())); +} + +inline +Uncertain smaller_of(const Uncertain& a, const Comparison_result& b) +{ + return smaller_of(a,make_uncertain(b)); +} + +inline +Uncertain smaller_of(const Comparison_result& a, const Uncertain& b) +{ + return smaller_of(make_uncertain(a),b); } template diff --git a/HalfedgeDS/package_info/HalfedgeDS/dependencies b/HalfedgeDS/package_info/HalfedgeDS/dependencies index ffbfcd5b201..08b771effbc 100644 --- a/HalfedgeDS/package_info/HalfedgeDS/dependencies +++ b/HalfedgeDS/package_info/HalfedgeDS/dependencies @@ -1,7 +1,6 @@ Algebraic_foundations BGL Circulator -Distance_3 HalfedgeDS Hash_map Installation