Skip to content

Commit 877dba1

Browse files
committed
simplify check
1 parent c3694ea commit 877dba1

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

Convex_hull_3/include/CGAL/Convex_hull_3/dual/halfspace_intersection_3.h

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -150,37 +150,23 @@ namespace CGAL
150150
}
151151
};
152152

153-
// Functor used during the computation of the equations
154-
// of the facets of a convex polyhedron
155-
template <class Facet>
156-
struct Plane_equation_convex_polyhedron {
157-
typename Facet::Plane_3 operator()(Facet& f) {
158-
typename Facet::Halfedge_handle h = f.halfedge();
159-
typedef typename Facet::Plane_3 Plane;
160-
return Plane(h->vertex()->point(),
161-
h->next()->vertex()->point(),
162-
h->next()->next()->vertex()->point());
163-
}
164-
};
165-
166153
// Test if a point is inside a convex polyhedron
167154
template <class Polyhedron>
168-
bool point_inside_convex_polyhedron (Polyhedron &P,
155+
bool point_inside_convex_polyhedron (const Polyhedron &P,
169156
typename Polyhedron::Traits::Point_3 const& p) {
170157
// Compute the equations of the facets of the polyhedron
171-
typedef typename Polyhedron::Plane_iterator Plane_iterator;
172158
typedef typename Polyhedron::Facet Facet;
173-
174-
std::transform(P.facets_begin(), P.facets_end(), P.planes_begin(),
175-
Plane_equation_convex_polyhedron<Facet>());
176-
177-
// Check if the point is inside the polyhdreon
178-
for (Plane_iterator pit = P.planes_begin();
179-
pit != P.planes_end();
180-
++pit) {
181-
if (! pit->has_on_negative_side(p)) {
182-
return false;
183-
}
159+
typedef typename Polyhedron::Facet_const_iterator Facet_iterator;
160+
for(Facet_iterator fit=P.facets_begin(), fit_end=P.facets_end();
161+
fit!=fit_end; ++fit)
162+
{
163+
typename Polyhedron::Halfedge_const_handle h = fit->halfedge();
164+
typedef typename Facet::Plane_3 Plane;
165+
Plane plane(h->vertex()->point(),
166+
h->next()->vertex()->point(),
167+
h->next()->next()->vertex()->point());
168+
if( !plane.has_on_negative_side(p) )
169+
return false;
184170
}
185171

186172
return true;
@@ -283,8 +269,7 @@ namespace CGAL
283269
P.delegate(build_primal);
284270

285271
// Posterior check if the origin is inside the computed polyhedron
286-
Polyhedron Q(P);
287-
CGAL_assertion_msg(!Convex_hull_3::internal::point_inside_convex_polyhedron(Q, p_origin), "halfspace_intersection_3: origin not in the polyhedron");
272+
CGAL_assertion_msg(!Convex_hull_3::internal::point_inside_convex_polyhedron(P, p_origin), "halfspace_intersection_3: origin not in the polyhedron");
288273
} else {
289274
// choose exact integral type
290275
#ifdef CGAL_USE_GMP
@@ -306,8 +291,7 @@ namespace CGAL
306291
P.delegate(build_primal);
307292

308293
// Posterior check if the origin is inside the computed polyhedron
309-
Polyhedron Q(P);
310-
CGAL_assertion_msg(!Convex_hull_3::internal::point_inside_convex_polyhedron(Q, origin), "halfspace_intersection_3: origin not in the polyhedron");
294+
CGAL_assertion_msg(!Convex_hull_3::internal::point_inside_convex_polyhedron(P, origin), "halfspace_intersection_3: origin not in the polyhedron");
311295
}
312296
}
313297

0 commit comments

Comments
 (0)