First bench

This commit is contained in:
Léo Valque 2025-02-26 18:44:08 +01:00
parent dce9e4fde7
commit bf4e61e4e5
9 changed files with 387 additions and 389 deletions

View File

@ -77,26 +77,28 @@ squared_distance(const typename K::Line_3& line,
return squared_distance(ray, line, k);
}
template <class K>
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 <class K>
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 <class K>
inline
typename K::FT
squared_distance(const Line_3<K>& line,
const Ray_3<K>& ray)
{
return K().compute_squared_distance_3_object()(line, ray);
}
template <class K>
inline
typename K::FT
squared_distance(const Ray_3<K>& ray,
const Line_3<K>& line)
{
return K().compute_squared_distance_3_object()(ray, line);
}
} // namespace CGAL
#endif // CGAL_DISTANCE_3_RAY_3_LINE_3_H

View File

@ -72,26 +72,28 @@ squared_distance(const typename K::Plane_3& plane,
return squared_distance(ray, plane, k);
}
template <class K>
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 <class K>
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 <class K>
inline
typename K::FT
squared_distance(const Ray_3<K>& ray,
const Plane_3<K>& plane)
{
return K().compute_squared_distance_3_object()(ray, plane);
}
template <class K>
inline
typename K::FT
squared_distance(const Plane_3<K>& plane,
const Ray_3<K>& ray)
{
return K().compute_squared_distance_3_object()(plane, ray);
}
} // namespace CGAL
#endif // CGAL_DISTANCE_3_RAY_3_PLANE_3_H

View File

@ -117,6 +117,16 @@ squared_distance(const typename K::Ray_3& ray1,
}
}
template <class K>
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 <class K>
@ -129,15 +139,6 @@ ray_ray_squared_distance_parallel(const Vector_3<K>& ray1dir,
return internal::ray_ray_squared_distance_parallel(ray1dir, ray2dir, s1_min_s2, K());
}
template <class K>
inline
typename K::FT
squared_distance(const Ray_3<K>& ray1,
const Ray_3<K>& ray2)
{
return K().compute_squared_distance_3_object()(ray1, ray2);
}
} // namespace CGAL
#endif // CGAL_DISTANCE_3_RAY_3_RAY_3_H

View File

@ -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 <class K>
@ -91,25 +98,77 @@ squared_distance(const typename K::Line_3& line,
return squared_distance(seg, line, k);
}
template <class K>
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 <class K>
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 <class K>
inline
typename K::FT
squared_distance(const Segment_3<K>& seg,
const Line_3<K>& line)
{
return K().compute_squared_distance_3_object()(seg, line);
}
template <class K>
inline
typename K::FT
squared_distance(const Line_3<K>& line,
const Segment_3<K>& seg)
{
return K().compute_squared_distance_3_object()(line, seg);
}
} // namespace CGAL

View File

@ -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 <class K>
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 <class K>
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 <class K>
inline
typename K::FT
squared_distance(const Segment_3<K>& seg,
const Plane_3<K>& plane)
{
return K().compute_squared_distance_3_object()(seg, plane);
}
template <class K>
inline
typename K::FT
squared_distance(const Plane_3<K>& plane,
const Segment_3<K>& seg)
{
return K().compute_squared_distance_3_object()(plane, seg);
}
} // namespace CGAL
#endif // CGAL_DISTANCE_3_SEGMENT_3_PLANE_3_H

View File

@ -168,6 +168,16 @@ squared_distance(const typename K::Ray_3& ray,
return squared_distance(seg, ray, k);
}
template <class K>
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 <class K>
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

View File

