diff --git a/Alpha_shapes_2/doc/Alpha_shapes_2/CGAL/Alpha_shape_2.h b/Alpha_shapes_2/doc/Alpha_shapes_2/CGAL/Alpha_shape_2.h index cf655264ac4..60ff817f059 100644 --- a/Alpha_shapes_2/doc/Alpha_shapes_2/CGAL/Alpha_shape_2.h +++ b/Alpha_shapes_2/doc/Alpha_shapes_2/CGAL/Alpha_shape_2.h @@ -108,6 +108,10 @@ resorting to exact arithmetic). Access to the interval containing the exact valu with `Protected=true`. Access to the exact value is provided through the function `FT::Exact_nt exact() const` where `FT::Exact_nt` depends on the configuration of %CGAL (it is `Gmpq` if `gmp` is available and `Quotient` otherwise). +An overload for the function `double to_double(FT)` is also available. Its +precision is controlled through `FT::set_relative_precision_of_to_double()` in +exactly the same way as with `Lazy_exact_nt`, so a call to `to_double` may +trigger an exact evaluation. It must be noted that an object of type `FT` is valid as long as the alpha shapes class that creates it is valid and has not been modified. For convenience, classical comparison operators are provided for the type `FT`. diff --git a/Alpha_shapes_2/include/CGAL/internal/Lazy_alpha_nt_2.h b/Alpha_shapes_2/include/CGAL/internal/Lazy_alpha_nt_2.h index 83eeac727d5..eb2aabbf0d6 100644 --- a/Alpha_shapes_2/include/CGAL/internal/Lazy_alpha_nt_2.h +++ b/Alpha_shapes_2/include/CGAL/internal/Lazy_alpha_nt_2.h @@ -186,7 +186,25 @@ class Lazy_alpha_nt_2 const Data_vector& data() const{ return input_points;} Data_vector& data(){ return input_points;} + static double & relative_precision_of_to_double_internal() + { + CGAL_STATIC_THREAD_LOCAL_VARIABLE(double, relative_precision_of_to_double, 0.00001); + return relative_precision_of_to_double; + } + public: + + static const double & get_relative_precision_of_to_double() + { + return relative_precision_of_to_double_internal(); + } + + static void set_relative_precision_of_to_double(double d) + { + CGAL_assertion((0 < d) & (d < 1)); + relative_precision_of_to_double_internal() = d; + } + typedef NT_exact Exact_nt; typedef NT_approx Approximate_nt; @@ -449,7 +467,17 @@ struct Alpha_nt_selector_2 template double to_double(const internal::Lazy_alpha_nt_2& a) { - return to_double(a.approx()); + double r; + if (fit_in_double(a.approx(), r)) + return r; + + // If it isn't precise enough, + // we trigger the exact computation first, + // which will refine the approximation. + if (!has_smaller_relative_precision(a.approx(), a.get_relative_precision_of_to_double())) + a.exact(); + + return CGAL_NTS to_double(a.approx()); } } // namespace CGAL