handle case when the x coordinate of the normal vector at the minimal vertex is 0

This commit is contained in:
Sébastien Loriot 2015-01-27 14:13:17 +01:00
parent 4cf96051c5
commit 7ab1037f6b
1 changed files with 26 additions and 15 deletions

View File

@ -26,16 +26,21 @@
#include <CGAL/internal/Operations_on_polyhedra/compute_normal.h>
namespace CGAL{
namespace internal{
template <class Less_xyz>
struct Compare_vertex_points_xyz_3{
Less_xyz less;
template<unsigned int axis>
struct Axis_compare {
typedef bool result_type;
template <class Vertex>
bool operator()(const Vertex& v0, const Vertex& v1) const
{ return v0.point()[axis] < v1.point()[axis]; }
};
bool operator()(const Vertex& v1, const Vertex& v2) const
{
return less(v1.point(), v2.point());
}
} // namespace internal
};
} // end of namespace internal
/**
* Tests whether a closed polyhedron has a positive orientation.
@ -60,17 +65,23 @@ struct Axis_compare {
* @endcode
*/
template<class Polyhedron>
bool is_oriented(const Polyhedron& polyhedron) {
const unsigned int axis = 0;
bool is_oriented(const Polyhedron& polyhedron)
{
typedef typename Polyhedron::Traits K;
internal::Compare_vertex_points_xyz_3< typename K::Less_xyz_3 > less_xyz;
typename Polyhedron::Vertex_const_iterator v_min
= std::min_element(polyhedron.vertices_begin(), polyhedron.vertices_end(), internal::Axis_compare<axis>());
= std::min_element(polyhedron.vertices_begin(), polyhedron.vertices_end(), less_xyz);
typedef typename Polyhedron::Traits K;
const typename K::Vector_3& normal_v_min = compute_vertex_normal<typename Polyhedron::Vertex, K>(*v_min);
CGAL_warning(normal_v_min[axis] != 0);
return normal_v_min[axis] < 0;
return normal_v_min[0] < 0 || (
normal_v_min[0] == 0 && (
normal_v_min[1] < 0 ||
( normal_v_min[1]==0 && normal_v_min[2] < 0 )
)
);
}
} // namespace CGAL
#endif // CGAL_ORIENT_POLYHEDRON_3