Add NumberGenerator.h for different methods
This commit is contained in:
parent
535d912742
commit
083ba53d67
72
NumberGenerator.h
Normal file
72
NumberGenerator.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "Point.h"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <cstdlib> // for srand, rand
|
||||||
|
|
||||||
|
class NumberGenerator
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static const int OFFSET = 0;
|
||||||
|
static const int WIDTH = 700;
|
||||||
|
static const int HEIGHT = 700;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::list<Point> get_random_numbers(int valCount)
|
||||||
|
{
|
||||||
|
std::list<Point> points;
|
||||||
|
|
||||||
|
//srand(static_cast <unsigned> (time(0)));
|
||||||
|
srand(static_cast <unsigned> (0)); // fixed seed for testing
|
||||||
|
|
||||||
|
float x = 0;
|
||||||
|
float y = 0;
|
||||||
|
for (int i = 0; i < valCount; ++i)
|
||||||
|
{
|
||||||
|
x = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (WIDTH - 2*OFFSET)));
|
||||||
|
y = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (HEIGHT - 2*OFFSET)));
|
||||||
|
|
||||||
|
points.push_back(Point(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::list<Point> get_rectangle_numbers(int valCount)
|
||||||
|
{
|
||||||
|
std::list<Point> points;
|
||||||
|
|
||||||
|
float diff = (2.f * HEIGHT / valCount);
|
||||||
|
|
||||||
|
float x = 0;
|
||||||
|
float y = 0;
|
||||||
|
for (int i = 0; i < valCount; ++i)
|
||||||
|
{
|
||||||
|
x = (i%2 == 0) ? OFFSET : WIDTH - OFFSET;
|
||||||
|
y = diff/2 + (i/2) * diff;
|
||||||
|
|
||||||
|
points.push_back(Point(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::list<Point> get_circle_numbers(int valCount)
|
||||||
|
{
|
||||||
|
std::list<Point> points;
|
||||||
|
|
||||||
|
float rad = HEIGHT / 2; //8.0f;
|
||||||
|
float deg = (float)(2 * 3.14159 / valCount);
|
||||||
|
|
||||||
|
float x = 0;
|
||||||
|
float y = 0;
|
||||||
|
for (int i = 0; i < valCount; ++i)
|
||||||
|
{
|
||||||
|
x = WIDTH/2 + rad * cosf(i * deg);
|
||||||
|
y = HEIGHT/2 + rad * sinf(i * deg);
|
||||||
|
|
||||||
|
points.push_back(Point(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user