Compare commits

...

3 Commits

5 changed files with 69 additions and 62 deletions

View File

@ -350,7 +350,7 @@ bool less (sf::CircleShape a, sf::CircleShape b)
}
// compute the cross product of vectors (center -> a) x (center -> b)
int det = (ax - centerx) * (by - centery) - (bx - centerx) * (ay - centery);
int det = (int)((ax - centerx) * (by - centery) - (bx - centerx) * (ay - centery));
if (det < 0)
return true;
if (det > 0)
@ -358,8 +358,8 @@ bool less (sf::CircleShape a, sf::CircleShape b)
// points a and b are on the same line from the center
// check which point is closer to the center
int d1 = (ax - centerx) * (ax - centerx) + (ay - centery) * (ay - centery);
int d2 = (bx - centerx) * (bx - centerx) + (by - centery) * (by - centery);
int d1 = (int)((ax - centerx) * (ax - centerx) + (ay - centery) * (ay - centery));
int d2 = (int)((bx - centerx) * (bx - centerx) + (by - centery) * (by - centery));
return d1 > d2;
}

View File

@ -41,7 +41,7 @@ private:
//std::list<Line> m_lines;
//Line *m_curLine = nullptr; // get any value if the underlying vector gets resized and moved in memory
Line m_curLine; // -> either make a copy
size_t m_curLineIdx = -1; // or just use index
int m_curLineIdx = -1; // or just use index
unsigned int m_step = 0;
void update();

View File

@ -1,12 +1,60 @@
#include "Point.h"
#include <list>
#include <cstdlib> // for srand, rand
#include <fstream> // ifstream
#include <ctime> // time
class NumberGenerator
{
public:
static std::list<Point> get_random_numbers(int valCount)
static std::list<Point> generate_numbers(const int count, const int mode = 1)
{
if (mode == 1)
{
return get_random_numbers(count);
}
else if (mode == 2)
{
return NumberGenerator::get_rectangle_numbers(count);
}
else if (mode == 3)
{
return NumberGenerator::get_circle_numbers(count);
}
else throw "unspecified rng Mode"; // TODO: could handle in parse args
}
static std::list<Point> read_numbers(const std::string &fileRnd)
{
std::list<Point> points;
std::ifstream in(fileRnd.c_str());
if (in.is_open())
{
std::string line;
std::getline(in, line); // get first line for explizit valueCount
int valCount = std::stoi(line);
float x = 0;
float y = 0;
for (int i = 0; i < valCount; ++i)
{
getline(in, line);
//getline(in, line, ','); // could also be used slightly different but includes newlines :/
size_t pos = line.find(',');
if (pos != std::string::npos)
{
x = std::stof(line.substr(0, pos));
y = std::stof(line.substr(pos + 1));
points.push_back(Point(x, y));
}
else
{
throw "invalid format!";
}
}
}
return points;
}
static std::list<Point> get_random_numbers (const int valCount)
{
std::list<Point> points;
@ -26,7 +74,7 @@ public:
return points;
}
static std::list<Point> get_rectangle_numbers(int valCount)
static std::list<Point> get_rectangle_numbers (const int valCount)
{
std::list<Point> points;
@ -45,7 +93,7 @@ public:
return points;
}
static std::list<Point> get_circle_numbers(int valCount)
static std::list<Point> get_circle_numbers (const int valCount)
{
std::list<Point> points;
@ -61,7 +109,6 @@ public:
points.push_back(Point(x, y));
}
return points;
}
};

View File

@ -7,7 +7,7 @@
#include <iostream>
#include "Display.h"
#include "Point.h"
//#include "Point.h"
//#include "Line.h"
#include "Triangle.h"

View File

@ -1,10 +1,7 @@
#include <iostream> // cin, cout
#include <fstream> // ifstream
#include <cstdlib> // srand, rand
#include <ctime> // time
#include <cstring> // strcmp
#include <vector> // TODO: or use arrays for maximum performance?
#include <list> // TODO: replace vector with list for easier insertion!
#include <vector>
#include <list> // TODO: replace vector in Display with list for easier insertion!
#include "Display.h"
#include "NumberGenerator.h"
@ -26,7 +23,7 @@ int main (int argc, char **argv)
// -stepsize <size> time between autosteps; if 0 or not provided -> manual steps
// TODO: care a little more <3
int stepSize = 0;
int valCount = 1000000;
int valCount = 100;
int rngMode = 1;
std::string fileRnd = "";
bool vis = false;
@ -34,67 +31,30 @@ int main (int argc, char **argv)
for (int i = 0; i < argc; ++i)
{
if (strcmp(argv[i], "-v") == 0) vis = true;
else if (strcmp(argv[i], "-akl") == 0) akl = true;
else if (strcmp(argv[i], "-stepsize") == 0) stepSize = std::stoi(argv[i + 1]);
else if (strcmp(argv[i], "--akl") == 0) akl = true;
else if (strcmp(argv[i], "--stepsize") == 0) stepSize = std::stoi(argv[i + 1]);
else if (strcmp(argv[i], "-f") == 0) fileRnd = argv[i + 1];
else if (strcmp(argv[i], "-rngCount") == 0) valCount = std::stoi(argv[i + 1]);
else if (strcmp(argv[i], "-rngMode") == 0) rngMode = std::stoi(argv[i + 1]);
else if (strcmp(argv[i], "--rngcount") == 0) valCount = std::stoi(argv[i + 1]);
else if (strcmp(argv[i], "--rngmode") == 0) rngMode = std::stoi(argv[i + 1]);
}
std::list<Point> points;
if (fileRnd.empty()) // generate random numbers
{
std::cout << "generating " << valCount << " random numbers for mode " << rngMode << "..." << std::endl;
if (rngMode == 1)
{
points = NumberGenerator::get_random_numbers(valCount);
points = NumberGenerator::generate_numbers(valCount, rngMode);
}
else if (rngMode == 2)
{
points = NumberGenerator::get_rectangle_numbers(valCount);
}
else if (rngMode == 3)
{
points = NumberGenerator::get_circle_numbers(valCount);
}
else throw "unspecified rng Mode"; // TODO: could handle in parse args
}
// TODO: move into NumberGenerator?
else // read random numbers
{
std::cout << "reading random numbers from file: " << fileRnd << "..." << std::endl;
std::ifstream in(fileRnd.c_str());
if (in.is_open())
{
std::string line;
std::getline(in, line); // get first line for explizit valueCount
valCount = std::stoi(line);
float x = 0;
float y = 0;
for (int i = 0; i < valCount; ++i)
{
getline(in, line);
//getline(in, line, ','); // could also be used slightly different but includes newlines :/
size_t pos = line.find(',');
if (pos != std::string::npos)
{
x = std::stof(line.substr(0, pos));
y = std::stof(line.substr(pos + 1));
points.push_back(Point(x, y));
}
else
{
throw "invalid format!";
}
}
}
points = NumberGenerator::read_numbers(fileRnd);
}
#ifdef _DEBUG
/*for (Point& pt : points)
for (Point& pt : points)
{
std::cout << "pt: " << pt.x() << ", " << pt.y() << std::endl;
}*/
}
#endif
// TEST to check SFML coordinate system