diff --git a/NumberGenerator.h b/NumberGenerator.h index 92861f7..6cb6d7a 100644 --- a/NumberGenerator.h +++ b/NumberGenerator.h @@ -1,12 +1,60 @@ -#include "Point.h" - #include #include // for srand, rand +#include // ifstream +#include // time class NumberGenerator { public: - static std::list get_random_numbers(int valCount) + static std::list 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 read_numbers(const std::string &fileRnd) + { + std::list 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 get_random_numbers (const int valCount) { std::list points; @@ -26,7 +74,7 @@ public: return points; } - static std::list get_rectangle_numbers(int valCount) + static std::list get_rectangle_numbers (const int valCount) { std::list points; @@ -45,7 +93,7 @@ public: return points; } - static std::list get_circle_numbers(int valCount) + static std::list get_circle_numbers (const int valCount) { std::list points; @@ -61,7 +109,6 @@ public: points.push_back(Point(x, y)); } - return points; } }; \ No newline at end of file diff --git a/Quickhull.h b/Quickhull.h index 4b76fbb..109a8be 100644 --- a/Quickhull.h +++ b/Quickhull.h @@ -7,7 +7,7 @@ #include #include "Display.h" -#include "Point.h" +//#include "Point.h" //#include "Line.h" #include "Triangle.h" diff --git a/main.cpp b/main.cpp index 02d42c0..8382b46 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,7 @@ #include // cin, cout -#include // ifstream -#include // srand, rand -#include // time #include // strcmp -#include // TODO: or use arrays for maximum performance? -#include // TODO: replace vector with list for easier insertion! +#include +#include // 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 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 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); - } - 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 + points = NumberGenerator::generate_numbers(valCount, rngMode); } - // 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