Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used std::vector instead of c-style arrays for point storage. #8709

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions Bounding_volumes/examples/Min_annulus_d/min_annulus_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <CGAL/Homogeneous.h>
#include <iostream>
#include <cassert>
#include <array>

#ifdef CGAL_USE_GMP
#include <CGAL/Gmpzf.h>
Expand All @@ -25,10 +26,10 @@ typedef CGAL::Min_annulus_d<Traits> Min_annulus;
int main()
{
// points on the squares [-1,1]^2 and [-2,2]^2
Point P[8] = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1),
Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)};
std::array<Point, 8> P = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1),
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)};
MaelRL marked this conversation as resolved.
Show resolved Hide resolved

Min_annulus ma(P, P+8);
Min_annulus ma(P.begin(), P.end());
assert (ma.is_valid());

// get center of annulus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef CGAL::Exact_integer ET;

#include <iostream>
#include <cassert>
#include <array>
MaelRL marked this conversation as resolved.
Show resolved Hide resolved

// use an inexact kernel...
typedef CGAL::Homogeneous<double> K;
Expand All @@ -24,10 +25,10 @@ typedef CGAL::Min_annulus_d<Traits> Min_annulus;
int main()
{
// points on the squares [-1,1]^2 and [-2,2]^2
Point P[8] = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1),
Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)};
std::array<Point, 8> P = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1),
Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)};
MaelRL marked this conversation as resolved.
Show resolved Hide resolved

Min_annulus ma(P, P+8);
Min_annulus ma(P.begin(), P.end());
assert (ma.is_valid());

// get center of annulus
Expand Down
7 changes: 4 additions & 3 deletions Bounding_volumes/examples/Min_circle_2/min_circle_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <CGAL/Random.h>

#include <iostream>
#include <array>

typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Min_sphere_of_points_d_traits_2<K,double> Traits;
Expand All @@ -14,14 +15,14 @@ int
main( int, char**)
{
const int n = 100;
Point P[n];
std::array<Point, n> P;
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.end());

Min_circle::Cartesian_const_iterator ccib = mc.center_cartesian_begin(), ccie = mc.center_cartesian_end();
std::cout << "center:";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <CGAL/Simple_homogeneous.h>
#include <CGAL/Min_circle_2.h>
#include <CGAL/Min_circle_2_traits_2.h>

#include <array>
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
#include <iostream>

// typedefs
Expand All @@ -16,15 +16,15 @@ int
main( int, char**)
{
const int n = 100;
Point P[n];
std::array<Point, n> P;

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.end(), false); // very slow
Min_circle mc2( P.begin(), P.end(), true); // fast

CGAL::IO::set_pretty_mode( std::cout);
std::cout << mc2;
Expand Down
10 changes: 5 additions & 5 deletions Bounding_volumes/examples/Min_ellipse_2/min_ellipse_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <CGAL/Exact_rational.h>

#include <cassert>

#include <array>
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
typedef CGAL::Exact_rational NT;
typedef CGAL::Cartesian<NT> K;
typedef CGAL::Point_2<K> Point;
Expand All @@ -16,20 +16,20 @@ int
main( int, char**)
{
const int n = 200;
Point P[n];
std::array<Point, n> P;

for ( int i = 0; i < n; ++i)
P[ i] = Point( i % 2 ? i : -i , 0);
P.at(i) = Point( i % 2 ? i : -i , 0);
// (0,0), (-1,0), (2,0), (-3,0)

std::cout << "Computing ellipse (without randomization)...";
std::cout.flush();
Min_ellipse me1( P, P+n, false); // very slow
Min_ellipse me1( P.begin(), P.end(), false); // very slow
std::cout << "done." << std::endl;

std::cout << "Computing ellipse (with randomization)...";
std::cout.flush();
Min_ellipse me2( P, P+n, true); // fast
Min_ellipse me2( P.begin(), P.end(), true); // fast
std::cout << "done." << std::endl;

// because all input points are collinear, the ellipse is
Expand Down
8 changes: 4 additions & 4 deletions Bounding_volumes/examples/Min_sphere_d/min_sphere_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <iostream>
#include <cstdlib>

#include <array>
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Min_sphere_of_points_d_traits_3<K,double> Traits;
typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_sphere;
Expand All @@ -16,16 +16,16 @@ const int d = 3; // dimension of points

int main ()
{
Point P[n]; // n points
std::array<Point, n> P; // n points
CGAL::Random r; // random number generator

for (int i=0; i<n; ++i) {
for (int j = 0; j < d; ++j) {
P[i] = Point(r.get_double(), r.get_double(), r.get_double()); // random point
P.at(i) = Point(r.get_double(), r.get_double(), r.get_double()); // random point
}
}

Min_sphere ms(P, P+n); // smallest enclosing sphere
Min_sphere ms(P.begin(), P.end()); // smallest enclosing sphere

Min_sphere::Cartesian_const_iterator ccib = ms.center_cartesian_begin(), ccie = ms.center_cartesian_end();
std::cout << "center:";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ int
main ()
{
const int n = 10; // number of points
Point P[n]; // n points
std::array<Point, n> P; // n points
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
CGAL::Random r; // random number generator

for (int i=0; i<n; ++i) {
P[i] = Point(r.get_int(0, 1000),r.get_int(0, 1000), r.get_int(0, 1000), 1 );
P.at(i) = Point(r.get_int(0, 1000),r.get_int(0, 1000), r.get_int(0, 1000), 1 );
}

Min_sphere ms (P, P+n); // smallest enclosing sphere
Min_sphere ms (P.begin(), P.end()); // smallest enclosing sphere

CGAL::IO::set_pretty_mode (std::cout);
std::cout << ms; // output the sphere
Expand Down
Loading