macro for global_function_distance

This commit is contained in:
Léo Valque 2025-02-19 19:26:09 +01:00
parent 8bdc4b4f5d
commit 0436efa118
15 changed files with 584 additions and 671 deletions

View File

@ -57,26 +57,6 @@ compare_squared_distance(const typename K::Line_3& line1,
} // namespace internal } // namespace internal
template <class K>
inline
typename K::FT
squared_distance(const Line_3<K>& line1,
const Line_3<K>& line2)
{
return K().compute_squared_distance_3_object()(line1, line2);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Line_3<K>& line1,
const Line_3<K>& line2,
const typename K::FT& d2)
{
return K().compare_squared_distance_3_object()(line1,line2,d2);
}
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_LINE_3_LINE_3_H #endif // CGAL_DISTANCE_3_LINE_3_LINE_3_H

View File

@ -61,26 +61,28 @@ squared_distance(const typename K::Plane_3& pl,
return squared_distance(l, pl, k); return squared_distance(l, pl, k);
} }
template <class K>
inline typename K::Comparison_result
compare_squared_distance(const typename K::Line_3& l,
const typename K::Plane_3& pl,
const K& k,
const typename K::FT& d2)
{
return compare(squared_distance(l, pl, k), d2);
}
template <class K>
inline typename K::Comparison_result
compare_squared_distance(const typename K::Plane_3& pl,
const typename K::Line_3& l,
const K& k,
const typename K::FT& d2)
{
return compare_squared_distance(l, pl, k, d2);
}
} // namespace internal } // namespace internal
template <class K>
inline
typename K::FT
squared_distance(const Line_3<K>& line,
const Plane_3<K>& plane)
{
return K().compute_squared_distance_3_object()(line, plane);
}
template <class K>
inline
typename K::FT
squared_distance(const Plane_3<K>& plane,
const Line_3<K>& line)
{
return K().compute_squared_distance_3_object()(plane, line);
}
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_LINE_3_PLANE_3_H #endif // CGAL_DISTANCE_3_LINE_3_PLANE_3_H

View File

@ -39,17 +39,18 @@ squared_distance(const typename K::Plane_3& plane1,
return sq_dist(plane1.point(), plane2); return sq_dist(plane1.point(), plane2);
} }
} // namespace internal
template <class K> template <class K>
inline inline typename K::Comparison_result
typename K::FT compare_squared_distance(const typename K::Plane_3& plane1,
squared_distance(const Plane_3<K>& plane1, const typename K::Plane_3& plane2,
const Plane_3<K>& plane2) const K& k,
const typename K::FT& d2)
{ {
return K().compute_squared_distance_3_object()(plane1, plane2); return compare(squared_distance(plane1,plane2,k), d2);
} }
} // namespace internal
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_PLANE_3_PLANE_3_H #endif // CGAL_DISTANCE_3_PLANE_3_PLANE_3_H

View File

@ -85,49 +85,11 @@ compare_squared_distance(const typename K::Line_3& line,
const K& k, const K& k,
const typename K::FT& d2) const typename K::FT& d2)
{ {
return compare(squared_distance(pt, line, k), d2); return compare_squared_distance(pt, line, k, d2);
} }
} // namespace internal } // namespace internal
template <class K>
inline
typename K::FT
squared_distance(const Point_3<K>& pt,
const Line_3<K>& line)
{
return K().compute_squared_distance_3_object()(pt, line);
}
template <class K>
inline
typename K::FT
squared_distance(const Line_3<K>& line,
const Point_3<K>& pt)
{
return K().compute_squared_distance_3_object()(line, pt);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Point_3<K>& pt,
const Line_3<K>& line,
const typename K::FT& d2)
{
return K().compare_squared_distance_3_object()(pt, line, d2);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Line_3<K>& line,
const Point_3<K>& pt,
const typename K::FT& d2)
{
return K().compare_squared_distance_3_object()(line, pt, d2);
}
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_POINT_3_LINE_3_H #endif // CGAL_DISTANCE_3_POINT_3_LINE_3_H

View File

@ -68,47 +68,6 @@ compare_squared_distance(const typename K::Plane_3& plane,
return compare_squared_distance(pt, plane, k, d2); return compare_squared_distance(pt, plane, k, d2);
} }
} // namespace internal } } // namespace CGAL::internal
template <class K>
inline
typename K::FT
squared_distance(const Point_3<K>& pt,
const Plane_3<K>& plane)
{
return K().compute_squared_distance_3_object()(pt, plane);
}
template <class K>
inline
typename K::FT
squared_distance(const Plane_3<K>& plane,
const Point_3<K>& pt)
{
return K().compute_squared_distance_3_object()(plane, pt);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Point_3<K>& pt,
const Plane_3<K>& pl,
const typename K::FT& d2)
{
return K().compare_squared_distance_3_object()(pt, pl, d2);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Plane_3<K>& pl,
const Point_3<K>& pt,
const typename K::FT& d2)
{
return K().compare_squared_distance_3_object()(pl, pt, d2);
}
} // namespace CGAL
#endif // CGAL_DISTANCE_3_POINT_3_PLANE_3_H #endif // CGAL_DISTANCE_3_POINT_3_PLANE_3_H

View File

@ -45,15 +45,6 @@ compare_squared_distance(const typename K::Point_3& pt1,
} // namespace internal } // namespace internal
template <class K>
inline
typename K::FT
squared_distance(const Point_3<K>& pt1,
const Point_3<K>& pt2)
{
return internal::squared_distance(pt1, pt2, K());
}
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_POINT_3_POINT_3_H #endif // CGAL_DISTANCE_3_POINT_3_POINT_3_H

View File