@ -215,13 +215,13 @@ squared_distance(const typename K::Triangle_3& tr1,
template <typename K>
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>
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

View File

@ -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

View File

@ -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<K,CGAL::Exact_predicates_exact_constructions_kernel>()(o1) ,
// CGAL::Cartesian_converter<K,CGAL::Exact_predicates_exact_constructions_kernel>()(o2)) << std::endl;
// if constexpr(std::is_same<O1, S>()){
// 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<K,CGAL::Exact_predicates_exact_constructions_kernel>()(o1.supporting_line()) ,
// CGAL::Cartesian_converter<K,CGAL::Exact_predicates_exact_constructions_kernel>()(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<N; ++i)
// {
// P p0 = random_point();
// P p1 = random_point();
// P p2 = random_point();
// P p3 = random_point();
// P p4 = random_point();
// P p5 = random_point();
std::cout << "Test" << std::endl;
// // these are still exact with EPECK
// p0 = CGAL::midpoint(p0, p1);
// p1 = p0 + FT(0.1) * V{p1 - p0};
// p2 = p2 + V{p2 - p0} / FT(CGAL_PI);
for(int i=0; i<N; ++i)
{
P p0 = random_point();
P p1 = random_point();
P p2 = random_point();
P p3 = random_point();
P p4 = random_point();
P p5 = random_point();
// // this is still exact with EPECK_with_sqrt
// p4 = p4 + V{p4 - CGAL::ORIGIN} / CGAL::approximate_sqrt(CGAL::square(p4.x()) + CGAL::square(p4.y()) + CGAL::square(p4.z()) + 3);
// these are still exact with EPECK
p0 = CGAL::midpoint(p0, p1);
p1 = p0 + FT(0.1) * V{p1 - p0};
p2 = p2 + V{p2 - p0} / FT(CGAL_PI);
// p5 = p5 + V{p5 - CGAL::ORIGIN} * FT(std::cos(1.3));
// this is still exact with EPECK_with_sqrt
p4 = p4 + V{p4 - CGAL::ORIGIN} / CGAL::approximate_sqrt(CGAL::square(p4.x()) + CGAL::square(p4.y()) + CGAL::square(p4.z()) + 3);
// // degenerate inputs
// check_compare_squared_distance(T{p3, p3, p3}, T{p3, p3, p3}, 0); // both degen
// check_compare_squared_distance(T{p0, p0, p0}, T{p3, p3, p3}, CGAL::squared_distance(p0, p3)); // both degen
p5 = p5 + V{p5 - CGAL::ORIGIN} * FT(std::cos(1.3));
// check_compare_squared_distance(T{p0, p0, p0}, T{p0, p0, p3}, 0); // single degen and common edge
// check_compare_squared_distance(T{p0, p0, p0}, T{p3, p0, p0}, 0);
// check_compare_squared_distance(T{p0, p0, p0}, T{p0, p3, p0}, 0);
// degenerate inputs
check_compare_squared_distance(T{p3, p3, p3}, T{p3, p3, p3}, 0); // both degen
check_compare_squared_distance(T{p0, p0, p0}, T{p3, p3, p3}, CGAL::squared_distance(p0, p3)); // both degen
// check_compare_squared_distance(T{p0, p0, p0}, T{p0, p3, p4}, 0); // single degen and common vertex
// check_compare_squared_distance(T{p0, p0, p0}, T{p3, p0, p4}, 0);
// check_compare_squared_distance(T{p0, p0, p0}, T{p3, p4, p0}, 0);
check_compare_squared_distance(T{p0, p0, p0}, T{p0, p0, p3}, 0); // single degen and common edge
check_compare_squared_distance(T{p0, p0, p0}, T{p3, p0, p0}, 0);
check_compare_squared_distance(T{p0, p0, p0}, T{p0, p3, p0}, 0);
// // degen into point & degen into segment
// check_compare_squared_distance(T{p1, p1, p1}, T{p4, p3, p3}, CGAL::squared_distance(p1, S{p3, p4}));
// check_compare_squared_distance(T{p5, p5, p5}, T{p3, p3, p4}, CGAL::squared_distance(p5, S{p3, p4}));
check_compare_squared_distance(T{p0, p0, p0}, T{p0, p3, p4}, 0); // single degen and common vertex
check_compare_squared_distance(T{p0, p0, p0}, T{p3, p0, p4}, 0);
check_compare_squared_distance(T{p0, p0, p0}, T{p3, p4, p0}, 0);
// // both degen into segment
// check_compare_squared_distance(T{p0, p1, p0}, T{p3, p3, p4}, CGAL::squared_distance(S{p0, p1}, S{p3, p4}));
// check_compare_squared_distance(T{p5, p5, p4}, T{p4, p3, p3}, CGAL::squared_distance(S{p5, p4}, S{p3, p4}));
// degen into point & degen into segment
check_compare_squared_distance(T{p1, p1, p1}, T{p4, p3, p3}, CGAL::squared_distance(p1, S{p3, p4}));
check_compare_squared_distance(T{p5, p5, p5}, T{p3, p3, p4}, CGAL::squared_distance(p5, S{p3, p4}));
// // common vertex
// check_compare_squared_distance(T{p0, p1, p2}, T{p0, p3, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p3, p0, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p0}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p1, p3, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p3, p1, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p1}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p2, p3, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p3, p2, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p2}, 0);
// both degen into segment
check_compare_squared_distance(T{p0, p1, p0}, T{p3, p3, p4}, CGAL::squared_distance(S{p0, p1}, S{p3, p4}));
check_compare_squared_distance(T{p5, p5, p4}, T{p4, p3, p3}, CGAL::squared_distance(S{p5, p4}, S{p3, p4}));
// // common edge
// check_compare_squared_distance(T{p0, p1, p2}, T{p0, p1, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p1, p0, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p0, p1}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p1, p0}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p0, p4, p1}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0);
// common vertex
check_compare_squared_distance(T{p0, p1, p2}, T{p0, p3, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p3, p0, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p0}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p1, p3, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p3, p1, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p1}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p2, p3, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p3, p2, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p2, p1, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p1, p2, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p2, p1}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p1, p2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p2, p4, p1}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0);
// common edge
check_compare_squared_distance(T{p0, p1, p2}, T{p0, p1, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p1, p0, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p0, p1}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p1, p0}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p0, p4, p1}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p0, p2, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p2, p0, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p0, p2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, p2, p0}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p0, p4, p2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p2, p4, p0}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p2, p1, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p1, p2, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p2, p1}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p1, p2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p2, p4, p1}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0);
// // same triangle
// check_compare_squared_distance(T{p0, p1, p2}, T{p0, p1, p2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p1, p2, p0}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p2, p0, p1}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p2, p1, p0}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p0, p2, p1}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p1, p0, p2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p0, p2, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p2, p0, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p0, p2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, p2, p0}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p0, p4, p2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p2, p4, p0}, 0);
// // vertex on triangle
// double lambda = r.get_double(0, 1);
// double mu = r.get_double(0, 1 - lambda);
// const P bp = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp, p3, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p3, bp, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p3, p4, bp}, 0);
// same triangle
check_compare_squared_distance(T{p0, p1, p2}, T{p0, p1, p2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p1, p2, p0}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p2, p0, p1}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p2, p1, p0}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p0, p2, p1}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p1, p0, p2}, 0);
// // edge on triangle
// lambda = r.get_double(0, 1);
// mu = r.get_double(0, 1 - lambda);
// P bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0);
// vertex on triangle
double lambda = r.get_double(0, 1);
double mu = r.get_double(0, 1 - lambda);
const P bp = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
check_compare_squared_distance(T{p0, p1, p2}, T{bp, p3, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p3, bp, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p3, p4, bp}, 0);
// // part of the edge crossing the triangle
// lambda = r.get_double(-1, 1);
// mu = r.get_double(-1, 1);
// bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0);
// check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0);
// edge on triangle
lambda = r.get_double(0, 1);
mu = r.get_double(0, 1 - lambda);
P bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
check_compare_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0);
// // generic triangles
// T tr1{p0, p1, p2}, tr2{p3, p4, p5};
// do_intersect_check(tr1, tr2);
// part of the edge crossing the triangle
lambda = r.get_double(-1, 1);
mu = r.get_double(-1, 1);
bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
check_compare_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0);
check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0);
// #ifdef CGAL_USE_GTE_AS_SANITY_CHECK
// gte::DCPQuery<FT, gte::Triangle3<FT>, gte::Triangle3<FT> > GTE_TT_checker;
// gte::Triangle3<FT> gte_tr1{{p0.x(), p0.y(), p0.z()}, {p1.x(), p1.y(), p1.z()}, {p2.x(), p2.y(), p2.z()}};
// gte::Triangle3<FT> 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<FT, gte::Triangle3<FT>, gte::Triangle3<FT> > GTE_TT_checker;
gte::Triangle3<FT> gte_tr1{{p0.x(), p0.y(), p0.z()}, {p1.x(), p1.y(), p1.z()}, {p2.x(), p2.y(), p2.z()}};
gte::Triangle3<FT> 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();
}