mirror of https://github.com/CGAL/cgal
121 lines
3.9 KiB
C++
121 lines
3.9 KiB
C++
// ======================================================================
|
|
//
|
|
// Copyright (c) 2002 The CGAL Consortium
|
|
//
|
|
// This software and related documentation is part of an INTERNAL release
|
|
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
|
// intended for general use.
|
|
//
|
|
// ----------------------------------------------------------------------
|
|
//
|
|
// release : $CGAL_Revision: CGAL-2.5-I-99 $
|
|
// release_date : $CGAL_Date: 2003/05/23 $
|
|
//
|
|
// file : include/CGAL/Euclidean_distance_sphere_point.h
|
|
// package : ASPAS (3.12)
|
|
// maintainer : Hans Tangelder <hanst@cs.uu.nl>
|
|
// revision : 2.4
|
|
// revision_date : 2002/16/08
|
|
// authors : Hans Tangelder (<hanst@cs.uu.nl>)
|
|
// coordinator : Utrecht University
|
|
//
|
|
// ======================================================================
|
|
|
|
|
|
|
|
#ifndef CGAL_EUCLIDEAN_DISTANCE_SPHERE_POINT_H
|
|
#define CGAL_EUCLIDEAN_DISTANCE_SPHERE_POINT_H
|
|
#include <CGAL/Kd_tree_rectangle.h>
|
|
|
|
namespace CGAL {
|
|
|
|
template <class SearchTraits>
|
|
class Euclidean_distance_sphere_point {
|
|
|
|
public:
|
|
|
|
typedef typename SearchTraits::Point_d Point_d;
|
|
typedef typename SearchTraits::Sphere_d Sphere_d;
|
|
typedef typename SearchTraits::FT FT;
|
|
typedef typename SearchTraits::Construct_center_d Construct_center_d;
|
|
typedef typename SearchTraits::Construct_squared_radius_d Construct_squared_radius_d
|
|
typedef typename SearchTraits::Construct_cartesian_const_iterator_d Construct_cartesian_const_iterator_d;
|
|
typedef typename SearchTraits::Cartesian_const_iterator_d Cartesian_const_iterator_d;
|
|
typedef Sphere_d Query_item;
|
|
public:
|
|
|
|
// default constructor
|
|
Euclidean_distance_sphere_point() {}
|
|
|
|
|
|
inline FT transformed_distance(const Sphere_d& q, const Point_d& p) const {
|
|
Point_d c= Construct_center_d()(q);
|
|
FT distance = FT(0);
|
|
Construct_cartesian_const_iterator_d construct_it;
|
|
Cartesian_const_iterator_d cit = construct_it(c),
|
|
ce = construct_it(c,1), pit = construct_it(p);
|
|
for(; cit != ce; cit++, pit++){
|
|
distance += ((*cit)-(*pit))*((*cit)-(*pit));
|
|
}
|
|
distance += - Construct_squared_radius_d()(q);
|
|
if (distance<0) distance=FT(0);
|
|
return distance;
|
|
}
|
|
|
|
|
|
inline FT min_distance_to_rectangle(const Sphere_d& q,
|
|
const Kd_tree_rectangle<SearchTraits>& r) const {
|
|
Point_d c= Construct_center_d(q);
|
|
FT distance = FT(0);
|
|
Construct_cartesian_const_iterator_d construct_it;
|
|
Cartesian_const_iterator_d cit = construct_it(c),
|
|
ce = construct_it(c,1);
|
|
for (unsigned int i = 0; cit != ce; ++i, ++cit) {
|
|
if ((*cit) < r.min_coord(i))
|
|
distance +=
|
|
(r.min_coord(i)-(*cit))*(r.min_coord(i)-(*cit));
|
|
else if ((*cit) > r.max_coord(i))
|
|
distance +=
|
|
((*cit)-r.max_coord(i))*((*cit)-r.max_coord(i));
|
|
|
|
};
|
|
distance += - Construct_squared_radius_d()(q);
|
|
if (distance<0) distance=FT(0);
|
|
return distance;
|
|
}
|
|
|
|
inline FT max_distance_to_rectangle(const Sphere_d& q,
|
|
const Kd_tree_rectangle<SearchTraits>& r) const {
|
|
Construct_center_d construct_center_d;
|
|
Point_d c = construct_center_d(q);
|
|
FT distance=FT(0);
|
|
Construct_cartesian_const_iterator_d construct_it;
|
|
Cartesian_const_iterator_d cit = construct_it(c),
|
|
ce = construct_it(c,1);
|
|
for (unsigned int i = 0; cit != ce; ++i, ++cit) {
|
|
if ((*cit) <= (r.min_coord(i)+r.max_coord(i))/FT(2.0))
|
|
distance += (r.max_coord(i)-(*cit))*(r.max_coord(i)-(*cit));
|
|
else
|
|
distance += ((*cit)-r.min_coord(i))*((*cit)-r.min_coord(i));
|
|
};
|
|
distance += - Construct_squared_radius()(q);
|
|
if (distance<0) distance=FT(0);
|
|
return distance;
|
|
}
|
|
|
|
|
|
|
|
inline FT transformed_distance(FT d) const {
|
|
return d*d;
|
|
}
|
|
|
|
inline FT inverse_of_transformed_distance(FT d) const {
|
|
return CGAL::sqrt(d);
|
|
}
|
|
|
|
}; // class Euclidean_distance_sphere_point
|
|
|
|
} // namespace CGAL
|
|
#endif // EUCLIDEAN_DISTANCE_SPHERE_POINT_H
|
|
|