@ -101,6 +101,7 @@ compare_squared_distance(const typename K::Point_3& pt,
const Vector_3 dir = ray.direction().vector(); const Vector_3 dir = ray.direction().vector();
const Vector_3 diff = vector(ray.source(), pt); const Vector_3 diff = vector(ray.source(), pt);
//Compare first the distance to the line, if larger we can exit early
const typename K::Comparison_result res_pl = compare_squared_distance_to_line(dir, diff, k, d2); const typename K::Comparison_result res_pl = compare_squared_distance_to_line(dir, diff, k, d2);
if(res_pl==LARGER) if(res_pl==LARGER)
return LARGER; return LARGER;
@ -123,45 +124,6 @@ compare_squared_distance(const typename K::Ray_3& ray,
} // namespace internal } // namespace internal
template <class K>
inline
typename K::FT
squared_distance(const Point_3<K>& pt,
const Ray_3<K>& ray)
{
return K().compute_squared_distance_3_object()(pt, ray);
}
template <class K>
inline
typename K::FT
squared_distance(const Ray_3<K>& ray,
const Point_3<K>& pt)
{
return K().compute_squared_distance_3_object()(ray, pt);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Point_3<K>& pt,
const Ray_3<K>& ray,
const typename K::FT& d2)
{
return K().compare_squared_distance_3_object()(pt, ray, d2);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Ray_3<K>& ray,
const Point_3<K>& pt,
const typename K::FT& d2)
{
return K().compare_squared_distance_3_object()(ray, pt, d2);
}
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_POINT_3_RAY_3_H #endif // CGAL_DISTANCE_3_POINT_3_RAY_3_H

View File

@ -79,6 +79,7 @@ squared_distance(const typename K::Point_3& pt,
typedef typename K::Vector_3 Vector_3; typedef typename K::Vector_3 Vector_3;
typename K::Construct_vector_3 vector = k.construct_vector_3_object(); 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();
// assert that the segment is valid (non zero length). // assert that the segment is valid (non zero length).
const Vector_3 diff = vector(seg.source(), pt); const Vector_3 diff = vector(seg.source(), pt);
@ -90,7 +91,7 @@ squared_distance(const typename K::Point_3& pt,
const RT e = wdot(segvec, segvec, k); const RT e = wdot(segvec, segvec, k);
if(wmult((K*)0, d, segvec.hw()) > wmult((K*)0, e, diff.hw())) if(wmult((K*)0, d, segvec.hw()) > wmult((K*)0, e, diff.hw()))
return squared_distance(pt, seg.target(), k); return sq_dist(pt, seg.target());
// This is an expanded call to squared_distance_to_line() to avoid recomputing 'e' // This is an expanded call to squared_distance_to_line() to avoid recomputing 'e'
const Vector_3 wcr = wcross(segvec, diff, k); const Vector_3 wcr = wcross(segvec, diff, k);
@ -113,37 +114,35 @@ typename K::Comparison_result
compare_squared_distance(const typename K::Point_3& pt, compare_squared_distance(const typename K::Point_3& pt,
const typename K::Segment_3& seg, const typename K::Segment_3& seg,
const K& k, const K& k,
const typename K::FT &d2) const typename K::FT& d2)
{ {
typedef typename K::RT RT; typedef typename K::RT RT;
typedef typename K::FT FT; typedef typename K::FT FT;
typedef typename K::Vector_3 Vector_3; typedef typename K::Vector_3 Vector_3;
typename K::Construct_vector_3 vector = k.construct_vector_3_object(); 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();
// assert that the segment is valid (non zero length). // assert that the segment is valid (non zero length).
const Vector_3 diff = vector(seg.source(), pt); const Vector_3 diff = vector(seg.source(), pt);
const Vector_3 segvec = vector(seg.source(), seg.target()); const Vector_3 segvec = vector(seg.source(), seg.target());
//We first compare the distance of the point and the line //Compare first the distance to the line, if larger we can exit early
const typename K::Comparison_result res_pl= compare_squared_distance_to_line(segvec, diff, k, d2); const typename K::Comparison_result res_pl= compare_squared_distance_to_line(segvec, diff, k, d2);
//If greater than d2, we early exit
if(res_pl==LARGER) if(res_pl==LARGER)
return LARGER; return LARGER;
//If distance is realized by the source //If the distance is realized by the source
const RT d = wdot(diff, segvec, k); const RT d = wdot(diff, segvec, k);
if(d <= RT(0)) if(d <= RT(0))
return compare(FT(diff*diff), d2); return compare(FT(diff*diff), d2);
//If distance is realized by the target //If the distance is realized by the target
const RT e = wdot(segvec, segvec, k); const RT e = wdot(segvec, segvec, k);
if(wmult((K*)0, d, segvec.hw()) > wmult((K*)0, e, diff.hw())) if(wmult((K*)0, d, segvec.hw()) > wmult((K*)0, e, diff.hw()))
return compare_squared_distance(pt, seg.target(), k, d2); return csq_dist(pt, seg.target(), d2);
//If distance is realized by the interior, it is equal to the one of the line //If the distance is realized by the interior
return res_pl; return res_pl;
} }
@ -160,44 +159,6 @@ compare_squared_distance(const typename K::Segment_3& seg,
} // namespace internal } // namespace internal
template <class K>
inline
typename K::FT
squared_distance(const Point_3<K>& pt,
const Segment_3<K>& seg)
{
return K().compute_squared_distance_3_object()(pt, seg);
}
template <class K>
inline
typename K::FT
squared_distance(const Segment_3<K>& seg,
const Point_3<K>& pt)
{
return K().compute_squared_distance_3_object()(seg, pt);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Point_3<K>& pt,
const Segment_3<K>& seg,
const typename K::FT &d2)
{
return K().compare_squared_distance_3_object()(pt, seg, d2);
}
template <class K>
inline
typename K::Comparison_result
compare_squared_distance(const Segment_3<K>& seg,
const Point_3<K>& pt,
const typename K::FT &d2)
{
return K().compare_squared_distance_3_object()(seg, pt, d2);
}
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_POINT_3_SEGMENT_3_H #endif // CGAL_DISTANCE_3_POINT_3_SEGMENT_3_H

View File

@ -140,97 +140,6 @@ squared_distance(const typename K::Segment_3& s1,
return res; return res;
} }
// Using Lumelsky, 'On Fast Computation of Distance Between Line Segments' 1984
template <typename K>
typename K::Comparison_result
compare_squared_distance(const typename K::Segment_3& s1,
const typename K::Segment_3& s2,
const K& k,
const typename K::FT& d2)
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point_3;
typedef typename K::Vector_3 Vector_3;
typename K::Construct_vertex_3 vertex = k.construct_vertex_3_object();
typename K::Construct_vector_3 cv = k.construct_vector_3_object();
typename K::Compute_scalar_product_3 sp = k.compute_scalar_product_3_object();
typename K::Compute_squared_distance_3 sq_dist = k.compute_squared_distance_3_object();
const Point_3& p1 = vertex(s1, 0);
const Point_3& q1 = vertex(s1, 1);
const Point_3& p2 = vertex(s2, 0);
const Point_3& q2 = vertex(s2, 1);
const Vector_3 v1 = cv(p1, q1), v2 = cv(p2, q2);
const Vector_3 p1p2 = cv(p1, p2);
//If degenerate segment, compare distance between the point and the other segment
if(p1 == q1)
if(p2 == q2)
return compare_square_distance(p1,p2,k,d2);
else
return compare_square_distance(p1,s2,k,d2);
else if(p2 == q2)
return compare_square_distance(s1,p2,k,d2);
//Compare distance between the lines
const Vector_3 normal = wcross(v1, v2, k);
const Vector_3 diff = p1p2;
//If the lines are at distance more than d, the segment do not be at distance less than d
typename K::Comparison_result res_ll=compare_squared_distance(v1.supporting_line(), v2.supporting_line(), k, d2);
if(res_ll==LARGER)
return LARGER; //Early exit
//Compute distance between the segments
//Since we already compare the distance between the lines, we care about only the cases where
//the distance are realized by vertices aka res.x or res.y are 0 or 1
const FT a = sp(v1, v1);
const FT b = - sp(v1, v2);
const FT c = - b;
const FT d = - sp(v2, v2);
const FT e = sp(v1, p1p2);
const FT f = sp(v2, p1p2);
CGAL_assertion(a > 0 && d < 0);
const FT det = a*d - b*c;
const FT res_x;
if(det == 0)
res_x = 0;
else
res_x = boost::algorithm::clamp<FT>((e*d - b*f) / det, 0, 1);
FT xc = res_x*c;
// res.y = (f - xc) / d, by definition, but building it up more efficiently
if(f > xc) // y < 0 <=> f - xc / d < 0 <=> f - xc > 0 (since d is -||v2||)
{
// res_y = 0;
res_x = boost::algorithm::clamp<FT>(e/a, 0, 1); // (e + y*c) / a
return compare(sq_dist(p1+res_x*v1,p2), d2);
}
else // y >= 0
{
FT n = f - xc; // delay the division by d
if(n < d) // y > 1 <=> n / d > 1 <=> n < d (once again, important to note that d is negative!)
{
// res_y = 1;
res_x = boost::algorithm::clamp<FT>((e + c) / a, 0, 1); // (e + y*c) / a
return compare(sq_dist(p1+res_x*v1,p2), d2);
}
else if(res_x==0 || res_x==1) // 0 <= y <= 1
{
FT res_y = n / d;
return compare(sq_dist(p1 + res_x*v1, p2 + res_y*v2), d2);
}
else
{
//Already computed by distance line line
return res_ll;
}
}
}
} // namespace internal } // namespace internal
} // namespace Distance_3 } // namespace Distance_3
@ -279,26 +188,97 @@ squared_distance(const typename K::Segment_3& seg1,
return res.squared_distance; return res.squared_distance;
} }
template <typename K>
typename K::Comparison_result
compare_squared_distance(const typename K::Segment_3& s1,
const typename K::Segment_3& s2,
const K& k,
const typename K::FT& d2)
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point_3;
typedef typename K::Vector_3 Vector_3;
typename K::Construct_vertex_3 vertex = k.construct_vertex_3_object();
typename K::Construct_vector_3 cv = k.construct_vector_3_object();
typename K::Compute_scalar_product_3 sp = k.compute_scalar_product_3_object();
typename K::Compute_squared_distance_3 sq_dist = k.compute_squared_distance_3_object();
typename K::Compare_squared_distance_3 csq_dist = k.compare_squared_distance_3_object();
const Point_3& p1 = vertex(s1, 0);
const Point_3& q1 = vertex(s1, 1);
const Point_3& p2 = vertex(s2, 0);
const Point_3& q2 = vertex(s2, 1);
const Vector_3 v1 = cv(p1, q1), v2 = cv(p2, q2);
const Vector_3 p1p2 = cv(p1, p2);
// If degenerate segment, compare the distance between the point and the other segment
if(p1 == q1)
if(p2 == q2)
return csq_dist(p1,p2,d2);
else
return csq_dist(p1,s2,d2);
else if(p2 == q2)
return csq_dist(s1,p2,d2);
const Vector_3 normal = wcross(v1, v2, k);
const Vector_3 diff = p1p2;
// 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)
return LARGER;
// Compute the distance between the segments
// TODO some factorization with above function? only the last case is different
const FT a = sp(v1, v1);
const FT b = - sp(v1, v2);
const FT c = - b;
const FT d = - sp(v2, v2);
const FT e = sp(v1, p1p2);
const FT f = sp(v2, p1p2);
CGAL_assertion(a > 0 && d < 0);
const FT det = a*d - b*c;
FT res_x;
if(det == 0)
res_x = 0;
else
res_x = boost::algorithm::clamp<FT>((e*d - b*f) / det, 0, 1);
FT xc = res_x*c;
// res.y = (f - xc) / d, by definition, but building it up more efficiently
if(f > xc) // y < 0 <=> f - xc / d < 0 <=> f - xc > 0 (since d is -||v2||)
{
// res_y = 0;
res_x = boost::algorithm::clamp<FT>(e/a, 0, 1); // (e + y*c) / a
return compare(sq_dist(p1+res_x*v1,p2), d2);
}
else // y >= 0
{
FT n = f - xc; // delay the division by d
if(n < d) // y > 1 <=> n / d > 1 <=> n < d (once again, important to note that d is negative!)
{
// res_y = 1;
res_x = boost::algorithm::clamp<FT>((e + c) / a, 0, 1); // (e + y*c) / a
return compare(sq_dist(p1+res_x*v1,p2), d2);
}
else if(res_x==0 || res_x==1) // 0 <= y <= 1
{
FT res_y = n / d;
return compare(sq_dist(p1 + res_x*v1, p2 + res_y*v2), d2);
}
else
{
//Already computed by distance line line
return res_ll;
}
}
}
} // namespace internal } // namespace internal
template <class K>
inline
typename K::FT
squared_distance_parallel(const Segment_3<K>& seg1,
const Segment_3<K>& seg2)
{
return internal::squared_distance_parallel(seg1, seg2, K());
}
template <class K>
inline
typename K::FT
squared_distance(const Segment_3<K>& seg1,
const Segment_3<K>& seg2)
{
return K().compute_squared_distance_3_object()(seg1, seg2);
}
} // namespace CGAL } // namespace CGAL
#endif // CGAL_DISTANCE_3_SEGMENT_3_SEGMENT_3_H #endif // CGAL_DISTANCE_3_SEGMENT_3_SEGMENT_3_H

