diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 878d361e3ef..b6d77833d0a 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -3200,6 +3200,7 @@ namespace HomogeneousKernelFunctors { template class Construct_weighted_point_2 { + typedef typename K::RT RT; typedef typename K::FT FT; typedef typename K::Point_2 Point_2; typedef typename K::Weighted_point_2 Weighted_point_2; diff --git a/Kernel_23/include/CGAL/Point_2.h b/Kernel_23/include/CGAL/Point_2.h index 42416f855e6..f86a1983c85 100644 --- a/Kernel_23/include/CGAL/Point_2.h +++ b/Kernel_23/include/CGAL/Point_2.h @@ -78,9 +78,11 @@ public: : RPoint_2(p) {} +#if 0 Point_2(const Weighted_point_2& wp) : Rep(wp.point()) {} +#endif template < typename T1, typename T2 > Point_2(const T1 &x, const T2 &y) diff --git a/Kernel_23/include/CGAL/Weighted_point_2.h b/Kernel_23/include/CGAL/Weighted_point_2.h index 48e86c362c2..43ea203c04a 100644 --- a/Kernel_23/include/CGAL/Weighted_point_2.h +++ b/Kernel_23/include/CGAL/Weighted_point_2.h @@ -76,7 +76,7 @@ public: Weighted_point_2(const Rep& p) : Rep(p) {} - Weighted_point_2(const Point_2& p) + explicit Weighted_point_2(const Point_2& p) : Rep(typename R::Construct_weighted_point_2()(Return_base_tag(), p, 0)) {} diff --git a/Triangulation_2/include/CGAL/Regular_traits_adaptor_2.h b/Triangulation_2/include/CGAL/Regular_traits_adaptor_2.h new file mode 100644 index 00000000000..6d7476b10a5 --- /dev/null +++ b/Triangulation_2/include/CGAL/Regular_traits_adaptor_2.h @@ -0,0 +1,213 @@ +// Copyright (c) 1999-2004,2006-2009,2014-2015 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Monique Teillaud +// Sylvain Pion +// Andreas Fabri +// Nico Kruithof +// Manuel Caroli +// Aymeric Pellé +#ifndef CGAL_REGULAR_TRAITS_ADAPTOR_2_H +#define CGAL_REGULAR_TRAITS_ADAPTOR_2_H + +#include + +#include +#include +#include + +namespace CGAL { + + template < class RTT, class ConstructPoint, class Functor_> +class Regular_traits_adaptor_2 +{ + const ConstructPoint& cp; + const Functor_& f; + + typedef RTT RTraits; + typedef Functor_ Functor; + + typedef typename RTraits::FT FT; +#if 0 + typedef typename boost::mpl::eval_if_c< + internal::Has_nested_type_Bare_point::value, + typename internal::Bare_point_type, + boost::mpl::identity + >::type Point_2; +#else + typedef typename RTT::Point_2 Point_2; +#endif + typedef typename RTraits::Triangle_2 Triangle_2; + typedef typename RTraits::Segment_2 Segment_2; + typedef typename RTraits::Circle_2 Circle_2; + typedef typename RTraits::Weighted_point_2 Weighted_point_2; + + template + struct Conv_wp_to_p { + typedef T type; + }; + + template <> + struct Conv_wp_to_p { + typedef Point_2 type; + }; + + template <> + struct Conv_wp_to_p { + typedef const Point_2 type; + }; + + template <> + struct Conv_wp_to_p { + typedef const Point_2& type; + }; + + template struct result {}; + + template struct result { + typedef typename Conv_wp_to_p::type A0p; + typedef typename cpp11::result_of::type type; + }; + + template struct result { + typedef typename Conv_wp_to_p::type A0p; + typedef typename Conv_wp_to_p::type A1p; + typedef typename cpp11::result_of::type type; + }; + + template struct result { + typedef typename Conv_wp_to_p::type A0p; + typedef typename Conv_wp_to_p::type A1p; + typedef typename Conv_wp_to_p::type A2p; + typedef typename cpp11::result_of::type type; + }; + + template + struct result { + typedef typename Conv_wp_to_p::type A0p; + typedef typename Conv_wp_to_p::type A1p; + typedef typename Conv_wp_to_p::type A2p; + typedef typename Conv_wp_to_p::type A3p; + typedef typename cpp11::result_of::type type; + }; + +public: + Regular_traits_adaptor_2 (const ConstructPoint& cp, const Functor& f) + : cp(cp), f(f) + { } + + + + typename cpp11::result_of::type operator() (const Triangle_2& t) const + { + return f(t); + } + + typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Point_2& p0, const Point_2& p1) const + { + return f(p0, p1); + } + + typename cpp11::result_of< Functor(Point_2,Point_2, Point_2) >::type operator() (const Point_2& p0, const Point_2& p1, const Point_2& p2) const + { + return f(p0, p1, p2); + } + + typename cpp11::result_of< Functor(Point_2,Point_2, Point_2,Point_2) >::type operator() (const Point_2& p0, const Point_2& p1, const Point_2& p2, const Point_2& p3) const + { + return f(p0, p1, p2, p3); + } + + typename cpp11::result_of< Functor(Point_2,Origin) >::type operator() (const Point_2& p0, const Origin& o) const + { + return f(p0, o); + } + + typename cpp11::result_of< Functor(Point_2,Origin) >::type operator() (const Origin& o, const Point_2& p0) const + { + return f(o, p0); + } + + typename cpp11::result_of< Functor(Segment_2,Point_2) >::type operator() (const Segment_2& pl, const Point_2& p) const + { + return f(pl, p); + } + + typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1) const + { + return f(cp(p0), cp(p1)); + } + + typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Point_2& p0, const Weighted_point_2& p1) const + { + return f(p0, cp(p1)); + } + + typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Weighted_point_2& p0, const Point_2& p1) const + { + return f(cp(p0), p1); + } + + typename cpp11::result_of::type operator() (const Segment_2& p0, const Weighted_point_2& p1) const + { + return f(p0, cp(p1)); + } + + + typename cpp11::result_of::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1, + const Weighted_point_2& p2) const + { + return f(cp(p0), cp(p1), cp(p2)); + } + + typename cpp11::result_of::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1, + const Weighted_point_2& p2, const Weighted_point_2& p3) const + { + return f(cp(p0), cp(p1), cp(p2), cp(p3)); + } + + typename cpp11::result_of::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1, + const Point_2& p2) const + { + return f(cp(p0), cp(p1), p2); + } + + typename cpp11::result_of::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1, + const Weighted_point_2& p2, const Point_2& p3) const + { + return f(cp(p0), cp(p1), cp(p2), p3); + } + + typename cpp11::result_of::type operator() (const Point_2& p0, const Weighted_point_2& p1, + const Weighted_point_2& p2) const + { + return f(p0, cp(p1), cp(p2)); + } + + typename cpp11::result_of::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1, + const Weighted_point_2& p2, const Weighted_point_2& p3, + const FT w) const + { + return f(cp(p0), cp(p1), cp(p2), cp(p3), w); + } + +}; + +} // namespace CGAL + +#endif /* CGAL_REGULAR_TRAITS_ADAPTOR_2_H */ diff --git a/Triangulation_2/include/CGAL/Regular_triangulation_2.h b/Triangulation_2/include/CGAL/Regular_triangulation_2.h index 4d787364e0c..8d312a24043 100644 --- a/Triangulation_2/include/CGAL/Regular_triangulation_2.h +++ b/Triangulation_2/include/CGAL/Regular_triangulation_2.h @@ -57,22 +57,140 @@ struct Weighted_point_mapper_2 Weighted_point_mapper_2(const K_& k) : K_(k) {} }; + namespace internal { +template < typename K_ > +struct RegTraits_2 + : public K_ +{ + typedef typename K_::Construct_point_2 Construct_point_2_base; + typedef typename K_::Construct_segment_2 Construct_segment_2_base; + typedef typename K_::Construct_triangle_2 Construct_triangle_2_base; + typedef typename K_::Construct_vector_2 Construct_vector_2_base; + typedef typename K_::Equal_2 Equal_2_base; + typedef typename K_::Compare_x_2 Compare_x_2_base; + typedef typename K_::Compare_y_2 Compare_y_2_base; + typedef typename K_::Orientation_2 Orientation_2_base; + typedef typename K_::Construct_circumcenter_2 Construct_circumcenter_2_base; + typedef typename K_::Less_x_2 Less_x_2_base; + typedef typename K_::Less_y_2 Less_y_2_base; + + + Construct_point_2_base cp; + + RegTraits_2() {} + RegTraits_2(const K_& k) + : K_(k), cp(k.construct_point_2_object()) + {} + + typedef Regular_traits_adaptor_2 Equal_2; + + typedef Regular_traits_adaptor_2 Construct_vector_2; + + typedef Regular_traits_adaptor_2 Compare_x_2; + + typedef Regular_traits_adaptor_2 Compare_y_2; + + typedef Regular_traits_adaptor_2 Orientation_2; + + typedef Regular_traits_adaptor_2 Construct_circumcenter_2; + + typedef Regular_traits_adaptor_2 Construct_triangle_2; + + typedef Regular_traits_adaptor_2 Construct_segment_2; + + typedef Regular_traits_adaptor_2 Less_x_2; + + typedef Regular_traits_adaptor_2 Less_y_2; + + Construct_vector_2 construct_vector_2_object() const + { + return Construct_vector_2(cp, static_cast(*this).construct_vector_2_object()); + } + + Construct_triangle_2 construct_triangle_2_object() const + { + return Construct_triangle_2(cp, static_cast(*this).construct_triangle_2_object()); + } + + Construct_segment_2 construct_segment_2_object() const + { + return Construct_segment_2(cp, static_cast(*this).construct_segment_2_object()); + } + + Equal_2 equal_2_object() const + { + return Equal_2(cp, static_cast(*this).equal_2_object()); + } + + Compare_x_2 compare_x_2_object() const + { + return Compare_x_2(cp, static_cast(*this).compare_x_2_object()); + } + + Compare_y_2 compare_y_2_object() const + { + return Compare_y_2(cp, static_cast(*this).compare_y_2_object()); + } + + Orientation_2 orientation_2_object() const + { + return Orientation_2(cp, static_cast(*this).orientation_2_object()); + } + + Construct_circumcenter_2 construct_circumcenter_2_object() const + { + return Construct_circumcenter_2(cp, static_cast(*this).construct_circumcenter_2_object()); + } + + Less_x_2 less_x_2_object() const + { + return Less_x_2(cp, static_cast(*this).less_x_2_object()); + } + + Less_y_2 less_y_2_object() const + { + return Less_y_2(cp, static_cast(*this).less_y_2_object()); + } +}; + + } // namespace internal + template < class Gt, class Tds = Triangulation_data_structure_2 < Regular_triangulation_vertex_base_2, Regular_triangulation_face_base_2 > > class Regular_triangulation_2 : public Triangulation_2< - Weighted_point_mapper_2, + Weighted_point_mapper_2 >, Tds> { - typedef Regular_triangulation_2 Self; - typedef Weighted_point_mapper_2 RT_traits; - typedef Triangulation_2 Base; + typedef Regular_triangulation_2 Self; + typedef Weighted_point_mapper_2 > RT_traits; + typedef Triangulation_2 Base; public: typedef Self Triangulation; typedef Tds Triangulation_data_structure; - typedef Gt Geom_traits; + typedef internal::RegTraits_2 Geom_traits; typedef typename boost::mpl::eval_if_c< internal::Has_nested_type_Bare_point::value, typename internal::Bare_point_type, @@ -80,7 +198,7 @@ public: >::type Bare_point; typedef typename Gt::Weighted_point_2 Weighted_point; typedef typename Gt::FT Weight; - + typedef typename Gt::Construct_weighted_point_2 Construct_weighted_point_2; typedef typename Base::size_type size_type; typedef typename Base::Face_handle Face_handle; typedef typename Base::Vertex_handle Vertex_handle; @@ -120,6 +238,7 @@ public: using Base::OUTSIDE_CONVEX_HULL; using Base::orientation; using Base::locate; + using Base::inexact_locate; using Base::incident_faces; using Base::is_infinite; using Base::degree; @@ -129,6 +248,7 @@ public: using Base::mirror_index; using Base::show_vertex; using Base::test_dim_down; + using Base::oriented_side; #endif private: @@ -243,6 +363,46 @@ public: return _hidden_vertices; } + // Overloads for Bare_point + + Face_handle + inexact_locate(const Bare_point& bp, + Face_handle start = Face_handle()) const + { + return Base::inexact_locate(geom_traits().construct_weighted_point_2_object()(bp), start); + } + + Face_handle + locate(const Bare_point& bp, + Locate_type& lt, + int& li, + Face_handle start = Face_handle()) const + { + return Base::locate(geom_traits().construct_weighted_point_2_object()(bp), lt, li, start); + } + + Face_handle + locate(const Bare_point& bp) + { + return Base::locate(geom_traits().construct_weighted_point_2_object()(bp)); + } + + Line_face_circulator line_walk(const Bare_point& p, + const Bare_point& q, + Face_handle f = Face_handle()) const + { + return Base::line_walk(this->geom_traits().construct_weighted_point_2_object()(p), + this->geom_traits().construct_weighted_point_2_object()(q), + f); + } + + Oriented_side + oriented_side(Face_handle f, const Bare_point &p) const + { + return Base::oriented_side(f, geom_traits().construct_weighted_point_2_object()(p)); + } + + // CHECK - QUERY Oriented_side power_test(const Weighted_point &p, diff --git a/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h b/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h index b831b1e145b..9322a68f06c 100644 --- a/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h +++ b/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h @@ -47,7 +47,7 @@ _test_is_to_the_left( const Triangulation &T, { return( T.orientation(f->vertex(f->ccw(li))->point(), f->vertex(f->cw(li))->point(), - p) == CGAL::LEFT_TURN ); + typename Triangulation::Weighted_point(p)) == CGAL::LEFT_TURN ); } template @@ -372,16 +372,16 @@ _test_cls_regular_triangulation_2( const Triangulation & ) T1_3_2.insert(wp9); T1_3_2.is_valid(verbose); loc = T1_3_2.locate(p1,lt,li); assert( lt == Cls::VERTEX ); - assert( T1_3_2.xy_equal(loc->vertex(li)->point(), p1) ); + assert( T1_3_2.xy_equal(loc->vertex(li)->point(), wp1) ); loc = T1_3_2.locate(p2,lt,li); assert( lt == Cls::VERTEX ); - assert( T1_3_2.xy_equal(loc->vertex(li)->point(), p2) ); + assert( T1_3_2.xy_equal(loc->vertex(li)->point(), wp2) ); loc = T1_3_2.locate(p9,lt,li); assert( lt == Cls::VERTEX ); - assert( T1_3_2.xy_equal(loc->vertex(li)->point(), p9) ); + assert( T1_3_2.xy_equal(loc->vertex(li)->point(), wp9) ); loc = T1_3_2.locate(p3,lt,li); assert( lt == Cls::EDGE ); - assert( (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p1) - && T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point().point(), p2)) - || (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p2) - && T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point().point(), p1))); + assert( (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point(), wp1) + && T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point(), wp2)) + || (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point(), wp2) + && T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point(), wp1))); loc = T1_3_2.locate(p8,lt,li); assert( lt == Cls::OUTSIDE_CONVEX_HULL ); loc = T1_3_2.locate(p7,lt,li); assert( lt == Cls::OUTSIDE_AFFINE_HULL ); loc = T1_3_2.locate(p5,lt,li); assert( lt == Cls::OUTSIDE_AFFINE_HULL ); @@ -392,32 +392,32 @@ _test_cls_regular_triangulation_2( const Triangulation & ) // Check point location in 2-dimensional triangulations std::cout << " point locations 2-dim" << std::endl; loc = T2_3.locate(p0,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p0) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp0) ); loc = T2_3.locate(p1,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p1) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp1) ); loc = T2_3.locate(p2,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p2) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp2) ); loc = T2_3.locate(p4,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p4) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp4) ); loc = T2_3.locate(p5,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p5) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp5) ); loc = T2_3.locate(p6,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p6) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp6) ); loc = T2_3.locate(p7,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p7) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp7) ); loc = T2_3.locate(p8,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p8) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp8) ); loc = T2_3.locate(p10,lt,li); assert( lt == Cls::VERTEX ); - assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p10) ); + assert( T2_3.xy_equal(loc->vertex(li)->point(), wp10) ); loc = T2_3.locate(p3,lt,li); assert( lt == Cls::EDGE ); loc = T2_3.locate(p9,lt,li); assert( lt == Cls::EDGE ); loc = T2_3.locate(p11,lt,li); assert( lt == Cls::EDGE); - assert( (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p1) - && T2_3.xy_equal(loc->vertex(loc->cw(li))->point().point(), p0)) - || (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p0) - && T2_3.xy_equal(loc->vertex(loc->cw(li))->point().point(), p1))); + assert( (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point(), wp1) + && T2_3.xy_equal(loc->vertex(loc->cw(li))->point(), wp0)) + || (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point(), wp0) + && T2_3.xy_equal(loc->vertex(loc->cw(li))->point(), wp1))); loc = T2_3.locate(p12,lt,li); assert( lt == Cls::FACE ); assert( T2_3.oriented_side(loc,p12) == CGAL::ON_POSITIVE_SIDE ); loc = T2_3.locate(p13,lt,li,loc); assert( lt == Cls::OUTSIDE_CONVEX_HULL ); @@ -443,7 +443,7 @@ _test_cls_regular_triangulation_2( const Triangulation & ) loc = T2_3_1.locate(p12,lt,li); assert( lt == Cls::FACE ); assert( T2_3_1.oriented_side(loc,p12) == CGAL::ON_POSITIVE_SIDE ); - assert( T2_3_1.power_test(loc,p12) == CGAL::ON_NEGATIVE_SIDE); + assert( T2_3_1.power_test(loc,wp12) == CGAL::ON_NEGATIVE_SIDE); T2_3_1.insert(wp12); //hidden in face T2_3_1.is_valid(verbose); @@ -537,10 +537,10 @@ _test_cls_regular_triangulation_2( const Triangulation & ) --fc; // testing with dummy triangulations Cls T2_8; - T2_8.insert(Bare_point(0,0,1)); - T2_8.insert(Bare_point(1,0,1)); - T2_8.insert(Bare_point(0,1,1)); - T2_8.insert(Bare_point(1,1,1)); + T2_8.insert(Weighted_point(Bare_point(0,0,1))); + T2_8.insert(Weighted_point(Bare_point(1,0,1))); + T2_8.insert(Weighted_point(Bare_point(0,1,1))); + T2_8.insert(Weighted_point(Bare_point(1,1,1))); int n=0; do {fc2++ ; n = n+1;} while (fc2 != fc); assert(T2_8.number_of_vertices()>=2); @@ -553,10 +553,10 @@ _test_cls_regular_triangulation_2( const Triangulation & ) assert(n==4); // the two point are vertices of the triangulation. Cls TT; - TT.insert(Bare_point(0,0)); - TT.insert(Bare_point(1,0)); - TT.insert(Bare_point(1,1)); - TT.insert(Bare_point(0,1)); + TT.insert(Weighted_point(Bare_point(0,0))); + TT.insert(Weighted_point(Bare_point(1,0))); + TT.insert(Weighted_point(Bare_point(1,1))); + TT.insert(Weighted_point(Bare_point(0,1))); assert(TT.dimension()==2); assert(TT.is_valid(verbose)); assert(TT.number_of_vertices()==4);