diff --git a/Makefile b/Makefile index 6ea65ec..f419673 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ CXX = g++ CXXFLAGS = -Wall -O3 -g +SFMLFLAGS = -lsfml-system -lsfml-window -lsfml-graphics # In case you installed SFML to a non-standard path, you'll need to tell the compiler where to find the SFML headers (.hpp files): # g++ -c main.cpp -I/include @@ -9,10 +10,10 @@ CXXFLAGS = -Wall -O3 -g quickhull: main.o Quickhull.h Point.h Line.h Triangle.h Timing.o Display.o # link with sfml libs; -lsfml-network -lsfml-audio currently not needed - $(CXX) $(CXXFLAGS) -o quickhull main.o Quickhull.h Point.h Line.h Triangle.h Timing.o Display.o -lsfml-system -lsfml-window -lsfml-graphics + $(CXX) $(CXXFLAGS) -o quickhull main.o Quickhull.h Point.h Line.h Triangle.h Timing.o Display.o $(SFMLFLAGS) -performance: performance.cpp - $(CXX) $(CXXFLAGS) -o performance performance.cpp +performance: performance.cpp Display.o + $(CXX) $(CXXFLAGS) -o performance Display.o performance.cpp $(SFMLFLAGS) main.o: main.cpp Timing.h $(CXX) $(CXXFLAGS) -c main.cpp diff --git a/performance.cpp b/performance.cpp index a813f5e..dff3f97 100644 --- a/performance.cpp +++ b/performance.cpp @@ -1,22 +1,56 @@ #include "Quickhull.h" +#include "NumberGenerator.h" +#include "Display.h" int main() { - std::list points = { - Point(1, 1), - Point(-1, -1), - Point(-1, 1), - Point(1, -1), - Point(0.5, 0) // Should not be in the hull - }; + std::list points = NumberGenerator::get_circle_numbers(500); std::list hull; Quickhull::get_hull(points, hull); - for (const Point &point : hull) + // create the window + sf::RenderWindow window(sf::VideoMode(800, 800), "k-d-tree"); + + sf::CircleShape normal_p(2); + normal_p.setFillColor(sf::Color(250, 250, 250)); + + sf::CircleShape hull_p(2); + hull_p.setFillColor(sf::Color(250, 100, 50)); + + // run the program as long as the window is open + while (window.isOpen()) { - std::cout << point.x() << ", " << point.y() << std::endl; + // check all the window's events that were triggered since the last iteration of the loop + sf::Event event; + while (window.pollEvent(event)) + { + // "close requested" event: we close the window + if (event.type == sf::Event::Closed) + window.close(); + } + + // clear the window with black color + window.clear(sf::Color::Black); + + // Draw all points + for (const Point &point : points) + { + normal_p.setPosition(point.x() + 50, point.y() + 50); + window.draw(normal_p); + } + + // Draw hull points + for (const Point &point : hull) + { + hull_p.setPosition(point.x() + 50, point.y() + 50); + window.draw(hull_p); + } + + // end the current frame + window.display(); } + return 0; } \ No newline at end of file