avoid using c style arrays

This commit is contained in:
Anirudh Lakhanpal 2025-01-21 23:12:12 +05:30
parent 93f02ccd61
commit 724ef98978
2 changed files with 9 additions and 9 deletions

View File

@ -4,7 +4,7 @@
#include <CGAL/Random.h>
#include <iostream>
#include <vector>
typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Min_sphere_of_points_d_traits_2<K,double> Traits;
typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_circle;
@ -14,14 +14,14 @@ int
main( int, char**)
{
const int n = 100;
Point P[n];
std::vector<Point> P(n);
CGAL::Random r; // random number generator
for ( int i = 0; i < n; ++i){
P[ i] = Point(r.get_double(), r.get_double());
P.at(i) = Point(r.get_double(), r.get_double());
}
Min_circle mc( P, P+n);
Min_circle mc( P.begin(), P.begin() + n);
Min_circle::Cartesian_const_iterator ccib = mc.center_cartesian_begin(), ccie = mc.center_cartesian_end();
std::cout << "center:";

View File

@ -2,7 +2,7 @@
#include <CGAL/Simple_homogeneous.h>
#include <CGAL/Min_circle_2.h>
#include <CGAL/Min_circle_2_traits_2.h>
#include <vector>
#include <iostream>
// typedefs
@ -16,15 +16,15 @@ int
main( int, char**)
{
const int n = 100;
Point P[n];
std::vector<Point> P(n);
for ( int i = 0; i < n; ++i){
P[i] = Point( (i%2 == 0 ? i : -i), 0, 1);
P.at(i) = Point( (i%2 == 0 ? i : -i), 0, 1);
// (0,0), (-1,0), (2,0), (-3,0), ...
}
Min_circle mc1( P, P+n, false); // very slow
Min_circle mc2( P, P+n, true); // fast
Min_circle mc1( P.begin(), P.begin() + n, false); // very slow
Min_circle mc2( P.begin(), P.begin() +n, true); // fast
CGAL::IO::set_pretty_mode( std::cout);
std::cout << mc2;