Compare commits
3 Commits
1c73b14f24
...
c6ea56a0a4
Author | SHA1 | Date | |
---|---|---|---|
c6ea56a0a4 | |||
0f0c2f8968 | |||
617ecaba91 |
@ -350,7 +350,7 @@ bool less (sf::CircleShape a, sf::CircleShape b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compute the cross product of vectors (center -> a) x (center -> 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)
|
if (det < 0)
|
||||||
return true;
|
return true;
|
||||||
if (det > 0)
|
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
|
// points a and b are on the same line from the center
|
||||||
// check which point is closer to the center
|
// check which point is closer to the center
|
||||||
int d1 = (ax - centerx) * (ax - centerx) + (ay - centery) * (ay - centery);
|
int d1 = (int)((ax - centerx) * (ax - centerx) + (ay - centery) * (ay - centery));
|
||||||
int d2 = (bx - centerx) * (bx - centerx) + (by - centery) * (by - centery);
|
int d2 = (int)((bx - centerx) * (bx - centerx) + (by - centery) * (by - centery));
|
||||||
return d1 > d2;
|
return d1 > d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ private:
|
|||||||
//std::list<Line> m_lines;
|
//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 = nullptr; // get any value if the underlying vector gets resized and moved in memory
|
||||||
Line m_curLine; // -> either make a copy
|
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;
|
unsigned int m_step = 0;
|
||||||
void update();
|
void update();
|
||||||
|
@ -1,12 +1,60 @@
|
|||||||
#include "Point.h"
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cstdlib> // for srand, rand
|
#include <cstdlib> // for srand, rand
|
||||||
|
#include <fstream> // ifstream
|
||||||
|
#include <ctime> // time
|
||||||
|
|
||||||
class NumberGenerator
|
class NumberGenerator
|
||||||
{
|
{
|
||||||
public:
|
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;
|
std::list<Point> points;
|
||||||
|
|
||||||
@ -26,7 +74,7 @@ public:
|
|||||||
return points;
|
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;
|
std::list<Point> points;
|
||||||
|
|
||||||
@ -45,7 +93,7 @@ public:
|
|||||||
return points;
|
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;
|
std::list<Point> points;
|
||||||
|
|
||||||
@ -61,7 +109,6 @@ public:
|
|||||||
|
|
||||||
points.push_back(Point(x, y));
|
points.push_back(Point(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -7,7 +7,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Display.h"
|
#include "Display.h"
|
||||||
#include "Point.h"
|
//#include "Point.h"
|
||||||
//#include "Line.h"
|
//#include "Line.h"
|
||||||
#include "Triangle.h"
|
#include "Triangle.h"
|
||||||
|
|
||||||
|
62
main.cpp
62
main.cpp
@ -1,10 +1,7 @@
|
|||||||
#include <iostream> // cin, cout
|
#include <iostream> // cin, cout
|
||||||
#include <fstream> // ifstream
|
|
||||||
#include <cstdlib> // srand, rand
|
|
||||||
#include <ctime> // time
|
|
||||||
#include <cstring> // strcmp
|
#include <cstring> // strcmp
|
||||||
#include <vector> // TODO: or use arrays for maximum performance?
|
#include <vector>
|
||||||
#include <list> // TODO: replace vector with list for easier insertion!
|
#include <list> // TODO: replace vector in Display with list for easier insertion!
|
||||||
|
|
||||||
#include "Display.h"
|
#include "Display.h"
|
||||||
#include "NumberGenerator.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
|
// -stepsize <size> time between autosteps; if 0 or not provided -> manual steps
|
||||||
// TODO: care a little more <3
|
// TODO: care a little more <3
|
||||||
int stepSize = 0;
|
int stepSize = 0;
|
||||||
int valCount = 1000000;
|
int valCount = 100;
|
||||||
int rngMode = 1;
|
int rngMode = 1;
|
||||||
std::string fileRnd = "";
|
std::string fileRnd = "";
|
||||||
bool vis = false;
|
bool vis = false;
|
||||||
@ -34,67 +31,30 @@ int main (int argc, char **argv)
|
|||||||
for (int i = 0; i < argc; ++i)
|
for (int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (strcmp(argv[i], "-v") == 0) vis = true;
|
if (strcmp(argv[i], "-v") == 0) vis = true;
|
||||||
else if (strcmp(argv[i], "-akl") == 0) akl = 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], "--stepsize") == 0) stepSize = std::stoi(argv[i + 1]);
|
||||||
else if (strcmp(argv[i], "-f") == 0) fileRnd = 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], "--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], "--rngmode") == 0) rngMode = std::stoi(argv[i + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Point> points;
|
std::list<Point> points;
|
||||||
if (fileRnd.empty()) // generate random numbers
|
if (fileRnd.empty()) // generate random numbers
|
||||||
{
|
{
|
||||||
std::cout << "generating " << valCount << " random numbers for mode " << rngMode << "..." << std::endl;
|
std::cout << "generating " << valCount << " random numbers for mode " << rngMode << "..." << std::endl;
|
||||||
if (rngMode == 1)
|
points = NumberGenerator::generate_numbers(valCount, rngMode);
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
|
||||||
// TODO: move into NumberGenerator?
|
|
||||||
else // read random numbers
|
else // read random numbers
|
||||||
{
|
{
|
||||||
std::cout << "reading random numbers from file: " << fileRnd << "..." << std::endl;
|
std::cout << "reading random numbers from file: " << fileRnd << "..." << std::endl;
|
||||||
std::ifstream in(fileRnd.c_str());
|
points = NumberGenerator::read_numbers(fileRnd);
|
||||||
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!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
/*for (Point& pt : points)
|
for (Point& pt : points)
|
||||||
{
|
{
|
||||||
std::cout << "pt: " << pt.x() << ", " << pt.y() << std::endl;
|
std::cout << "pt: " << pt.x() << ", " << pt.y() << std::endl;
|
||||||
}*/
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TEST to check SFML coordinate system
|
// TEST to check SFML coordinate system
|
||||||
|
Loading…
x
Reference in New Issue
Block a user