diff --git a/Apollonius_graph_2/include/CGAL/new_traits/Apollonius_graph_new_traits_2.h b/Apollonius_graph_2/include/CGAL/new_traits/Apollonius_graph_new_traits_2.h index 1e1e0b829f2..aeda70e46ed 100644 --- a/Apollonius_graph_2/include/CGAL/new_traits/Apollonius_graph_new_traits_2.h +++ b/Apollonius_graph_2/include/CGAL/new_traits/Apollonius_graph_new_traits_2.h @@ -41,6 +41,60 @@ CGAL_BEGIN_NAMESPACE // return static_cast (static_cast (s1) * static_cast (s2)); // } + +template +class AG2_Orientation_test_new_2 : public AG2_Orientation_test_2 +{ +public: + typedef K Kernel; + typedef typename K::FT FT; + typedef typename K::Site_2 Site_2; + typedef typename K::Point_2 Point_2; + + typedef Orientation result_type; + typedef Arity_tag<3> Arity; + typedef Site_2 argument_type; + + Orientation operator() (const Site_2 &s0, const Site_2 &s1, const Site_2 &s2, + const Point_2 &q) const + { + FT x1 = s1.x() - s0.x(), y1 = s1.y() - s0.y(), w1 = s1.weight() - s0.weight(); + FT x2 = s2.x() - s0.x(), y2 = s2.y() - s0.y(), w2 = s2.weight() - s0.weight(); + FT xq = q.x() - s0.x(), yq = q.y() - s0.y(); + + FT a1 = x1 * x1 + y1 * y1 - w1 * w1; + FT a2 = x2 * x2 + y2 * y2 - w2 * w2; + + CGAL_assertion (sign (a1) > 0); + CGAL_assertion (sign (a2) > 0); + + FT x = a1 * x2 - a2 * x1; + FT y = a1 * y2 - a2 * y1; + FT w = a1 * w2 - a2 * w1; + FT s = x * xq + y * yq; + + Sign W = CGAL::sign (w); + Sign S = CGAL::sign (s); + + if (W == 0) return Sign (- S); + + FT o = x * yq - y * xq; + + Sign O = CGAL::sign (o); + + if (S == 0) return Sign (O * W); + + if (W * S * O <= 0) return Sign (- S); + + FT i = w * w * (xq * xq + yq * yq) - s * s; + + Sign I = CGAL::sign (i); + + return Sign (S * I); + } + +}; + //----------------------------------------------------------------------- // Conflict Base //----------------------------------------------------------------------- @@ -676,7 +730,7 @@ public: typedef CGAL::Ag2_compare_x_2 Compare_x_2; typedef CGAL::Ag2_compare_y_2 Compare_y_2; typedef CGAL::Ag2_compare_weight_2 Compare_weight_2; - typedef CGAL::AG2_Orientation_test_2 Orientation_2; + typedef CGAL::AG2_Orientation_test_new_2 Orientation_2; typedef CGAL::Is_hidden_2 Is_hidden_2; typedef CGAL::Oriented_side_of_bisector_2 /* */ Oriented_side_of_bisector_2; diff --git a/Apollonius_graph_2/test/Apollonius_graph_2/test_ag_new_traits_2.cpp b/Apollonius_graph_2/test/Apollonius_graph_2/test_ag_new_traits_2.cpp index 7c603057585..1277e1bbd9f 100644 --- a/Apollonius_graph_2/test/Apollonius_graph_2/test_ag_new_traits_2.cpp +++ b/Apollonius_graph_2/test/Apollonius_graph_2/test_ag_new_traits_2.cpp @@ -126,6 +126,35 @@ typedef Check_traits GT; typedef CGAL::Apollonius_graph_2 AG; typedef AG::Site_2 Site; +typedef AG::Finite_faces_iterator Finite_faces_iterator; +typedef AG::Finite_vertices_iterator Finite_vertices_iterator; +typedef AG::Vertex_handle Vertex_handle; + +void test_orientation (const AG &ag, + Vertex_handle v0, Vertex_handle v1, Vertex_handle v2) +{ + const Site &s0 = v0->site(); + const Site &s1 = v1->site(); + const Site &s2 = v2->site(); + + GT gt; + GT_new gt_new; + + GT::Orientation_2 orientation1 = gt.orientation_2_object(); + GT_new::Orientation_2 orientation2 = gt_new.orientation_2_object(); + + for (Finite_vertices_iterator _v = ag.finite_vertices_begin(); + _v != ag.finite_vertices_end(); ++_v) + { + Vertex_handle v = _v; + if (v == v0) continue; + + Sign o1 = orientation1 (s0, s1, s2, s0, v->site()); + Sign o2 = orientation2 (s0, s1, s2, v->site().point()); + + assert (o1 == o2); + } +} void test_file (const char *filename) { @@ -142,6 +171,17 @@ void test_file (const char *filename) std::cout << "OK" << std::endl; + std::cout << "Test orientation... " << std::flush; + + for (Finite_faces_iterator f = ag.finite_faces_begin(); + f != ag.finite_faces_end(); ++f) + { + test_orientation (ag, f->vertex(0), f->vertex(1), f->vertex(2)); + test_orientation (ag, f->vertex(1), f->vertex(2), f->vertex(0)); + test_orientation (ag, f->vertex(2), f->vertex(0), f->vertex(1)); + } + + std::cout << "OK" << std::endl; } int main (void)