mirror of https://github.com/CGAL/cgal
added generator for random sites in the box [0,1]x[0,1]
This commit is contained in:
parent
57f41219ce
commit
8cccb18d41
|
|
@ -0,0 +1,52 @@
|
||||||
|
#include <CGAL/basic.h>
|
||||||
|
#include <CGAL/Apollonius_graph_2/random_sites_in_0x1_box.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include <CGAL/Simple_cartesian.h>
|
||||||
|
#include <CGAL/Apollonius_site_2.h>
|
||||||
|
|
||||||
|
typedef CGAL::Simple_cartesian<double> K;
|
||||||
|
typedef CGAL::Apollonius_site_2<K> Site_2;
|
||||||
|
|
||||||
|
int usage (int argc, char **argv)
|
||||||
|
{
|
||||||
|
std::cerr << "usage: " << argv[0]
|
||||||
|
<< " <number of points> <max radius> [seed]" << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int num, seed = 42;
|
||||||
|
double rmax;
|
||||||
|
|
||||||
|
if (argc < 2)
|
||||||
|
return usage (argc, argv);
|
||||||
|
|
||||||
|
{
|
||||||
|
std::istringstream is (argv[1]);
|
||||||
|
if (! (is >> num)) return usage (argc, argv);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::istringstream is (argv[2]);
|
||||||
|
if (! (is >> rmax)) return usage (argc, argv);
|
||||||
|
}
|
||||||
|
if (argc > 3) {
|
||||||
|
std::istringstream is (argv[3]);
|
||||||
|
if (! (is >> seed)) return usage (argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGAL::Random_sites_in_0x1_box<Site_2> g(rmax, seed);
|
||||||
|
|
||||||
|
std::cout << std::setprecision(17);
|
||||||
|
|
||||||
|
for (int i = 0; i < num; ++i) {
|
||||||
|
std::cout << *g << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef CGAL_APOLLONIUS_GRAPH_2_RANDOM_SITES_IN_0X1_BOX_H
|
||||||
|
#define CGAL_APOLLONIUS_GRAPH_2_RANDOM_SITES_IN_0X1_BOX_H 1
|
||||||
|
|
||||||
|
#include <CGAL/basic.h>
|
||||||
|
#include <CGAL/Random.h>
|
||||||
|
|
||||||
|
CGAL_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
template<class Site>
|
||||||
|
class Random_sites_in_0x1_box
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef Site Site_2;
|
||||||
|
typedef Site_2 result_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef typename Site_2::Point_2 Point_2;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Random_sites_in_0x1_box(double rmax = 0.125, int seed = 0)
|
||||||
|
: rmax_(rmax), random_(seed) {}
|
||||||
|
|
||||||
|
Site_2 operator*() {
|
||||||
|
double x = random_.get_double(0, 1);
|
||||||
|
double y = random_.get_double(0, 1);
|
||||||
|
double w = random_.get_double(0, rmax_);
|
||||||
|
return Site_2(Point_2(x,y),w);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
double rmax_;
|
||||||
|
Random random_;
|
||||||
|
};
|
||||||
|
|
||||||
|
CGAL_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // CGAL_APOLLONIUS_GRAPH_2_RANDOM_SITES_IN_0X1_BOX_H
|
||||||
Loading…
Reference in New Issue