From ee4134317ecf88a7918fec151abff48aad6a3fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 12 Jan 2018 16:45:11 +0100 Subject: [PATCH] Improved tests of natural/regular coordinates (2D) backward compatible + new tests --- .../CGAL/_test_natural_neighbors_2.cpp | 314 ++++++++--- .../CGAL/_test_regular_neighbors_2.cpp | 492 ++++++++++++------ .../test_natural_neighbors_2.cpp | 4 +- .../test_regular_neighbors_2.cpp | 13 +- 4 files changed, 579 insertions(+), 244 deletions(-) diff --git a/Interpolation/test/Interpolation/include/CGAL/_test_natural_neighbors_2.cpp b/Interpolation/test/Interpolation/include/CGAL/_test_natural_neighbors_2.cpp index aa9565c51eb..fe3ef8e16ae 100644 --- a/Interpolation/test/Interpolation/include/CGAL/_test_natural_neighbors_2.cpp +++ b/Interpolation/test/Interpolation/include/CGAL/_test_natural_neighbors_2.cpp @@ -18,67 +18,278 @@ // // // Author(s) : Naceur MESKINI. +// Mael Rouxel-Labbé +#include #include #include #include #include -#include #include +#include +#include +#include #include +#include template < class ForwardIterator > bool test_norm(ForwardIterator first, ForwardIterator beyond, typename std::iterator_traits::value_type::second_type norm) { - typename - std::iterator_traits::value_type::second_type sum(0); - for(; first !=beyond; first++) + typename std::iterator_traits::value_type::second_type sum(0); + for(; first!=beyond; first++) sum += first->second; return norm == sum; } -template < class ForwardIterator, class Point > +template < class ForwardIterator, class Dt > bool test_barycenter(ForwardIterator first, ForwardIterator beyond, - typename std::iterator_traits::value_type::second_type /*norm*/, - const Point& p) + const typename Dt::Point& p) { return p == CGAL::barycenter(first, beyond); } - -template -void _test_natural_neighbors_2( const Tr & ) +template < class Dt > +void _test_natural_neighbors_2_without_outputfunctor(const Dt& T) { + std::cout << "Testing backward compatibility..." << std::endl; - typedef typename Tr::Geom_traits Gt; + typedef typename Dt::Geom_traits Gt; + typedef typename Gt::Point_2 Point_2; + typedef typename Gt::FT Coord_type; - typedef typename Gt::Point_2 Point_2; - typedef typename Gt::FT Coord_type; + typedef std::vector > Point_coordinate_vector; + typedef typename Point_coordinate_vector::const_iterator PCV_cit; - typedef std::vector< std::pair > Point_coordinate_vector; + typedef typename Dt::Vertex_handle Vertex_handle; + typedef typename Dt::Face_handle Face_handle; + typedef std::pair Edge; - // TESTING a GRID POINT SET - std::cout << "NN2: Testing grid points." << std::endl; + Point_coordinate_vector coords; - Tr T; + // point on a vertex + Point_2 p = T.finite_vertices_begin()->point(); + CGAL::Triple, Coord_type, bool> coordinate_result = + CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); + assert(coordinate_result.third); + + Coord_type norm = coordinate_result.second; + assert(norm == Coord_type(1)); + + PCV_cit ci = coords.begin(); + assert(ci->first == p); + assert(ci->second == Coord_type(1)); + ++ci; + assert(ci == coords.end()); + coords.clear(); + + // On a point, but as a vertex handle + Vertex_handle vh = --(T.finite_vertices_end()); + coordinate_result = CGAL::natural_neighbor_coordinates_2(T, vh, std::back_inserter(coords)); + assert(coordinate_result.third); + + norm = coordinate_result.second; + bool is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + assert(norm == Coord_type(1)); + + ci = coords.begin(); + while(ci != coords.end()) + { + assert(ci->first != vh->point()); + assert(ci->second != Coord_type(1)); + ++ci; + } + coords.clear(); + + // point on an edge + p = Point_2(0,0.5); + coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); + assert(coordinate_result.third); + + norm = coordinate_result.second; + is_equal = test_barycenter(coords.begin(), coords.end(), p); + assert(is_equal); + coords.clear(); + + // with the conflict hole + std::list hole_bd; + T.get_boundary_of_conflicts(p, std::back_inserter(hole_bd)); + coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords), + hole_bd.begin(), hole_bd.end()); + assert(coordinate_result.third); + + norm = coordinate_result.second; + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(coords.begin(), coords.end(), p); + assert(is_equal); + coords.clear(); + + // outside convex hull + p = Point_2(3,0.5); + coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); + assert(!coordinate_result.third); + + // same, but with the face hint API + coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords), + T.finite_faces_begin()); + assert(!coordinate_result.third); + + // on a convex hull edge: + coords.clear(); + p = Point_2(2, 1); + coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); + assert(coordinate_result.third); + + norm = coordinate_result.second; + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(coords.begin(), coords.end(), p); + assert(is_equal); +} + +template < class Dt > +void _test_natural_neighbors_2_with_outputfunctor(const Dt& T) +{ + std::cout << "Testing with OutputFunctor..." << std::endl; + + typedef typename Dt::Geom_traits Gt; + typedef typename Dt::Point Point; + typedef typename Gt::FT Coord_type; + + typedef typename Dt::Vertex_handle Vertex_handle; + typedef typename Dt::Face_handle Face_handle; + typedef std::pair Edge; + + typedef std::vector > Vertex_coordinate_vector; + typedef typename Vertex_coordinate_vector::const_iterator VCV_cit; + typedef CGAL::Identity > Identity_output_functor; + + typedef std::vector > Point_coordinate_vector; + typedef typename Point_coordinate_vector::const_iterator PCV_cit; + typedef CGAL::Interpolation::internal::Extract_point_in_pair Point_output_functor; + + Vertex_coordinate_vector vh_coords; + Identity_output_functor vh_fct; + + Point_coordinate_vector pt_coords; + Point_output_functor pt_fct; + + // point on a vertex + Point p = T.finite_vertices_begin()->point(); + CGAL::Triple, Coord_type, bool> vh_coordinate_result = + CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(vh_coords), vh_fct); + assert(vh_coordinate_result.third); + + Coord_type norm = vh_coordinate_result.second; + assert(norm == Coord_type(1)); + + VCV_cit ci = vh_coords.begin(); + assert(ci->first == Vertex_handle(T.finite_vertices_begin())); + assert(ci->second == Coord_type(1)); + ++ci; + assert(ci == vh_coords.end()); + vh_coords.clear(); + + // On a point, but as a vertex handle + Vertex_handle vh = --(T.finite_vertices_end()); + vh_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, vh, std::back_inserter(vh_coords), vh_fct); + assert(vh_coordinate_result.third); + + norm = vh_coordinate_result.second; + assert(norm == Coord_type(1)); + + ci = vh_coords.begin(); + while(ci != vh_coords.end()) + { + assert(ci->first != vh); + assert(T.tds().is_vertex(vh)); + assert(ci->second != Coord_type(1)); + ++ci; + } + vh_coords.clear(); + + // point on an edge + p = Point(0,0.5); + CGAL::Triple, Coord_type, bool> pt_coordinate_result = + CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct); + assert(pt_coordinate_result.third); + + norm = pt_coordinate_result.second; + bool is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), p); + assert(is_equal); + pt_coords.clear(); + + // with the conflict hole + std::list hole_bd; + T.get_boundary_of_conflicts(p, std::back_inserter(hole_bd)); + pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct, + hole_bd.begin(), hole_bd.end()); + assert(pt_coordinate_result.third); + + norm = pt_coordinate_result.second; + is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), p); + assert(is_equal); + pt_coords.clear(); + + // outside convex hull + p = Point(3,0.5); + pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct); + assert(!pt_coordinate_result.third); + pt_coords.clear(); + + // same, but with the face hint API + pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct, + T.finite_faces_begin()); + assert(!pt_coordinate_result.third); + pt_coords.clear(); + + // on a convex hull edge: + p = Point(2, 1); + pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct); + assert(pt_coordinate_result.third); + + norm = pt_coordinate_result.second; + is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), p); + assert(is_equal); +} + +template < class Dt > +void _test_natural_neighbors_2(const Dt&) +{ + typedef typename Dt::Geom_traits Gt; + typedef typename Gt::Point_2 Point; + + Dt T; //Grid points: - Point_2 p1_2(-2, -2); - Point_2 p2_2(-2, 2); - Point_2 p3_2(2, -2); - Point_2 p4_2(2, 2); - Point_2 p1(-1, -1); - Point_2 p2(-1, 1); - Point_2 p3(1, -1); - Point_2 p4(1, 1); - Point_2 p12(-1, 0); - Point_2 p23(0, 1); - Point_2 p34(1, 0); - Point_2 p41(0, -1); + Point p1_2(-2, -2); + Point p2_2(-2, 2); + Point p3_2(2, -2); + Point p4_2(2, 2); + Point p1(-1, -1); + Point p2(-1, 1); + Point p3(1, -1); + Point p4(1, 1); + Point p12(-1, 0); + Point p23(0, 1); + Point p34(1, 0); + Point p41(0, -1); T.insert(p1_2); T.insert(p2_2); @@ -92,47 +303,10 @@ void _test_natural_neighbors_2( const Tr & ) T.insert(p23); T.insert(p34); T.insert(p41); - T.insert(Point_2(0,0)); + T.insert(Point(0,0)); - Point_coordinate_vector coords; - - // point on a vertex; - Point_2 p = Point_2(p34); - CGAL::Triple, Coord_type, bool> coordinate_result = - CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); - assert(coordinate_result.third); - - Coord_type norm = coordinate_result.second; - assert(norm == Coord_type(1)); - - typename std::vector >::const_iterator ci= coords.begin(); - assert(ci->first == p); - assert(ci->second == Coord_type(1)); - ci++; - assert(ci==coords.end()); - coords.clear(); - - // point on an edge: - p = Point_2(0,0.5); - coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); - assert(coordinate_result.third); - - norm = coordinate_result.second; - assert(test_barycenter(coords.begin(), coords.end(), norm, p)); - coords.clear(); - - // outside convex hull: - p = Point_2(3,0.5); - coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); - assert(!coordinate_result.third); - - // on a convex hull edge: - coords.clear(); - p = Point_2(2, 1); - coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)); - assert(coordinate_result.third); - - norm = coordinate_result.second; - assert(test_barycenter( coords.begin(), coords.end(),norm, p)); + _test_natural_neighbors_2_without_outputfunctor(T); + _test_natural_neighbors_2_with_outputfunctor(T); + std::cout << "done" << std::endl; } diff --git a/Interpolation/test/Interpolation/include/CGAL/_test_regular_neighbors_2.cpp b/Interpolation/test/Interpolation/include/CGAL/_test_regular_neighbors_2.cpp index dd923498abb..f52d705d4dc 100644 --- a/Interpolation/test/Interpolation/include/CGAL/_test_regular_neighbors_2.cpp +++ b/Interpolation/test/Interpolation/include/CGAL/_test_regular_neighbors_2.cpp @@ -42,105 +42,337 @@ bool test_norm(ForwardIterator first, ForwardIterator beyond, return norm == sum; } -template < class ForwardIterator, class Point > +template < class Rt, class ForwardIterator > bool test_barycenter(ForwardIterator first, ForwardIterator beyond, typename std::iterator_traits::value_type::second_type norm, - const Point& p) + const typename Rt::Weighted_point& p) { - typedef typename CGAL::Kernel_traits::Kernel::Point_2 Bare_point; + typedef typename Rt::Geom_traits Gt; + typedef typename Rt::Bare_point Bare_point; + + typename Gt::Construct_point_2 cp = Gt().construct_point_2_object(); + Bare_point b = CGAL::ORIGIN; for(; first != beyond; ++first) - b = b + (first->second/norm) * (first->first.point() - CGAL::ORIGIN); + b = b + (first->second / norm) * (cp(first->first) - CGAL::ORIGIN); - return p == b; + return (cp(p) == b); } -template -struct Functor +template < class Rt > +void _test_natural_neighbors_2_without_outputfunctor(Rt T) // intentional copy because T is modified { - typedef Point argument_type; - typedef std::pair result_type; + std::cout << "Testing backward compatibility..." << std::endl; - result_type operator()(const Point&) { return std::make_pair(0., true); } -}; + typedef typename Rt::Bare_point Bare_point; + typedef typename Rt::Weighted_point Weighted_point; + typedef typename Rt::Geom_traits Gt; + typedef typename Gt::FT Coord_type; + typedef std::vector > Point_coordinate_vector; -template -void test_gradient_fitting(const Tr& rt) -{ - typedef typename Tr::Geom_traits::Kernel K; - typedef typename Tr::Geom_traits::FT FT; - typedef typename Tr::Geom_traits::Vector_2 Vector_2; - typedef typename Tr::Geom_traits::Weighted_point_2 Point; - - typedef typename std::back_insert_iterator< - std::vector< - std::pair > > OutputIterator; - - std::vector > v; - OutputIterator out = std::back_inserter(v); - Functor f; - - CGAL::Interpolation_gradient_fitting_traits_2 traits; - - sibson_gradient_fitting_rn_2(rt, out, f, traits); -} - -template -void _test_regular_neighbors_2(const Tr &) -{ - Tr T; - - int n=20, m=200; - double r = 3; - double max_weight =1; - - typedef typename Tr::Geom_traits Gt; - typedef typename Gt::Weighted_point_2 Weighted_point; - typedef typename Gt::Point_2 Bare_point; - typedef typename Gt::FT Coord_type; - - typedef std::vector > Point_coordinate_vector; - - - std::cout << "RN2: Testing random points." << std::endl; - //test random points in a square of length r: - std::vector points; - points.reserve(n+m); - - //put four bounding box points: - points.push_back(Bare_point(-r,-r)); - points.push_back(Bare_point(r,-r)); - points.push_back(Bare_point(-r,r)); - points.push_back(Bare_point(r,r)); - - // Create n+m-4 points within a disc of radius 2 - CGAL::Random_points_in_square_2 g(r); - CGAL::cpp11::copy_n(g, n+m, std::back_inserter(points)); - - CGAL::Random random; - for(int i=0; i Edge; Point_coordinate_vector coords; - for(int i=n; i, Coord_type, bool> coordinate_result = + CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords)); + assert(coordinate_result.third); + + Coord_type norm = coordinate_result.second; + assert(norm == Coord_type(1)); + + typename std::vector< std::pair >::const_iterator ci = coords.begin(); + for(; ci!= coords.end(); ci++) + assert(ci->second == Coord_type(0.25)); + + bool is_equal = test_barycenter(coords.begin(), coords.end(), norm, wp); + assert(is_equal); + coords.clear(); + + // test with hidden_vertices: + wp = Weighted_point(Bare_point(0,0), 4.); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords)); + assert(coordinate_result.third); + norm = coordinate_result.second; + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(coords.begin(), coords.end(), norm, wp); + assert(is_equal); + coords.clear(); + + // add the middle point of the grid + T.insert(Weighted_point(Bare_point(0,0), 0.)); + + // point on a vertex; + wp = Weighted_point(Bare_point(1,0), 0.); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords)); + assert(coordinate_result.third); + + norm = coordinate_result.second; + assert(norm == Coord_type(1)); + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + ci = coords.begin(); + assert(ci->first == wp); + assert(ci->second == Coord_type(1)); + ++ci; + assert(ci == coords.end()); + coords.clear(); + + // point on the vertex but creating a hole: + wp = Weighted_point(Bare_point(1,0), 2.); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords)); + assert(coordinate_result.third); + + norm = coordinate_result.second; + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(coords.begin(), coords.end(), norm, wp); + assert(is_equal); + coords.clear(); + + // point on an edge: + wp = Weighted_point(Bare_point(0,0.5), 3.); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords)); + assert(coordinate_result.third); + + norm = coordinate_result.second; + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(coords.begin(), coords.end(), norm, wp); + assert(is_equal); + coords.clear(); + + // a vertex v in Reg(P\v->point()): + typename Rt::Vertex_iterator vit = T.finite_vertices_end(); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, --vit, std::back_inserter(coords)); + assert(coordinate_result.third); + + norm = coordinate_result.second; + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(coords.begin(), coords.end(), norm, vit->point()); + assert(is_equal); + coords.clear(); + + ci = coords.begin(); + while(ci != coords.end()) { - Weighted_point wp = Weighted_point(points[i], random.get_double(2*max_weight, 3*max_weight)); - CGAL::Triple, Coord_type, bool> coordinate_result = - CGAL::regular_neighbor_coordinates_2(T,wp,std::back_inserter(coords)); - assert(coordinate_result.third); - Coord_type norm = coordinate_result.second; - - assert(norm > 0); - assert(test_barycenter(coords.begin(), coords.end(), norm, points[i])); - coords.clear(); + assert(ci->first != (--vit)->point()); + assert(ci->second != Coord_type(1)); + ++ci; } + coords.clear(); - test_gradient_fitting(T); + // with the conflict hole + std::list hole_bd; + std::list hidden_vertices; + T.get_boundary_of_conflicts_and_hidden_vertices(wp, std::back_inserter(hole_bd), std::back_inserter(hidden_vertices)); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords), + hole_bd.begin(), hole_bd.end(), + hidden_vertices.begin(), hidden_vertices.end()); + assert(coordinate_result.third); - //TESTING a GRID POINT SET - std::cout << "RN2: Testing grid points." << std::endl; + norm = coordinate_result.second; + is_equal = test_norm(coords.begin(), coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(coords.begin(), coords.end(), norm, wp); + assert(is_equal); + coords.clear(); + + // outside convex hull: + wp = Weighted_point(Bare_point(3,0.5), 3.); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords)); + assert(!coordinate_result.third); + + // same but with the face hint API + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords), + T.finite_faces_begin()); + assert(!coordinate_result.third); + + // on a convex hull edge: + wp = Weighted_point(Bare_point(2,1), 3.); + coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords)); + assert(!coordinate_result.third); +} + +template < class Rt > +void _test_natural_neighbors_2_with_outputfunctor(Rt T) // intentional copy because T is modified +{ + std::cout << "Testing with OutputFunctor..." << std::endl; + + typedef typename Rt::Bare_point Bare_point; + typedef typename Rt::Weighted_point Weighted_point; + typedef typename Rt::Geom_traits Gt; + typedef typename Gt::FT Coord_type; + + typedef typename Rt::Vertex_handle Vertex_handle; + typedef typename Rt::Face_handle Face_handle; + typedef std::pair Edge; + + typedef std::vector > Vertex_coordinate_vector; + typedef typename Vertex_coordinate_vector::const_iterator VCV_cit; + typedef CGAL::Identity > Identity_output_functor; + + typedef std::vector > Point_coordinate_vector; + typedef typename Point_coordinate_vector::const_iterator PCV_cit; + typedef CGAL::Interpolation::internal::Extract_point_in_pair Point_output_functor; + + Vertex_coordinate_vector vh_coords; + Identity_output_functor vh_fct; + + Point_coordinate_vector pt_coords; + Point_output_functor pt_fct; + + // test with 0 weight: + Weighted_point wp(Bare_point(0,0), 0.); + CGAL::Triple, Coord_type, bool> pt_coordinate_result = + CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct); + assert(pt_coordinate_result.third); + + Coord_type norm = pt_coordinate_result.second; + assert(norm == Coord_type(1)); + + PCV_cit ci = pt_coords.begin(); + for(; ci!= pt_coords.end(); ci++) + assert(ci->second == Coord_type(0.25)); + + bool is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), norm, wp); + assert(is_equal); + pt_coords.clear(); + + // test with hidden_vertices: + wp = Weighted_point(Bare_point(0,0), 4.); + pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct); + assert(pt_coordinate_result.third); + norm = pt_coordinate_result.second; + is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), norm, wp); + assert(is_equal); + pt_coords.clear(); + + // add the middle point of the grid + T.insert(Weighted_point(Bare_point(0,0), 0.)); + + // point on a vertex; + wp = Weighted_point(Bare_point(1,0), 0.); + CGAL::Triple, Coord_type, bool> vh_coordinate_result = + CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(vh_coords), vh_fct); + assert(vh_coordinate_result.third); + + norm = vh_coordinate_result.second; + assert(norm == Coord_type(1)); + is_equal = test_norm(vh_coords.begin(), vh_coords.end(), norm); + assert(is_equal); + + VCV_cit vh_ci = vh_coords.begin(); + assert(vh_ci->first->point() == wp); + assert(vh_ci->second == Coord_type(1)); + ++vh_ci; + assert(vh_ci == vh_coords.end()); + vh_coords.clear(); + + // point on the vertex but creating a hole: + wp = Weighted_point(Bare_point(1,0), 2.); + pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct); + assert(pt_coordinate_result.third); + + norm = pt_coordinate_result.second; + is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), norm, wp); + assert(is_equal); + pt_coords.clear(); + + // point on an edge: + wp = Weighted_point(Bare_point(0,0.5), 3.); + pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct); + assert(pt_coordinate_result.third); + + norm = pt_coordinate_result.second; + is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), norm, wp); + assert(is_equal); + pt_coords.clear(); + + // a vertex v in Reg(P\v->point()): + typename Rt::Vertex_iterator vit = T.finite_vertices_end(); + pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, --vit, std::back_inserter(pt_coords), pt_fct); + assert(pt_coordinate_result.third); + + norm = pt_coordinate_result.second; + is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), norm, vit->point()); + assert(is_equal); + pt_coords.clear(); + + ci = pt_coords.begin(); + while(ci != pt_coords.end()) + { + assert(ci->first != (--vit)->point()); + assert(ci->second != Coord_type(1)); + ++ci; + } + pt_coords.clear(); + + // with the conflict hole + std::list hole_bd; + std::list hidden_vertices; + T.get_boundary_of_conflicts_and_hidden_vertices(wp, std::back_inserter(hole_bd), std::back_inserter(hidden_vertices)); + pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct, + hole_bd.begin(), hole_bd.end(), + hidden_vertices.begin(), hidden_vertices.end()); + assert(pt_coordinate_result.third); + + norm = pt_coordinate_result.second; + is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm); + assert(is_equal); + + is_equal = test_barycenter(pt_coords.begin(), pt_coords.end(), norm, wp); + assert(is_equal); + pt_coords.clear(); + + // outside convex hull: + wp = Weighted_point(Bare_point(3,0.5), 3.); + pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct); + assert(!pt_coordinate_result.third); + + // same but with the face hint API + vh_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(vh_coords), vh_fct, + T.finite_faces_begin()); + assert(!vh_coordinate_result.third); + + // on a convex hull edge: + wp = Weighted_point(Bare_point(2,1), 3.); + pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct); + assert(!pt_coordinate_result.third); +} + +template +void _test_regular_neighbors_2(const Rt &) +{ + typedef typename Rt::Bare_point Bare_point; + typedef typename Rt::Weighted_point Weighted_point; + + Rt T; - Tr T2; //Grid points: Bare_point p1_2(-2, -2); Bare_point p2_2(-2,2); @@ -155,89 +387,19 @@ void _test_regular_neighbors_2(const Tr &) Bare_point p34(1,0); Bare_point p41(0,-1); - T2.insert(Weighted_point(p1_2, 0)); - T2.insert(Weighted_point(p2_2, 0)); - T2.insert(Weighted_point(p3_2, 0)); - T2.insert(Weighted_point(p4_2, 0)); - T2.insert(Weighted_point(p1, 0)); - T2.insert(Weighted_point(p2, 0)); - T2.insert(Weighted_point(p3, 0)); - T2.insert(Weighted_point(p4, 0)); - T2.insert(Weighted_point(p12, 0)); - T2.insert(Weighted_point(p23, 0)); - T2.insert(Weighted_point(p34, 0)); - T2.insert(Weighted_point(p41, 0)); + T.insert(Weighted_point(p1_2, 0)); + T.insert(Weighted_point(p2_2, 0)); + T.insert(Weighted_point(p3_2, 0)); + T.insert(Weighted_point(p4_2, 0)); + T.insert(Weighted_point(p1, 0)); + T.insert(Weighted_point(p2, 0)); + T.insert(Weighted_point(p3, 0)); + T.insert(Weighted_point(p4, 0)); + T.insert(Weighted_point(p12, 0)); + T.insert(Weighted_point(p23, 0)); + T.insert(Weighted_point(p34, 0)); + T.insert(Weighted_point(p41, 0)); - //test with 0 weight: - Weighted_point wp(Bare_point(0,0), 0); - CGAL::Triple, Coord_type, bool> coordinate_result = - CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords)); - assert(coordinate_result.third); - - Coord_type norm = coordinate_result.second; - assert(norm == Coord_type(1)); - - typename std::vector< std::pair >::const_iterator ci = coords.begin(); - for(; ci!= coords.end(); ci++) - assert(ci->second == Coord_type(0.25)); - assert(test_barycenter(coords.begin(), coords.end(), norm, wp)); - coords.clear(); - - //test with hidden_vertices: - wp = Weighted_point(Bare_point(0,0), 4); - coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords)); - assert(coordinate_result.third); - norm = coordinate_result.second; - assert(test_barycenter(coords.begin(), coords.end(), norm, wp)); - coords.clear(); - - //add the middle point of the grid - T2.insert(Weighted_point(Bare_point(0,0), 0)); - - //point on a vertex; - wp = Weighted_point(p34, 0); - coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords)); - assert(coordinate_result.third); - norm = coordinate_result.second; - assert(norm == Coord_type(1)); - ci = coords.begin(); - assert(ci->first == wp); - assert(ci->second == Coord_type(1)); - ci++; - assert(ci == coords.end()); - coords.clear(); - - //point on the vertex but creating a hole: - wp = Weighted_point(p34, 2); - coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords)); - assert(coordinate_result.third); - norm = coordinate_result.second; - assert(test_barycenter(coords.begin(), coords.end(), norm, wp)); - coords.clear(); - - //point on an edge: - wp = Weighted_point(Bare_point(0,0.5), 3); - coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords)); - assert(coordinate_result.third); - norm = coordinate_result.second; - assert(test_barycenter(coords.begin(), coords.end(), norm, wp)); - coords.clear(); - - //a vertex v in Reg(P\v->point()): - typename Tr::Vertex_iterator vit = T2.finite_vertices_end(); - coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, --vit, std::back_inserter(coords)); - assert(coordinate_result.third); - norm = coordinate_result.second; - assert(test_barycenter(coords.begin(), coords.end(), norm,vit->point())); - coords.clear(); - - //outside convex hull: - wp = Weighted_point(Bare_point(3,0.5), 3); - coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords)); - assert(!coordinate_result.third); - - //on a convex hull edge: - wp = Weighted_point(Bare_point(2,1), 3); - coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords)); - assert(!coordinate_result.third); + _test_natural_neighbors_2_without_outputfunctor(T); + _test_natural_neighbors_2_with_outputfunctor(T); } diff --git a/Interpolation/test/Interpolation/test_natural_neighbors_2.cpp b/Interpolation/test/Interpolation/test_natural_neighbors_2.cpp index bbca41aaee7..5514853b9e6 100644 --- a/Interpolation/test/Interpolation/test_natural_neighbors_2.cpp +++ b/Interpolation/test/Interpolation/test_natural_neighbors_2.cpp @@ -30,8 +30,8 @@ typedef CGAL::Delaunay_triangulation_2 Dt; int main() { std::cout << "Testing NN_neighbors_2 " << std::endl; - std::cout << " with Exact_predicates_inexact_constructions_kernel: " << std::endl ; + std::cout << " using Exact_predicates_inexact_constructions_kernel: " << std::endl; _test_natural_neighbors_2( Dt() ); - return 0; + return EXIT_SUCCESS; } diff --git a/Interpolation/test/Interpolation/test_regular_neighbors_2.cpp b/Interpolation/test/Interpolation/test_regular_neighbors_2.cpp index 0e4f36c5dd1..aea65b1b575 100644 --- a/Interpolation/test/Interpolation/test_regular_neighbors_2.cpp +++ b/Interpolation/test/Interpolation/test_regular_neighbors_2.cpp @@ -16,25 +16,24 @@ // // Author(s) : Julia Floetotto -#include -#include +#include #include -#include -#include +#include +#include +#include #include typedef CGAL::Exact_predicates_exact_constructions_kernel K; - typedef CGAL::Regular_triangulation_2 Rt1; int main() { std::cout << "Testing NN_neighbors_2 " << std::endl; - std::cout << " with Exact_predicates_exact_constructions_kernel: " << std::endl ; + std::cout << " using Exact_predicates_exact_constructions_kernel: " << std::endl; _test_regular_neighbors_2( Rt1() ); - return 0; + return EXIT_SUCCESS; }