View File

@ -217,8 +217,8 @@ template <typename K>
typename K::Comparison_result typename K::Comparison_result
compare_squared_distance(const typename K::Triangle_3& tr1, compare_squared_distance(const typename K::Triangle_3& tr1,
const typename K::Triangle_3& tr2, const typename K::Triangle_3& tr2,
const typename K::FT& d, const K& k,
const K& k) const typename K::FT& d2)
{ {
typedef typename K::FT FT; typedef typename K::FT FT;
@ -237,15 +237,15 @@ compare_squared_distance(const typename K::Triangle_3& tr1,
{ {
for(int j=0; j<3; ++j) for(int j=0; j<3; ++j)
{ {
if(CGAL::possibly(CGAL::compare_squared_distance(Line_3(vertex(tr1, i%3), vertex(tr1, (i+1)%3)),Line_3(vertex(tr2, j%3), vertex(tr2, (j+1)%3)),d)!=CGAL::LARGER)) if(CGAL::possibly(CGAL::compare_squared_distance(Line_3(vertex(tr1, i%3), vertex(tr1, (i+1)%3)),Line_3(vertex(tr2, j%3), vertex(tr2, (j+1)%3)),d2)!=CGAL::LARGER))
{ {
typename K::comparison_result res_seg_seg= CGAL::compare_squared_distance(Segment_3(vertex(tr1, i%3), vertex(tr1, (i+1)%3)),Segment_3(vertex(tr2, j%3), vertex(tr2, (j+1)%3)),d); typename K::comparison_result res_seg_seg= CGAL::compare_squared_distance(Segment_3(vertex(tr1, i%3), vertex(tr1, (i+1)%3)),Segment_3(vertex(tr2, j%3), vertex(tr2, (j+1)%3)),d2);
if(is_certain(res_seg_seg) && res_seg_seg==CGAL::SMALLER) if(is_certain(res_seg_seg) && res_seg_seg==CGAL::SMALLER)
return CGAL::SMALLER; return CGAL::SMALLER;
} }
} }
typename K::comparison_result res_v_pl= CGAL::compare_squared_distance(vertex(tr1, i), tr2.supporting_plane(),d); typename K::comparison_result res_v_pl= CGAL::compare_squared_distance(vertex(tr1, i), tr2.supporting_plane(),d2);
if(tr_contains_proj_p(tr2, vertex(tr1, i))) if(tr_contains_proj_p(tr2, vertex(tr1, i)))
if(res_v_pl==CGAL::SMALLER) if(res_v_pl==CGAL::SMALLER)
return CGAL::SMALLER; return CGAL::SMALLER;

View File

@ -0,0 +1,99 @@
// Copyright (c) 2025
// GeometryFactory (France),
//
// This file is part of CGAL (www.cgal.org)
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Léo Valque
#ifndef CGAL_KERNEL_GLOBAL_FUNCTIONS_DISTANCE_3_H
#define CGAL_KERNEL_GLOBAL_FUNCTIONS_DISTANCE_3_H
// Distance functions calling the kernel functor.
#define CGAL_SQUARED_DISTANCE_FUNCTION(A, B) \
template <class K> \
inline \
typename K::FT \
squared_distance(const A<K>& a, const B<K>& b) \
{ \
return K().compute_squared_distance_3_object()(a, b); \
} \
template <class K> \
inline \
typename K::FT \
squared_distance(const B<K>& a, const A<K>& b) \
{ \
return K().compute_squared_distance_3_object()(b, a); \
}
#define CGAL_SQUARED_DISTANCE_FUNCTION_SELF(A) \
template <class K> \
inline \
typename K::FT \
squared_distance(const A<K>& a, const A<K>& b) \
{ \
return K().compute_squared_distance_3_object()(a, b); \
}
#define CGAL_COMPARE_SQUARED_DISTANCE_FUNCTION(A, B) \
template <class K> \
inline \
typename K::Comparison_result \
compare_squared_distance(const A<K>& a, \
const B<K>& b, \
const typename K::FT& d2) \
{ \
return K().compare_squared_distance_3_object()(a, b, d2); \
} \
template <class K> \
inline \
typename K::Comparison_result \
compare_squared_distance(const B<K>& b, \
const A<K>& a, \
const typename K::FT& d2) \
{ \
return K().compare_squared_distance_3_object()(b, a, d2); \
}
#define CGAL_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(A) \
template <class K> \
inline \
typename K::Comparison_result \
compare_squared_distance(const A<K>& a, \
const A<K>& b, \
const typename K::FT& d2) \
{ \
return K().compare_squared_distance_3_object()(a, b, d2); \
}
#define CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(A) \
CGAL_SQUARED_DISTANCE_FUNCTION_SELF(A) \
CGAL_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(A)
#define CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(A, B) \
CGAL_SQUARED_DISTANCE_FUNCTION(A, B) \
CGAL_COMPARE_SQUARED_DISTANCE_FUNCTION(A, B)
namespace CGAL {
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(Point_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(Segment_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(Line_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION_SELF(Plane_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Point_3, Line_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Point_3, Ray_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Point_3, Segment_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Point_3, Plane_3)
CGAL_COMPUTE_AND_COMPARE_SQUARED_DISTANCE_FUNCTION(Line_3, Plane_3)
} //namespace CGAL
#endif // CGAL_KERNEL_GLOBAL_FUNCTIONS_DISTANCE_3_H

View File

@ -45,4 +45,6 @@
#include <CGAL/Distance_3/Plane_3_Plane_3.h> #include <CGAL/Distance_3/Plane_3_Plane_3.h>
#include <CGAL/global_functions_distance_3.h>
#endif // CGAL_DISTANCE_3_H #endif // CGAL_DISTANCE_3_H

View File

@ -115,76 +115,112 @@ private:
return true; return true;
} }
template <typename O1, typename O2> void do_intersect_check(const P&, const P&) { }
void check_compare_squared_distance(const O1& o1, const O2& o2, const FT& d, const Comparison_result& expected_result)
{
const FT res_o1o2 = CGAL::compare_squared_distance(o1, o2, d);
const FT res_o2o1 = CGAL::compare_squared_distance(o2, o1, d);
assert(res_o1o2 == expected_result); template <typename O2>
assert(res_o2o1 == expected_result); void do_intersect_check(const P& p, const O2& o2)
{
if(!o2.is_degenerate() && CGAL::do_intersect(p, o2))
{
assert(are_equal(CGAL::squared_distance(p, o2), FT(0)));
assert(are_equal(CGAL::squared_distance(o2, p), FT(0)));
}
}
template <typename O1, typename O2>
void do_intersect_check(const O1& o1, const O2& o2)
{
if(!o1.is_degenerate() && !o2.is_degenerate() && CGAL::do_intersect(o1, o2))
{
assert(are_equal(CGAL::squared_distance(o1, o2), FT(0)));
assert(are_equal(CGAL::squared_distance(o2, o1), FT(0)));
}
}
template <typename O1, typename O2>
void check_compare_squared_distance(const O1& o1, const O2& o2, const FT& expected_result)
{
// const FT res_o1o2 = K().compare_squared_distance_3_object()(o1, o2, expected_result);
// const FT res_o2o1 = K().compare_squared_distance_3_object()(o2, o1, expected_result);
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);
const bool res_s_o1o2 = (CGAL::compare_squared_distance(o1, o2, expected_result+1) == CGAL::SMALLER);
const bool res_s_o2o1 = (CGAL::compare_squared_distance(o2, o1, expected_result+1) == CGAL::SMALLER);
const bool res_l_o1o2 = (CGAL::compare_squared_distance(o1, o2, expected_result-1) == CGAL::LARGER);
const bool res_l_o2o1 = (CGAL::compare_squared_distance(o2, o1, expected_result-1) == CGAL::LARGER);
assert(res_e_o1o2);
assert(res_e_o2o1);
assert(res_s_o1o2);
assert(res_s_o2o1);
assert(res_l_o1o2);
assert(res_l_o2o1);
}
template <typename O1, typename O2>
void check_compare_squared_distance_with_bound(const O1& o1, const O2& o2, const FT& upper_bound)
{
// const FT res_o1o2 = K().compare_squared_distance_3_object()(o1, o2, expected_result);
// const FT res_o2o1 = K().compare_squared_distance_3_object()(o2, o1, expected_result);
const bool res_o1o2 = (CGAL::compare_squared_distance(o1, o2, upper_bound) == CGAL::SMALLER);
const bool res_o2o1 = (CGAL::compare_squared_distance(o2, o1, upper_bound) == CGAL::SMALLER);
assert(res_o1o2);
assert(res_o2o1);
} }
private: private:
void P_P() void P_P()
{ {
std::cout << "Point - Point" << std::endl; std::cout << "Point - Point" << std::endl;
check_compare_squared_distance(p(0, 0, 0), p(0, 0, 0), 0, CGAL::EQUAL); check_compare_squared_distance(p(0, 0, 0), p(0, 0, 0), 0);
check_compare_squared_distance(p(0, 0, 0), p(0, 0, 0), 1, CGAL::SMALLER); check_compare_squared_distance(p(3, 5, 7), p(0, 0, 0), 83);
check_compare_squared_distance(p(3, 5, 7), p(0, 0, 0), 83, CGAL::EQUAL);
check_compare_squared_distance(p(3, 5, 7), p(0, 0, 0), 80, CGAL::LARGER);
} }
void P_S() void P_S()
{ {
std::cout << "Point - Segment" << std::endl; std::cout << "Point - Segment" << std::endl;
check_compare_squared_distance(p(0, 1, 2), S{p(-3, 0, 0), p( 2, 0, 0)}, 4, CGAL::LARGER); check_compare_squared_distance(p(0, 1, 2), S{p(-3, 0, 0), p( 2, 0, 0)}, 5);
check_compare_squared_distance(p(0, 1, 2), S{p(-3, 0, 0), p( 2, 0, 0)}, 5, CGAL::EQUAL); check_compare_squared_distance(p(0, 1, 2), S{p( 3, 0, 0), p( 2, 0, 0)}, 9);
check_compare_squared_distance(p(0, 1, 2), S{p(-3, 0, 0), p( 2, 0, 0)}, 6, CGAL::SMALLER); check_compare_squared_distance(p(0, 1, 2), S{p( 2, 0, 0), p( 3, 0, 0)}, 9);
check_compare_squared_distance(p(6, 1, 2), S{p( 2, 0, 0), p( 3, 0, 0)}, 14);
check_compare_squared_distance(p(0, 1, 2), S{p( 3, 0, 0), p( 2, 0, 0)}, 8, CGAL::LARGER);
check_compare_squared_distance(p(0, 1, 2), S{p( 3, 0, 0), p( 2, 0, 0)}, 9, CGAL::EQUAL);
check_compare_squared_distance(p(0, 1, 2), S{p( 3, 0, 0), p( 2, 0, 0)}, 10, CGAL::SMALLER);
check_compare_squared_distance(p(0, 1, 2), S{p( 2, 0, 0), p( 3, 0, 0)}, 10, CGAL::SMALLER);
check_compare_squared_distance(p(6, 1, 2), S{p( 2, 0, 0), p( 3, 0, 0)}, 13, CGAL::LARGER);
check_compare_squared_distance(p(6, 1, 2), S{p( 2, 0, 0), p( 3, 0, 0)}, 14, CGAL::EQUAL);
check_compare_squared_distance(p(6, 1, 2), S{p( 2, 0, 0), p( 3, 0, 0)}, 15, CGAL::SMALLER);
} }
// void P_T() // void P_T()
// { // {
// std::cout << "Point - Triangle" << std::endl; // std::cout << "Point - Triangle" << std::endl;
// check_squared_distance(p(0, 1, 2), T{p(0, 0, 0), p(2, 0, 0), p(0, 2, 0)}, 4); // check_compare_squared_distance(p(0, 1, 2), T{p(0, 0, 0), p(2, 0, 0), p(0, 2, 0)}, 4);
// T t(p(0,0,0), p(3,0,0), p(3,3,0)); // T t(p(0,0,0), p(3,0,0), p(3,3,0));
// check_squared_distance (p(-1, -1, 0), t, 2); // check_compare_squared_distance (p(-1, -1, 0), t, 2);
// check_squared_distance (p(-1, 0, 0), t, 1); // check_compare_squared_distance (p(-1, 0, 0), t, 1);
// check_squared_distance (p(0, 0, 0), t, 0); // check_compare_squared_distance (p(0, 0, 0), t, 0);
// check_squared_distance (p(1, 0, 0), t, 0); // check_compare_squared_distance (p(1, 0, 0), t, 0);
// check_squared_distance (p(4, 0, 0), t, 1); // check_compare_squared_distance (p(4, 0, 0), t, 1);
// check_squared_distance (p(1, -1, 0), t, 1); // check_compare_squared_distance (p(1, -1, 0), t, 1);
// check_squared_distance (p(1, 1, 1), t, 1); // check_compare_squared_distance (p(1, 1, 1), t, 1);
// check_squared_distance (p(1, 0, 1), t, 1); // check_compare_squared_distance (p(1, 0, 1), t, 1);
// check_squared_distance (p(0, 0, 1), t, 1); // check_compare_squared_distance (p(0, 0, 1), t, 1);
// // Degenerate // // Degenerate
// check_squared_distance (p(1, 2, 3), T(p(4,3,2), p(4,3,2), p(4,3,2)), squared_distance(p(1, 2, 3), p(4,3,2))); // check_compare_squared_distance (p(1, 2, 3), T(p(4,3,2), p(4,3,2), p(4,3,2)), squared_distance(p(1, 2, 3), p(4,3,2)));
// check_squared_distance (p(1, 2, 3), T(p(4,3,2), p(10,12,3), p(4,3,2)), squared_distance(p(1, 2, 3), p(4,3,2))); // check_compare_squared_distance (p(1, 2, 3), T(p(4,3,2), p(10,12,3), p(4,3,2)), squared_distance(p(1, 2, 3), p(4,3,2)));
// check_squared_distance (p(0, 0, 0), T(p(4,3,2), p(4,-3,-2), p(4,3,2)), squared_distance(p(0, 0, 0), p(4,0,0))); // check_compare_squared_distance (p(0, 0, 0), T(p(4,3,2), p(4,-3,-2), p(4,3,2)), squared_distance(p(0, 0, 0), p(4,0,0)));
// // On the triangle // // On the triangle
// check_squared_distance (p(7, 1, -5), T(p(2,9,8), p(-4,-3,-5), p(7, 1, -5)), 0); // vertex // check_compare_squared_distance (p(7, 1, -5), T(p(2,9,8), p(-4,-3,-5), p(7, 1, -5)), 0); // vertex
// check_squared_distance (p(7, 1, -5), T(p(14,2,-10), p(-7,-1,5), p(8, 3, -1)), 0); // edge // check_compare_squared_distance (p(7, 1, -5), T(p(14,2,-10), p(-7,-1,5), p(8, 3, -1)), 0); // edge
// check_squared_distance (p(1, 4, -3), T(p(0,-8,-3), p(-5,14,-3), p(10, 1, -3)), 0); // face // check_compare_squared_distance (p(1, 4, -3), T(p(0,-8,-3), p(-5,14,-3), p(10, 1, -3)), 0); // face
// // General // // General
// check_squared_distance (p(-15, 1, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), 25); // check_compare_squared_distance (p(-15, 1, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), 25);
// check_squared_distance (p(-5, 0, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), squared_distance(p(-5, 0, 0), S(p(-10, 1, 0), p(0,0,0)))); // check_compare_squared_distance (p(-5, 0, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), squared_distance(p(-5, 0, 0), S(p(-10, 1, 0), p(0,0,0))));
// check_squared_distance (p(0, -3, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), 9); // check_compare_squared_distance (p(0, -3, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), 9);
// check_squared_distance (p(3, -3, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), squared_distance(p(3, -3, 0), S(p(0,0,0), p(10,0,0)))); // check_compare_squared_distance (p(3, -3, 0), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), squared_distance(p(3, -3, 0), S(p(0,0,0), p(10,0,0))));
// check_squared_distance (p(16, 1, 1), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), 38); // check_compare_squared_distance (p(16, 1, 1), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), 38);
// check_squared_distance (p(5, 5, 2), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), squared_distance(p(5, 5, 2), S(p(10,0,0), p(-10,1,0)))); // check_compare_squared_distance (p(5, 5, 2), T(p(-10, 1, 0), p(0,0,0), p(10,0,0)), squared_distance(p(5, 5, 2), S(p(10,0,0), p(-10,1,0))));
// for(int i=0; i<N; ++i) // for(int i=0; i<N; ++i)
// { // {
@ -193,321 +229,307 @@ private:
// P p2 = random_point(); // P p2 = random_point();
// P q = random_point(); // P q = random_point();
// check_squared_distance_with_bound(q, T(p0, p1, p2), squared_distance(q, S(p0, p1))); // check_compare_squared_distance_with_bound(q, T(p0, p1, p2), squared_distance(q, S(p0, p1)));
// check_squared_distance_with_bound(q, T(p0, p1, p2), squared_distance(q, S(p1, p2))); // check_compare_squared_distance_with_bound(q, T(p0, p1, p2), squared_distance(q, S(p1, p2)));
// check_squared_distance_with_bound(q, T(p0, p1, p2), squared_distance(q, S(p2, p0))); // check_compare_squared_distance_with_bound(q, T(p0, p1, p2), squared_distance(q, S(p2, p0)));
// } // }
// } // }
// void P_Tet() // void P_Tet()
// { // {
// std::cout << "Point - Tetrahedron\n"; // std::cout << "Point - Tetrahedron\n";
// check_squared_distance (p(0, 0, 0), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 0); // check_compare_squared_distance (p(0, 0, 0), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 0);
// check_squared_distance (p(0, 0, 2), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 1); // check_compare_squared_distance (p(0, 0, 2), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 1);
// check_squared_distance (p(0, 0, -1), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 1); // check_compare_squared_distance (p(0, 0, -1), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 1);
// check_squared_distance (p(5, 0, 0), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 4, 0, 1)), 2); // check_compare_squared_distance (p(5, 0, 0), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 4, 0, 1)), 2);
// } // }
// void S_S() void S_S()
// { {
// std::cout << "Segment - Segment" << std::endl; std::cout << "Segment - Segment" << std::endl;
// // coplanar segments (hardcoded) // coplanar segments (hardcoded)
// FT z(std::sqrt(2.)); FT z(std::sqrt(2.));
// P p0{-1, 0, z}; P p0{-1, 0, z};
// P p1{ 1, 0, z}; P p1{ 1, 0, z};
// // translations of (0, -1, z) -- (0, 1, z) to have all variations of x&y (<0, [0;1]; >1) in the code // translations of (0, -1, z) -- (0, 1, z) to have all variations of x&y (<0, [0;1]; >1) in the code
// for(int j=-2;j<4; j+=2) for(int j=-2;j<4; j+=2)
// { {
// for(int k=-3;k<3; k+=2) for(int k=-3;k<3; k+=2)
// { {
// P p2{j, k, z}; P p2{j, k, z};
// P p3{j, k+2, z}; P p3{j, k+2, z};
// // to explicit the expected distances // to explicit the expected distances
// if(j == -2 && k == -3) if(j == -2 && k == -3)
// check_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p3, p0)); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p3, p0));
// else if(j == -2 && k == -1) else if(j == -2 && k == -1)
// check_squared_distance(S{p0, p1}, S{p2, p3}, 1); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, 1);
// else if(j == -2 && k == 1) else if(j == -2 && k == 1)
// check_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p2, p0)); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p2, p0));
// else if(j == 0 && k == -3) else if(j == 0 && k == -3)
// check_squared_distance(S{p0, p1}, S{p2, p3}, 1); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, 1);
// else if(j == 0 && k == -1) else if(j == 0 && k == -1)
// check_squared_distance(S{p0, p1}, S{p2, p3}, 0); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, 0);
// else if(j == 0 && k == 1) else if(j == 0 && k == 1)
// check_squared_distance(S{p0, p1}, S{p2, p3}, 1); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, 1);
// else if(j == 2 && k == -3) else if(j == 2 && k == -3)
// check_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p3, p1)); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p3, p1));
// else if(j == 2 && k == -1) else if(j == 2 && k == -1)
// check_squared_distance(S{p0, p1}, S{p2, p3}, 1); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, 1);
// else if(j == 2 && k == 1) else if(j == 2 && k == 1)
// check_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p2, p1)); check_compare_squared_distance(S{p0, p1}, S{p2, p3}, CGAL::squared_distance(p2, p1));
// } }
// } }
// for(int i=0; i<N; ++i) for(int i=0; i<N; ++i)
// { {
// P p0 = random_point(); P p0 = random_point();
// P p1 = random_point(); P p1 = random_point();
// P p2 = random_point(); P p2 = random_point();
// P p3 = random_point(); P p3 = random_point();
// p0 = CGAL::midpoint(p0, p1); p0 = CGAL::midpoint(p0, p1);
// p1 = p0 + FT(0.1) * V{p1 - p0}; p1 = p0 + FT(0.1) * V{p1 - p0};
// p2 = p2 + V{p2 - CGAL::ORIGIN} / CGAL::approximate_sqrt(CGAL::square(p2.x()) + CGAL::square(p2.y()) + CGAL::square(p2.z()) + 3); p2 = p2 + V{p2 - CGAL::ORIGIN} / CGAL::approximate_sqrt(CGAL::square(p2.x()) + CGAL::square(p2.y()) + CGAL::square(p2.z()) + 3);
// p3 = p3 + V{p3 - CGAL::ORIGIN} * FT(std::cos(1.3)); p3 = p3 + V{p3 - CGAL::ORIGIN} * FT(std::cos(1.3));
// // degenerate inputs // degenerate inputs
// check_squared_distance(S{p0, p0}, S{p0, p0}, 0); // both degen check_compare_squared_distance(S{p0, p0}, S{p0, p0}, 0); // both degen
// check_squared_distance(S{p3, p3}, S{p3, p3}, 0); // both degen check_compare_squared_distance(S{p3, p3}, S{p3, p3}, 0); // both degen
// check_squared_distance(S{p0, p0}, S{p0, p1}, 0); // left degen + common extremity (left) check_compare_squared_distance(S{p0, p0}, S{p0, p1}, 0); // left degen + common extremity (left)
// check_squared_distance(S{p0, p0}, S{p1, p0}, 0); // left degen + common extremity (right) check_compare_squared_distance(S{p0, p0}, S{p1, p0}, 0); // left degen + common extremity (right)
// check_squared_distance(S{p0, p0}, S{p2, p3}, CGAL::squared_distance(p0, S(p2, p3))); // left degen check_compare_squared_distance(S{p0, p0}, S{p2, p3}, CGAL::squared_distance(p0, S(p2, p3))); // left degen
// // common extremities // common extremities
// check_squared_distance(S{p2, p3}, S{p2, p3}, 0); // equal segments check_compare_squared_distance(S{p2, p3}, S{p2, p3}, 0); // equal segments
// check_squared_distance(S{p3, p2}, S{p2, p3}, 0); // equal segments but opposite dirs check_compare_squared_distance(S{p3, p2}, S{p2, p3}, 0); // equal segments but opposite dirs
// check_squared_distance(S{p2, p3}, S{p2, p1}, 0); // common generic (p2 common) check_compare_squared_distance(S{p2, p3}, S{p2, p1}, 0); // common generic (p2 common)
// check_squared_distance(S{p2, p3}, S{p1, p2}, 0); // common generic (p2 common) check_compare_squared_distance(S{p2, p3}, S{p1, p2}, 0); // common generic (p2 common)
// check_squared_distance(S{p2, p3}, S{p3, p1}, 0); // common generic (p3 common) check_compare_squared_distance(S{p2, p3}, S{p3, p1}, 0); // common generic (p3 common)
// check_squared_distance(S{p2, p3}, S{p1, p3}, 0); // common generic (p3 common) check_compare_squared_distance(S{p2, p3}, S{p1, p3}, 0); // common generic (p3 common)
// // collinear segments // collinear segments
// const double lambda_4 = r.get_double(0, 1); const double lambda_4 = r.get_double(0, 1);
// const P p4 = p2 + FT(lambda_4) * V{p3 - p2}; const P p4 = p2 + FT(lambda_4) * V{p3 - p2};
// const double lambda_5 = r.get_double(0, 1); const double lambda_5 = r.get_double(0, 1);
// const P p5 = p2 + FT(lambda_5) * V{p3 - p2}; const P p5 = p2 + FT(lambda_5) * V{p3 - p2};
// // [p2;p3) fully contains [p4;p5] // [p2;p3) fully contains [p4;p5]
// check_squared_distance(S{p2, p3}, S{p4, p5}, 0); check_compare_squared_distance(S{p2, p3}, S{p4, p5}, 0);
// check_squared_distance(S{p2, p3}, S{p5, p4}, 0); check_compare_squared_distance(S{p2, p3}, S{p5, p4}, 0);
// check_squared_distance(S{p3, p2}, S{p4, p5}, 0); check_compare_squared_distance(S{p3, p2}, S{p4, p5}, 0);
// check_squared_distance(S{p3, p2}, S{p5, p4}, 0); check_compare_squared_distance(S{p3, p2}, S{p5, p4}, 0);
// const double lambda_6 = r.get_double(0, 1); const double lambda_6 = r.get_double(0, 1);
// const P p6 = p3 + FT(lambda_6) * V{p3 - p2}; const P p6 = p3 + FT(lambda_6) * V{p3 - p2};
// // [p2;p3] overlaps [p5;p6] // [p2;p3] overlaps [p5;p6]
// check_squared_distance(S{p2, p3}, S{p6, p5}, 0); check_compare_squared_distance(S{p2, p3}, S{p6, p5}, 0);
// check_squared_distance(S{p2, p3}, S{p5, p6}, 0); check_compare_squared_distance(S{p2, p3}, S{p5, p6}, 0);
// check_squared_distance(S{p3, p2}, S{p6, p5}, 0); check_compare_squared_distance(S{p3, p2}, S{p6, p5}, 0);
// check_squared_distance(S{p3, p2}, S{p5, p6}, 0); check_compare_squared_distance(S{p3, p2}, S{p5, p6}, 0);
// const double lambda_7 = r.get_double(1, 2); const double lambda_7 = r.get_double(1, 2);
// const P p7 = p3 + FT(lambda_7) * V{p3 - p2}; const P p7 = p3 + FT(lambda_7) * V{p3 - p2};
// // [p2;p3] disjoint && left of [p6;p7] // [p2;p3] disjoint && left of [p6;p7]
// check_squared_distance(S{p2, p3}, S{p6, p7}, CGAL::squared_distance(p3, p6)); check_compare_squared_distance(S{p2, p3}, S{p6, p7}, CGAL::squared_distance(p3, p6));
// check_squared_distance(S{p2, p3}, S{p7, p6}, CGAL::squared_distance(p3, p6)); check_compare_squared_distance(S{p2, p3}, S{p7, p6}, CGAL::squared_distance(p3, p6));
// check_squared_distance(S{p3, p2}, S{p6, p7}, CGAL::squared_distance(p3, p6)); check_compare_squared_distance(S{p3, p2}, S{p6, p7}, CGAL::squared_distance(p3, p6));
// check_squared_distance(S{p3, p2}, S{p7, p6}, CGAL::squared_distance(p3, p6)); check_compare_squared_distance(S{p3, p2}, S{p7, p6}, CGAL::squared_distance(p3, p6));
// // Generic collinear // Generic collinear
// const double lambda_8 = r.get_double(-M, M); const double lambda_8 = r.get_double(-M, M);
// const P p8 = p2 + FT(lambda_8) * V{p3 - p2}; const P p8 = p2 + FT(lambda_8) * V{p3 - p2};
// const double lambda_9 = r.get_double(-M, M); const double lambda_9 = r.get_double(-M, M);
// const P p9 = p2 + FT(lambda_9) * V{p3 - p2}; const P p9 = p2 + FT(lambda_9) * V{p3 - p2};
// S s89(p8, p9); S s89(p8, p9);
// S s32(p3, p2); S s32(p3, p2);
// FT result; FT result;
// if(!s89.is_degenerate() && !s32.is_degenerate()) // for do_intersect... if(!s89.is_degenerate() && !s32.is_degenerate()) // for do_intersect...
// { {
// if(CGAL::do_intersect(s89, s32)) if(CGAL::do_intersect(s89, s32))
// result = 0; result = 0;
// else else
// result = (std::min)(CGAL::squared_distance(p2, p8), result = (std::min)(CGAL::squared_distance(p2, p8),
// (std::min)(CGAL::squared_distance(p2, p9), (std::min)(CGAL::squared_distance(p2, p9),
// (std::min)(CGAL::squared_distance(p3, p8), (std::min)(CGAL::squared_distance(p3, p8),
// CGAL::squared_distance(p3, p9)))); CGAL::squared_distance(p3, p9))));
// #ifdef CGAL_USE_GTE_AS_SANITY_CHECK #ifdef CGAL_USE_GTE_AS_SANITY_CHECK
// gte::DCPQuery<FT, gte::Segment<3, FT>, gte::Segment<3, FT> > GTE_SS_checker; gte::DCPQuery<FT, gte::Segment<3, FT>, gte::Segment<3, FT> > GTE_SS_checker;
// gte::Segment<3, FT> gte_s1{{p8.x(), p8.y(), p8.z()}, {p9.x(), p9.y(), p9.z()}}; gte::Segment<3, FT> gte_s1{{p8.x(), p8.y(), p8.z()}, {p9.x(), p9.y(), p9.z()}};
// gte::Segment<3, FT> gte_s2{{p3.x(), p3.y(), p3.z()}, {p2.x(), p2.y(), p2.z()}}; gte::Segment<3, FT> gte_s2{{p3.x(), p3.y(), p3.z()}, {p2.x(), p2.y(), p2.z()}};
// auto gte_res = GTE_SS_checker(gte_s1, gte_s2); auto gte_res = GTE_SS_checker(gte_s1, gte_s2);
// std::cout << "-------" << std::endl; std::cout << "-------" << std::endl;
// std::cout << "old: " << CGAL::internal::squared_distance_old(s89, s32, K()) << std::endl; std::cout << "old: " << CGAL::internal::squared_distance_old(s89, s32, K()) << std::endl;
// std::cout << "dist (GTE) : " << gte_res.sqrDistance << std::endl; std::cout << "dist (GTE) : " << gte_res.sqrDistance << std::endl;
// #endif #endif
// // Because do_intersect() with constructions is likely to return 'false' even for overlaps // Because do_intersect() with constructions is likely to return 'false' even for overlaps
// assert(are_equal(CGAL::squared_distance(s89, s32), result, false /*verbose*/) || assert(are_equal(CGAL::squared_distance(s89, s32), result, false /*verbose*/) ||
// are_equal(CGAL::squared_distance(s32, s89), FT(0))); are_equal(CGAL::squared_distance(s32, s89), FT(0)));
// } }
// // completely generic // completely generic
// S s1{p0, p1}, s2{p2, p3}; S s1{p0, p1}, s2{p2, p3};
// do_intersect_check(s1, s2); do_intersect_check(s1, s2);
// #ifdef CGAL_USE_GTE_AS_SANITY_CHECK #ifdef CGAL_USE_GTE_AS_SANITY_CHECK
// gte::DCPQuery<FT, gte::Segment<3, FT>, gte::Segment<3, FT> > GTE_SS_checker; gte::DCPQuery<FT, gte::Segment<3, FT>, gte::Segment<3, FT> > GTE_SS_checker;
// gte::Segment<3, FT> gte_s1{{p0.x(), p0.y(), p0.z()}, {p1.x(), p1.y(), p1.z()}}; gte::Segment<3, FT> gte_s1{{p0.x(), p0.y(), p0.z()}, {p1.x(), p1.y(), p1.z()}};
// gte::Segment<3, FT> gte_s2{{p2.x(), p2.y(), p2.z()}, {p3.x(), p3.y(), p3.z()}}; gte::Segment<3, FT> gte_s2{{p2.x(), p2.y(), p2.z()}, {p3.x(), p3.y(), p3.z()}};
// auto gte_res = GTE_SS_checker(gte_s1, gte_s2); auto gte_res = GTE_SS_checker(gte_s1, gte_s2);
// std::cout << "dist (CGAL) : " << CGAL::squared_distance(s1, s2) << std::endl; std::cout << "dist (CGAL) : " << CGAL::squared_distance(s1, s2) << std::endl;
// std::cout << "dist (GTE) : " << gte_res.sqrDistance << std::endl; std::cout << "dist (GTE) : " << gte_res.sqrDistance << std::endl;
// assert(are_equal(CGAL::squared_distance(s1, s2), gte_res.sqrDistance)); assert(are_equal(CGAL::squared_distance(s1, s2), gte_res.sqrDistance));
// #endif #endif
// } }
// // a few brute force checks: sample a segments and use squared_distance(P3, S3) // a few brute force checks: sample a segments and use squared_distance(P3, S3)
// for(int i=0; i<10; ++i) for(int i=0; i<10; ++i)
// { {
// P p0 = random_point(); P p0 = random_point();
// P p1 = random_point(); P p1 = random_point();
// P p2 = random_point(); P p2 = random_point();
// P p3 = random_point(); P p3 = random_point();
// S s01{p0, p1}; S s01{p0, p1};
// S s23{p2, p3}; S s23{p2, p3};
// FT upper_bound = CGAL::squared_distance(p0, p2); FT upper_bound = CGAL::squared_distance(p0, p2);
// V p01 = V{p0, p1} / FT(N); V p01 = V{p0, p1} / FT(N);
// for(int l=0; l<N; ++l) for(int l=0; l<N; ++l)
// { {
// P tp = p0 + FT(l) * p01; P tp = p0 + FT(l) * p01;
// FT sqd = CGAL::squared_distance(tp, s23); FT sqd = CGAL::squared_distance(tp, s23);
// if(sqd < upper_bound) if(sqd < upper_bound)
// upper_bound = sqd; upper_bound = sqd;
// } }
// // bit ugly, but if constructions are not exact, building `tp` introduces some error // bit ugly, but if constructions are not exact, building `tp` introduces some error
// if(epsilon != 0) if(epsilon != 0)
// upper_bound *= (1 + 1e-10); upper_bound *= (1 + 1e-10);
// check_squared_distance_with_bound(s01, s23, upper_bound); check_compare_squared_distance_with_bound(s01, s23, upper_bound);
// } }
// } }
void P_R() void P_R()
{ {
// Note : the value is not verified by hand // Note : the value is not verified by hand
std::cout << "Point - Ray" << std::endl; std::cout << "Point - Ray" << std::endl;
check_compare_squared_distance(p( -8, -7, 0), R{p(23, -27, 2), p( -17, 16, 2)}, 86.368512614, CGAL::SMALLER); check_compare_squared_distance_with_bound(p( -8, -7, 0), R{p(23, -27, 2), p( -17, 16, 2)}, 86.368512613);
} }
// void R_R() // void R_R()
// { // {
// // Note : the values are not verified by hand // // Note : the values are not verified by hand
// std::cout << "Ray - Ray" << std::endl; // std::cout << "Ray - Ray" << std::endl;
// check_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_with_bound(R{p( 0, 0, 30), p( 0, 30, 30)}, R{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002);
// check_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( 1, 0, 0), p( 0, 0, 0)}, R{p( 1, 3, 3), p( 0, 0, 3)}, 9);
// check_squared_distance(R{p( 0, 0, 0), p( 1, 0, 0)}, R{p( 0, 0, 2), p( -1, 0, 2)}, 4); // 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() // void S_R()
// { // {
// // Note : the values are not verified by hand // // Note : the values are not verified by hand
// std::cout << "Segment - Ray" << std::endl; // std::cout << "Segment - Ray" << std::endl;
// check_squared_distance_with_bound(S{p( 0, 0, 30), p( 0, 30, 30)}, R{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002); // 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() // void R_L()
// { // {
// // Note : the values are not verified by hand // // Note : the values are not verified by hand
// std::cout << "Ray - Line" << std::endl; // std::cout << "Ray - Line" << std::endl;
// check_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_with_bound(R{p( 0, 0, 30), p( 0, 30, 30)}, L{p(100, -100, 0), p( 200, 1, 0)}, 20899.504975002);
// check_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(10, 0, 0), p( 20, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 109);
// check_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( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9);
// check_squared_distance(R{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4); // 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() void P_L()
{ {
std::cout << "Point - Line" << std::endl; std::cout << "Point - Line" << std::endl;
check_compare_squared_distance(p( 0, 1, 2), L{p( 2, 0, 0), p( 3, 0, 0)}, 4, CGAL::LARGER); check_compare_squared_distance(p( 0, 1, 2), L{p( 2, 0, 0), p( 3, 0, 0)}, 5);
check_compare_squared_distance(p( 0, 1, 2), L{p( 2, 0, 0), p( 3, 0, 0)}, 5, CGAL::EQUAL); check_compare_squared_distance(p( 0, 0, 2), L{p( 0, 0, 0), p( 1, 2, 0)}, 4);
check_compare_squared_distance(p( 0, 1, 2), L{p( 2, 0, 0), p( 3, 0, 0)}, 6, CGAL::SMALLER);
check_compare_squared_distance(p( 0, 0, 2), L{p( 0, 0, 0), p( 1, 2, 0)}, 3, CGAL::LARGER);
check_compare_squared_distance(p( 0, 0, 2), L{p( 0, 0, 0), p( 1, 2, 0)}, 4, CGAL::EQUAL);
check_compare_squared_distance(p( 0, 0, 2), L{p( 0, 0, 0), p( 1, 2, 0)}, 5, CGAL::SMALLER);
} }
// void S_L() // void S_L()
// { // {
// // Note : the values are not verified by hand // // Note : the values are not verified by hand
// std::cout << "Segment - Line" << std::endl; // std::cout << "Segment - Line" << std::endl;
// check_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( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9);
// check_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(-90, 0, 0), p(-10, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 109);
// check_squared_distance(S{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4); // 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() void L_L()
{ {
// Note : the values are not verified by hand // Note : the values are not verified by hand
std::cout << "Line - Line" << std::endl; std::cout << "Line - Line" << std::endl;
check_compare_squared_distance(L{p(-10, 0, 0), p(-90, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 8, CGAL::LARGER); check_compare_squared_distance(L{p(-10, 0, 0), p(-90, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 9);
check_compare_squared_distance(L{p(-10, 0, 0), p(-90, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 9, CGAL::EQUAL); check_compare_squared_distance(L{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9);
check_compare_squared_distance(L{p(-10, 0, 0), p(-90, 0, 0)}, L{p( 0, 0, 3), p( 0, 3, 3)}, 10, CGAL::SMALLER); check_compare_squared_distance(L{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4);
check_compare_squared_distance(L{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 8, CGAL::LARGER);
check_compare_squared_distance(L{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 9, CGAL::EQUAL);
check_compare_squared_distance(L{p( 1, 0, 0), p( 0, 0, 0)}, L{p( 1, 3, 3), p( 0, 0, 3)}, 10, CGAL::SMALLER);
check_compare_squared_distance(L{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 3, CGAL::LARGER);
check_compare_squared_distance(L{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 4, CGAL::EQUAL);
check_compare_squared_distance(L{p( 0, 0, 0), p( 1, 0, 0)}, L{p( 0, 0, 2), p( -1, 0, 2)}, 5, CGAL::SMALLER);
} }
void P_Pl() void P_Pl()
{ {
std::cout << "Point - Plane" << std::endl; std::cout << "Point - Plane" << std::endl;
check_compare_squared_distance(p(2, 5, 3), Pl(0, 1, 0, 0), 24, CGAL::LARGER); check_compare_squared_distance(p(2, 5, 3), Pl(0, 1, 0, 0), 25);
check_compare_squared_distance(p(2, 5, 3), Pl(0, 1, 0, 0), 25, CGAL::EQUAL);
check_compare_squared_distance(p(2, 5, 3), Pl(0, 1, 0, 0), 26, CGAL::SMALLER);
} }
// void S_Pl() // void S_Pl()
// { // {
// std::cout << "Segment - Plane" << std::endl; // std::cout << "Segment - Plane" << std::endl;
// check_squared_distance(S{p(2, -3, 3), p( 3,-7, 4)}, pl(0, 1, 0, 0), 9); // check_compare_squared_distance(S{p(2, -3, 3), p( 3,-7, 4)}, pl(0, 1, 0, 0), 9);
// } // }
// void R_Pl() // void R_Pl()
// { // {
// std::cout << "Ray - Plane" << std::endl; // std::cout << "Ray - Plane" << std::endl;
// check_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), 16);
// check_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, 4, 4)}, Pl(0, 1, 0, 0), 0);
// check_squared_distance(R{p(2, -4, 3), p( 3,-8, 4)}, Pl(0, 1, 0, 0), 16); // check_compare_squared_distance(R{p(2, -4, 3), p( 3,-8, 4)}, Pl(0, 1, 0, 0), 16);
// } // }
// void L_Pl() void L_Pl()
// { {
// std::cout << "Line - Plane" << std::endl; std::cout << "Line - Plane" << std::endl;
// check_squared_distance(L{p(2, -4, 3), p( 3,-4, 4)}, Pl(0, 1, 0, 0), 16); check_compare_squared_distance(L{p(2, -4, 3), p( 3,-4, 4)}, Pl(0, 1, 0, 0), 16);
// check_squared_distance(L{p(2, -4, 3), p( 3, 4, 4)}, Pl(0, 1, 0, 0), 0); check_compare_squared_distance(L{p(2, -4, 3), p( 3, 4, 4)}, Pl(0, 1, 0, 0), 0);
// check_squared_distance(L{p(2, -4, 3), p( 3,-8, 4)}, Pl(0, 1, 0, 0), 0); check_compare_squared_distance(L{p(2, -4, 3), p( 3,-8, 4)}, Pl(0, 1, 0, 0), 0);
// } }
// void Pl_Pl() void Pl_Pl()
// { {
// std::cout << "Plane - Plane" << std::endl; std::cout << "Plane - Plane" << std::endl;
// Pl p1(0, 1, 0, 0); Pl p1(0, 1, 0, 0);
// typename K::Vector_3 v = -p1.orthogonal_vector(); typename K::Vector_3 v = -p1.orthogonal_vector();
// v /= CGAL::approximate_sqrt(v.squared_length()); v /= CGAL::approximate_sqrt(v.squared_length());
// Pl p2 = Pl(0,-1,0,6); Pl p2 = Pl(0,-1,0,6);
// check_squared_distance(p1,p2, 36); check_compare_squared_distance(p1,p2, 36);
// check_squared_distance(Pl(-2, 1, 1, 0), Pl(2, 1, 3, 0), 0); check_compare_squared_distance(Pl(-2, 1, 1, 0), Pl(2, 1, 3, 0), 0);
// } }
// void T_T() // void T_T()
// { // {
// std::cout << "Triangle - Triangle" << std::endl; // std::cout << "Triangle - Triangle" << std::endl;
// // min between vertices (hardcoded) // // min between vertices (hardcoded)
// check_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(0,0,2), p(-1,0,2), p(0,-1,2)}, 4);
// check_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(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_squared_distance(T{p(1,2,3), P{FT(4.2),FT(5.3),-6}, p(7,-8,9)}, // 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)}, // 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})); // CGAL::squared_distance(P{FT(4.2),FT(5.3),-6}, P{FT(10.1), 12, -10}));
// // min vertex-edge (hardcoded) // // min vertex-edge (hardcoded)
// check_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(1,0,0), p(0,1,0)}, T{p(1,1,0), p(2,1,0), p(1,2,0)}, 0.5);
// check_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); // 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) // for(int i=0; i<N; ++i)
// { // {
@ -529,95 +551,95 @@ private:
// p5 = p5 + V{p5 - CGAL::ORIGIN} * FT(std::cos(1.3)); // p5 = p5 + V{p5 - CGAL::ORIGIN} * FT(std::cos(1.3));
// // degenerate inputs // // degenerate inputs
// check_squared_distance(T{p3, p3, p3}, T{p3, p3, p3}, 0); // both degen // check_compare_squared_distance(T{p3, p3, p3}, T{p3, p3, p3}, 0); // both degen
// check_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{p3, p3, p3}, CGAL::squared_distance(p0, p3)); // both degen
// check_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{p0, p0, p3}, 0); // single degen and common edge
// check_squared_distance(T{p0, p0, p0}, T{p3, p0, p0}, 0); // check_compare_squared_distance(T{p0, p0, p0}, T{p3, p0, p0}, 0);
// check_squared_distance(T{p0, p0, p0}, T{p0, p3, p0}, 0); // check_compare_squared_distance(T{p0, p0, p0}, T{p0, p3, p0}, 0);
// check_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{p0, p3, p4}, 0); // single degen and common vertex
// check_squared_distance(T{p0, p0, p0}, T{p3, p0, p4}, 0); // check_compare_squared_distance(T{p0, p0, p0}, T{p3, p0, p4}, 0);
// check_squared_distance(T{p0, p0, p0}, T{p3, p4, p0}, 0); // check_compare_squared_distance(T{p0, p0, p0}, T{p3, p4, p0}, 0);
// // degen into point & degen into segment // // degen into point & degen into segment
// check_squared_distance(T{p1, p1, p1}, T{p4, p3, p3}, CGAL::squared_distance(p1, S{p3, p4})); // check_compare_squared_distance(T{p1, p1, p1}, T{p4, p3, p3}, CGAL::squared_distance(p1, S{p3, p4}));
// check_squared_distance(T{p5, p5, p5}, T{p3, p3, p4}, CGAL::squared_distance(p5, S{p3, p4})); // check_compare_squared_distance(T{p5, p5, p5}, T{p3, p3, p4}, CGAL::squared_distance(p5, S{p3, p4}));
// // both degen into segment // // both degen into segment
// check_squared_distance(T{p0, p1, p0}, T{p3, p3, p4}, CGAL::squared_distance(S{p0, p1}, S{p3, p4})); // check_compare_squared_distance(T{p0, p1, p0}, T{p3, p3, p4}, CGAL::squared_distance(S{p0, p1}, S{p3, p4}));
// check_squared_distance(T{p5, p5, p4}, T{p4, p3, p3}, CGAL::squared_distance(S{p5, p4}, 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 vertex // // common vertex
// check_squared_distance(T{p0, p1, p2}, T{p0, p3, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p0, p3, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p3, p0, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p3, p0, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p3, p0}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p0}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p1, p3, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p1, p3, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p3, p1, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p3, p1, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p3, p1}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p1}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p2, p3, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p2, p3, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p3, p2, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p3, p2, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p3, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p3, p2}, 0);
// // common edge // // common edge
// check_squared_distance(T{p0, p1, p2}, T{p0, p1, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p0, p1, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p1, p0, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p1, p0, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p0, p1}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p0, p1}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p1, p0}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p1, p0}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p0, p4, p1}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p0, p4, p1}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p2, p1, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p2, p1, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p1, p2, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p1, p2, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p2, p1}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p2, p1}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p1, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p1, p2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p2, p4, p1}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p2, p4, p1}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p1, p4, p2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p0, p2, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p0, p2, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p2, p0, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p2, p0, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p0, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p0, p2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, p2, p0}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, p2, p0}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p0, p4, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p0, p4, p2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p2, p4, p0}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p2, p4, p0}, 0);
// // same triangle // // same triangle
// check_squared_distance(T{p0, p1, p2}, T{p0, p1, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p0, p1, p2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p1, p2, p0}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p1, p2, p0}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p2, p0, p1}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p2, p0, p1}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p2, p1, p0}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p2, p1, p0}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p0, p2, p1}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p0, p2, p1}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p1, p0, p2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p1, p0, p2}, 0);
// // vertex on triangle // // vertex on triangle
// double lambda = r.get_double(0, 1); // double lambda = r.get_double(0, 1);
// double mu = r.get_double(0, 1 - lambda); // double mu = r.get_double(0, 1 - lambda);
// const P bp = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu); // const P bp = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
// check_squared_distance(T{p0, p1, p2}, T{bp, p3, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp, p3, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p3, bp, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p3, bp, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p3, p4, bp}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p3, p4, bp}, 0);
// // edge on triangle // // edge on triangle
// lambda = r.get_double(0, 1); // lambda = r.get_double(0, 1);
// mu = r.get_double(0, 1 - lambda); // mu = r.get_double(0, 1 - lambda);
// P bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu); // P bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
// check_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0);
// // part of the edge crossing the triangle // // part of the edge crossing the triangle
// lambda = r.get_double(-1, 1); // lambda = r.get_double(-1, 1);
// mu = r.get_double(-1, 1); // mu = r.get_double(-1, 1);
// bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu); // bp2 = CGAL::barycenter(p0, lambda, p1, mu, p2, 1 - lambda - mu);
// check_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp, bp2, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp2, bp, p4}, 0);
// check_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp, p4, bp2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{bp2, p4, bp}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp, bp2}, 0);
// check_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0); // check_compare_squared_distance(T{p0, p1, p2}, T{p4, bp2, bp}, 0);
// // generic triangles // // generic triangles
// T tr1{p0, p1, p2}, tr2{p3, p4, p5}; // T tr1{p0, p1, p2}, tr2{p3, p4, p5};
@ -652,7 +674,7 @@ public:
P_Pl(); P_Pl();
// P_Tet(); // P_Tet();
// S_S(); S_S();
// S_R(); // S_R();
// S_L(); // S_L();
// S_Pl(); // S_Pl();
@ -662,11 +684,11 @@ public:
// R_Pl(); // R_Pl();
L_L(); L_L();
// L_Pl(); L_Pl();
// T_T(); // T_T();
// Pl_Pl(); Pl_Pl();
} }
}; };
@ -685,7 +707,7 @@ int main()
// Test<CGAL::Simple_homogeneous<double> >(r, 1e-5).run(); // Test<CGAL::Simple_homogeneous<double> >(r, 1e-5).run();
// Test<CGAL::Simple_cartesian<CGAL::Interval_nt<true> > >(r, 1e-5).run(); // Test<CGAL::Simple_cartesian<CGAL::Interval_nt<true> > >(r, 1e-5).run();
Test<CGAL::Homogeneous<CGAL::Exact_integer> >(r, 0).run(); // Test<CGAL::Homogeneous<CGAL::Exact_integer> >(r, 0).run();
const double epick_eps = 10 * std::numeric_limits<double>::epsilon(); const double epick_eps = 10 * std::numeric_limits<double>::epsilon();
Test<CGAL::Exact_predicates_inexact_constructions_kernel>(r, epick_eps).run(); Test<CGAL::Exact_predicates_inexact_constructions_kernel>(r, epick_eps).run();

View File

@ -945,8 +945,10 @@ namespace CommonKernelFunctors {
Needs_FT<result_type> Needs_FT<result_type>
operator()(const T1& p, const T2& q, const T3& r, const T4& s) const operator()(const T1& p, const T2& q, const T3& r, const T4& s) const
{ {
return CGAL::compare(internal::squared_distance(p, q, K()), // return internal::compare_squared_distance(p, q, K(), internal::squared_distance(p, q, K()));
internal::squared_distance(r, s, K())); return internal::compare_squared_distance(p, q, K(), internal::squared_distance(r, s, K()));
// return CGAL::compare(internal::squared_distance(p, q, K()),
// internal::squared_distance(r, s, K()));
} }
}; };

View File

@ -412,16 +412,6 @@ compare_slope(const Point_3<K> &p,
return internal::compare_slope(p, q, r, s, K()); return internal::compare_slope(p, q, r, s, K());
} }
template < class K >
inline
typename K::Comparison_result
compare_squared_distance(const Point_3<K> &p,
const Point_3<K> &q,
const typename K::FT &d2)
{
return internal::compare_squared_distance(p, q, d2, K());
}
template < class K > template < class K >
inline inline
typename K::Comparison_result typename K::Comparison_result