diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index f7cd19fdbb8..e7d781e0f42 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -4268,6 +4268,8 @@ namespace CartesianKernelFunctors { typedef typename K::Circle_2 Circle_2; typedef typename K::Line_2 Line_2; typedef typename K::Triangle_2 Triangle_2; + typedef typename K::Segment_2 Segment_2; + typedef typename K::FT FT; public: typedef typename K::Oriented_side result_type; @@ -4304,6 +4306,36 @@ namespace CartesianKernelFunctors { ? result_type(ON_ORIENTED_BOUNDARY) : opposite(ot); } + + result_type + operator()(const Segment_2& s, const Triangle_2& t) const + { + typename K::Construct_source_2 source; + typename K::Construct_target_2 target; + const Point_2 a = source(s); + const Point_2 b = target(s); + const FT dX = b.x() - a.x(); + const FT dY = b.y() - a.y(); + + const Point_2& p0 = t[0]; + const Point_2& p1 = t[1]; + const Point_2& p2 = t[2]; + const FT R0 = p0.x() * p0.x() + p0.y() * p0.y(); + const FT R1 = p1.x() * p1.x() + p1.y() * p1.y(); + const FT R2 = p2.x() * p2.x() + p2.y() * p2.y(); + const FT denominator = (p1.x() - p0.x()) * (p2.y() - p0.y()) + + (p0.x() - p2.x()) * (p1.y() - p0.y()); + const FT det = 2 * denominator * (a.x() * dY - a.y() * dX) + - (R2 - R1) * (p0.x() * dX + p0.y() * dY) + - (R0 - R2) * (p1.x() * dX + p1.y() * dY) + - (R1 - R0) * (p2.x() * dX + p2.y() * dY); + if (det < 0) + return CGAL::ON_NEGATIVE_SIDE; + else if (det == 0.) + return CGAL::ON_ORIENTED_BOUNDARY; + else + return CGAL::ON_POSITIVE_SIDE; + } }; template diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 8091a640d18..2f15ce3be76 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -4670,6 +4670,7 @@ namespace HomogeneousKernelFunctors { typedef typename K::Circle_2 Circle_2; typedef typename K::Line_2 Line_2; typedef typename K::Triangle_2 Triangle_2; + typedef typename K::Segment_2 Segment_2; public: typedef typename K::Oriented_side result_type; @@ -4709,6 +4710,33 @@ namespace HomogeneousKernelFunctors { ? ON_ORIENTED_BOUNDARY : -ot; } + + result_type + operator()(const Segment_2& s, const Triangle_2& t) const + { + typename K::Construct_source_2 source; + typename K::Construct_target_2 target; + typename K::Construct_circumcenter_2 circumcenter; + typename K::Orientation_2 orientation; + + const Point_2 a = source(s); + const Point_2 b = target(s); + const Point_2 cc = circumcenter(t); + + CGAL::Orientation o_abc = orientation(a, b, cc); + if (o_abc == CGAL::COLLINEAR) + return CGAL::ON_ORIENTED_BOUNDARY; + + CGAL::Orientation o_abt = orientation(a, b, t[0]); + if (o_abt == CGAL::COLLINEAR) + o_abt = orientation(a, b, t[1]); + if (o_abt == CGAL::COLLINEAR) + o_abt = orientation(a, b, t[2]); + CGAL_assertion(o_abt != CGAL::COLLINEAR); + + if (o_abc == o_abt) return CGAL::ON_POSITIVE_SIDE; + else return CGAL::ON_NEGATIVE_SIDE; + } }; diff --git a/Mesh_2/include/CGAL/Constrained_voronoi_diagram_2.h b/Mesh_2/include/CGAL/Constrained_voronoi_diagram_2.h index 13f7f528181..b03ca56d811 100644 --- a/Mesh_2/include/CGAL/Constrained_voronoi_diagram_2.h +++ b/Mesh_2/include/CGAL/Constrained_voronoi_diagram_2.h @@ -242,25 +242,9 @@ private: bool segment_hides_circumcenter(const Segment& seg, const Triangle& tr) { - Point a = seg.source(); - Point b = seg.target(); - double dX = b.x() - a.x(); - double dY = b.y() - a.y(); - - const Point& p0 = tr[0]; - const Point& p1 = tr[1]; - const Point& p2 = tr[2]; - double R0 = p0.x()*p0.x() + p0.y()*p0.y(); - double R1 = p1.x()*p1.x() + p1.y()*p1.y(); - double R2 = p2.x()*p2.x() + p2.y()*p2.y(); - double denominator = (p1.x()-p0.x())*(p2.y()-p0.y()) + - (p0.x()-p2.x())*(p1.y()-p0.y()); - - double det = 2*denominator * (a.x()*dY - a.y()*dX) - - (R2-R1) * (p0.x()*dX + p0.y()*dY) - - (R0-R2) * (p1.x()*dX + p1.y()*dY) - - (R1-R0) * (p2.x()*dX + p2.y()*dY); - return (det <= 0); + typename Geom_traits::Oriented_side_2 os + = m_cdt.geom_traits().oriented_side_2_object(); + return (os(seg, tr) != CGAL::ON_POSITIVE_SIDE); } // tags with their sights, with respect to the Edge constraint,