// ============================================================================ // // Copyright (c) 1997 The CGAL Consortium // // This software and related documentation is part of an INTERNAL release // of the Computational Geometry Algorithms Library (CGAL). It is not // intended for general use. // // ---------------------------------------------------------------------------- // // release : $CGAL_Revision: $ // release_date : $CGAL_Date: $ // // file : test_generators.C // chapter : $CGAL_Chapter: Geometric Object Generators $ // package : $CGAL_Package: Generator 2.12 (28 Jul 1999) $ // source : generators.fw // revision : $Id$ // revision_date : $Date$ // author(s) : Lutz Kettner // Olivier Devillers // // coordinator : INRIA, Sophia Antipolis // // Test Random Sources and Geometric Object Generators // ============================================================================ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace CGAL; typedef Cartesian R; typedef CGAL::Cartesian_d Kd; void test_point_generators_2() { typedef Point_2 Point_2; typedef Creator_uniform_2 Creator; // Create test point set. std::vector points; points.reserve(1000); Random_points_in_disc_2 g1( 100.0); CGAL::cpp11::copy_n( g1, 100, std::back_inserter(points)); Random_points_on_circle_2 g2( 100.0); Random_points_in_square_2 g3( 100.0); Random_points_on_square_2 g4( 100.0); Random_points_on_segment_2 g5( Point_2(-100,-100), Point_2( 100, 100)); Points_on_segment_2 g5a( Point_2( 50,-50), Point_2(-50, 50), 50); CGAL::cpp11::copy_n( g2, 100, std::back_inserter(points)); CGAL::cpp11::copy_n( g3, 100, std::back_inserter(points)); CGAL::cpp11::copy_n( g4, 100, std::back_inserter(points)); CGAL::cpp11::copy_n( g5, 50, std::back_inserter(points)); CGAL::cpp11::copy_n( g5a, 50, std::back_inserter(points)); points_on_square_grid_2( 50.0, (std::size_t)1, std::back_inserter(points), Creator()); points_on_square_grid_2( 50.0, (std::size_t)2, std::back_inserter(points), Creator()); points_on_square_grid_2( 50.0, (std::size_t)3, std::back_inserter(points), Creator()); points_on_square_grid_2( 50.0, (std::size_t)94, std::back_inserter(points), Creator()); points_on_segment_2( Point_2(-100, 100), Point_2( 100,-100), (std::size_t)100, std::back_inserter(points)); random_selection( points.begin(), points.end(), (std::size_t)100, std::back_inserter(points)); random_collinear_points_2( points.begin(), points.end(), (std::size_t)100, std::back_inserter(points)); // Check perturbation. Make sure that the result stays within // the 100 x 100 square. 10 pixel perturbation allowed. Random_points_in_square_2 g6( 90.0); int count = 100 ; CGAL::cpp11::copy_n( g6, count, std::back_inserter(points)); std::vector::iterator i2 = points.end(); std::vector::iterator i1 = i2 ; std::advance(i1,-count); perturb_points_2( i1, i2, 10.0); // Create a random permutation. std::random_shuffle( points.begin(), points.end(), get_default_random()); assert( points.size() == 1000); for ( std::vector::iterator i = points.begin(); i != points.end(); i++){ assert( i->x() <= 100); assert( i->x() >= -100); assert( i->y() <= 100); assert( i->y() >= -100); } } void test_point_generators_3() { typedef Point_3 Point_3; typedef Creator_uniform_3 Creator; /* Create test point set. */ std::vector points; points.reserve(600); Random_points_in_sphere_3 g1( 100.0); CGAL::cpp11::copy_n( g1, 100, std::back_inserter(points)); Random_points_on_sphere_3 g2( 100.0); Random_points_in_cube_3 g3( 100.0); Random_points_on_segment_3 g4( Point_3(-100,-100, -100), Point_3( 100, 100, 100)); CGAL::cpp11::copy_n( g2, 100, std::back_inserter(points)); CGAL::cpp11::copy_n( g3, 100, std::back_inserter(points)); CGAL::cpp11::copy_n( g4, 100, std::back_inserter(points)); points_on_cube_grid_3( 50.0, (std::size_t)1, std::back_inserter(points), Creator()); points_on_cube_grid_3( 50.0, (std::size_t)2, std::back_inserter(points), Creator()); points_on_cube_grid_3( 50.0, (std::size_t)3, std::back_inserter(points), Creator()); points_on_cube_grid_3( 50.0, (std::size_t)94, std::back_inserter(points), Creator()); random_selection( points.begin(), points.end(), 100, std::back_inserter(points)); assert( points.size() == 600); for ( std::vector::iterator i = points.begin(); i != points.end(); i++){ assert( i->x() <= 100); assert( i->x() >= -100); assert( i->y() <= 100); assert( i->y() >= -100); assert( i->z() <= 100); assert( i->z() >= -100); } } void test_point_generators_d() { typedef Kd::Point_d Point; typedef CGAL::Creator_uniform_d::iterator, Point>Creator_d; std::vector points; int nb_g=10000; points.reserve (nb_g+403); int i=0,ii; { // 100 random points in dim 36 std::cout<<" cube dim 36"< gen (36, 1.0); CGAL::cpp11::copy_n( gen, 100, std::back_inserter(points)); i+=100; std::cout<<" done"< gen (4, 100.0); CGAL::cpp11::copy_n( gen, 100, std::back_inserter(points)); std::cout<<" done"< gen (3, 1.0); CGAL::cpp11::copy_n( gen, nb_g, std::back_inserter(points)); std::cout<<" done"<0) g = g + (points[i] - o3); } assert( std::fabs( g[0]/nb_g - 3.0/16.0) < 0.01 ); std::cout<<" center of mass 3/16~="< gen (26, 1.0); CGAL::cpp11::copy_n( gen, 100, std::back_inserter(points)); std::cout<<" done"<