diff --git a/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h b/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h index 15cf91f451a..7ea9e73a8ad 100644 --- a/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h +++ b/Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h @@ -243,7 +243,7 @@ namespace CGAL template void halfspace_intersection_3 (PlaneIterator begin, PlaneIterator end, Polyhedron &P, - boost::optional const& origin = boost::none) { + boost::optional origin = boost::none) { // Checks whether the intersection is a polyhedron CGAL_assertion_msg(Convex_hull_3::internal::is_intersection_dim_3(begin, end), "halfspace_intersection_3: intersection not a polyhedron"); @@ -252,20 +252,9 @@ namespace CGAL typedef Convex_hull_3::Convex_hull_traits_dual_3 Hull_traits_dual_3; typedef Polyhedron_3 Polyhedron_dual_3; typedef Convex_hull_3::internal::Build_primal_polyhedron Builder; - typedef typename Polyhedron::Vertex::Point_3 Point_3; - if (origin) { - Point_3 p_origin = boost::get(origin); - Hull_traits_dual_3 dual_traits(p_origin); - - Polyhedron_dual_3 dual_convex_hull; - CGAL::convex_hull_3(begin, end, dual_convex_hull, dual_traits); - Builder build_primal(dual_convex_hull, p_origin); - P.delegate(build_primal); - - // Posterior check if the origin is inside the computed polyhedron - CGAL_assertion_msg(Convex_hull_3::internal::point_inside_convex_polyhedron(P, p_origin), "halfspace_intersection_3: origin not in the polyhedron"); - } else { + // if a point inside is not provided find one using linear programming + if (!origin) { // choose exact integral type #ifdef CGAL_USE_GMP typedef CGAL::Gmpq ET; @@ -278,18 +267,18 @@ namespace CGAL CGAL_assertion_code(bool interior_point_found = ) interior.find(begin, end); CGAL_assertion_msg(interior_point_found, "halfspace_intersection_3: problem when determing a point inside the intersection"); - Point_3 origin = interior.inside_point(); - - Hull_traits_dual_3 dual_traits(origin); - - Polyhedron_dual_3 dual_convex_hull; - CGAL::convex_hull_3(begin, end, dual_convex_hull, dual_traits); - Builder build_primal(dual_convex_hull, origin); - P.delegate(build_primal); - - // Posterior check if the origin is inside the computed polyhedron - CGAL_assertion_msg(Convex_hull_3::internal::point_inside_convex_polyhedron(P, origin), "halfspace_intersection_3: origin not in the polyhedron"); + origin = boost::make_optional(interior.inside_point()); } + + // compute the intersection of the half-space using the dual formulation + Hull_traits_dual_3 dual_traits(*origin); + Polyhedron_dual_3 dual_convex_hull; + CGAL::convex_hull_3(begin, end, dual_convex_hull, dual_traits); + Builder build_primal(dual_convex_hull, *origin); + P.delegate(build_primal); + + // Posterior check if the origin is inside the computed polyhedron + CGAL_assertion_msg(Convex_hull_3::internal::point_inside_convex_polyhedron(P, *origin), "halfspace_intersection_3: origin not in the polyhedron"); } #ifndef CGAL_NO_DEPRECATED_CODE