2020-11-18 18:01:57 +01:00
# include <iostream>
2020-11-26 22:17:36 +01:00
# include <chrono>
# include <thread>
2020-11-18 18:01:57 +01:00
# include "Display.h"
2020-11-19 09:46:02 +01:00
# include "Point.h"
2020-11-26 22:17:36 +01:00
# include "Utility.h"
2020-11-18 18:01:57 +01:00
2020-11-30 15:43:42 +01:00
Display : : Display ( const std : : vector < Point > & pts , int stepSize , bool akl ) : m_stepSize ( stepSize ) , m_useAkl ( akl )
2020-11-26 22:17:36 +01:00
{
2020-11-29 04:04:25 +01:00
if ( ! m_font . loadFromFile ( " Resources/LiberationSans-Regular.ttf " ) )
2020-11-26 22:17:36 +01:00
{
2020-11-28 23:30:31 +01:00
std : : cerr < < " font LiberationSans-Regular.ttf could not be loaded! " < < std : : endl ;
2020-11-26 22:17:36 +01:00
}
m_textStatus . setPosition ( OFFSET , HEIGHT - 2 * OFFSET ) ;
m_textStatus . setFont ( m_font ) ;
m_textStatus . setString ( " initializing... " ) ;
m_textStatus . setCharacterSize ( 12 ) ;
m_textStatus . setFillColor ( sf : : Color : : Black ) ;
2020-11-27 03:09:50 +01:00
size_t points = pts . size ( ) ;
for ( size_t i = 0 ; i < points ; + + i )
{
const Point & pt = pts [ i ] ;
sf : : CircleShape shape ( OFFSET ) ;
shape . setOrigin ( OFFSET , OFFSET ) ;
shape . setPosition ( pt . x ( ) , pt . y ( ) ) ;
shape . setFillColor ( sf : : Color : : Green ) ;
shape . setOutlineThickness ( 1.f ) ;
shape . setOutlineColor ( sf : : Color : : Black ) ;
m_points . push_back ( shape ) ;
sf : : Text label ;
label . setOrigin ( OFFSET / 2 - 1 , OFFSET / 2 + 3 ) ;
label . setPosition ( pt . x ( ) , pt . y ( ) ) ;
label . setFont ( m_font ) ;
label . setString ( std : : to_string ( i ) ) ;
label . setCharacterSize ( 12 ) ;
label . setFillColor ( sf : : Color : : Black ) ;
m_labels . push_back ( label ) ;
}
2020-11-26 22:17:36 +01:00
}
// multiple options possible:
// a) draw every frame, using elapsed time for updates
// --> not really needed because we have no animations... also uses a lot of performance
// b) checking every frame if elapsed time since last tick is larger than a specified offset, then draw the field
// --> mostly doing nothing but still uses a lot of performance O_o
// c) just start a simple (c++11 <3) non-busy sleep
// --> may delay user input / events but don't care atm :p
2020-11-18 18:01:57 +01:00
void Display : : show ( )
{
2020-11-26 22:17:36 +01:00
sf : : ContextSettings settings ;
2020-11-27 03:09:50 +01:00
settings . antialiasingLevel = 8 ;
2020-11-26 22:17:36 +01:00
sf : : RenderWindow window ( sf : : VideoMode ( WIDTH , HEIGHT ) , " ALGO Prog2: Quickhull - visualization " , sf : : Style : : Default , settings ) ;
2020-11-27 03:09:50 +01:00
/* b)
window . setFramerateLimit ( 0.2 ) ;
2020-11-26 22:17:36 +01:00
2020-11-27 03:09:50 +01:00
sf : : Clock clock ;
sf : : Time frameTime = sf : : seconds ( 2 ) ; //sf::seconds(1.f / 60.f)
sf : : Time timeSinceLastUpdate = frameTime ; //sf::Time::Zero;*/
2020-11-18 18:01:57 +01:00
while ( window . isOpen ( ) )
{
sf : : Event event ;
while ( window . pollEvent ( event ) )
{
if ( event . type = = sf : : Event : : Closed )
window . close ( ) ;
}
2020-11-27 03:09:50 +01:00
// a)
//update(elapsed);
//render(window);
2020-11-26 22:17:36 +01:00
/* b)
timeSinceLastUpdate + = clock . restart ( ) ;
// only handle every few seconds because we need no animations
2020-11-27 03:09:50 +01:00
if ( timeSinceLastUpdate > = frameTime )
2020-11-26 22:17:36 +01:00
{
2020-11-27 03:09:50 +01:00
std : : cout < < " entering update and render " < < std : : endl ;
2020-11-26 22:17:36 +01:00
// start by getting the most left and right point
timeSinceLastUpdate - = frameTime ;
2020-11-27 03:09:50 +01:00
update ( ) ;
render ( window ) ;
} */
2020-11-26 22:17:36 +01:00
// c)
2020-11-27 03:09:50 +01:00
// choose a simple sleep
update ( ) ;
render ( window ) ;
2020-11-29 14:51:55 +01:00
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( m_stepSize ) ) ;
2020-11-26 22:17:36 +01:00
}
}
2020-11-30 17:02:52 +01:00
void Display : : setCurrentLine ( )
{
while ( m_curLineIdx = = - 1 )
{
size_t lines = m_lines . size ( ) ;
if ( lines < 1 ) // no more open lines -> fin
{
std : : cout < < " ## no more open lines -> fin! " < < std : : endl ;
m_points . clear ( ) ;
if ( m_points . size ( ) = = 0 )
{
unsigned int curStep = ( m_step > 5 ) ? ( ( m_step - 2 ) % 4 + 2 ) : ( m_step % 6 ) ; // skip init and first step after first run
std : : string text = " ( " + std : : to_string ( m_step ) + " ) step " + std : : to_string ( curStep ) + " : " ;
m_textStatus . setString ( text + " finished calculating convex hull in " + std : : to_string ( ( m_step / 4 + 1 ) ) + " cycles " ) ;
}
return ;
}
Line cand = m_lines [ lines - 1 ] ;
int positives = 0 ;
for ( auto & pt : m_points )
{
if ( cand . is_point_right ( Point ( pt . getPosition ( ) . x , pt . getPosition ( ) . y ) ) )
{
positives + + ;
break ; // sufficient as candidate if at least one point is right
}
2020-11-30 18:08:26 +01:00
/*if (sign(pt.getPosition().x, pt.getPosition().y,
cand . from ( ) . x ( ) , cand . from ( ) . y ( ) ,
cand . to ( ) . x ( ) , cand . to ( ) . y ( ) ) > 0 )
{
positives + + ;
break ; // sufficient as candidate if at least one point is right
} */
2020-11-30 17:02:52 +01:00
}
if ( positives > 0 )
{
m_curLineIdx = lines - 1 ;
m_curLine = m_lines [ lines - 1 ] ;
2020-11-30 18:08:26 +01:00
std : : cout < < " selecting last line of " < < lines < < " : " < <
m_curLine . from ( ) . x ( ) < < " , " < < m_curLine . from ( ) . y ( ) < < " - " < <
m_curLine . to ( ) . x ( ) < < " , " < < m_curLine . to ( ) . y ( ) < < std : : endl ;
2020-11-30 17:02:52 +01:00
}
else
{
m_lines . pop_back ( ) ;
}
}
for ( auto & pt : m_points )
{
pt . setFillColor ( sign (
pt . getPosition ( ) . x , pt . getPosition ( ) . y ,
m_lines [ m_curLineIdx ] . from ( ) . x ( ) , m_lines [ m_curLineIdx ] . from ( ) . y ( ) ,
m_lines [ m_curLineIdx ] . to ( ) . x ( ) , m_lines [ m_curLineIdx ] . to ( ) . y ( ) ) > 0 ? sf : : Color : : Red : sf : : Color : : Green ) ;
}
}
2020-11-27 03:09:50 +01:00
void Display : : update ( )
2020-11-26 22:17:36 +01:00
{
2020-11-27 03:09:50 +01:00
unsigned int curStep = ( m_step > 5 ) ? ( ( m_step - 2 ) % 4 + 2 ) : ( m_step % 6 ) ; // skip init and first step after first run
2020-11-29 23:32:54 +01:00
if ( m_stepSize = = 0 & & curStep > 0 )
{
std : : cout < < " any key to continue with next step... " ;
std : : cin . get ( ) ;
}
2020-11-27 03:09:50 +01:00
std : : string text = " ( " + std : : to_string ( m_step ) + " ) step " + std : : to_string ( curStep ) + " : " ;
if ( curStep = = 1 )
2020-11-26 22:17:36 +01:00
{
// first step: select min - max x coordinates
2020-11-27 03:09:50 +01:00
m_textStatus . setString ( text + " select min - max x coordinates... " ) ;
// if use Akl<6B> Toussaint heuristic
2020-11-30 15:43:42 +01:00
if ( m_useAkl )
2020-11-27 03:09:50 +01:00
{
2020-11-30 17:02:52 +01:00
sf : : Vector2f left ( WIDTH , HEIGHT ) ;
sf : : Vector2f right ( 0 , HEIGHT ) ;
sf : : Vector2f bot ( 0 , 0 ) ;
sf : : Vector2f top ( 0 , HEIGHT ) ;
2020-11-27 03:09:50 +01:00
2020-11-30 17:02:52 +01:00
// index to find points
int i_left = WIDTH ;
int i_right = 0 ;
int i_top = HEIGHT ;
int i_bot = 0 ;
size_t points = m_points . size ( ) ;
for ( size_t i = 0 ; i < points ; + + i )
2020-11-27 03:09:50 +01:00
{
2020-11-30 17:02:52 +01:00
sf : : Vector2f pos = m_points [ i ] . getPosition ( ) ;
2020-11-27 03:09:50 +01:00
float x = pos . x ;
float y = pos . y ;
2020-11-30 17:02:52 +01:00
if ( x < left . x )
{
left = pos ;
i_left = i ;
}
if ( x > right . x )
{
right = pos ;
i_right = i ;
}
if ( y < top . y )
{
top = pos ;
i_top = i ;
}
if ( y > bot . y )
{
bot = pos ;
i_bot = i ;
}
}
2020-11-30 18:08:26 +01:00
std : : cout < < " right: " < < right . x < < " , " < < right . y < < std : : endl ;
std : : cout < < " top: " < < top . x < < " , " < < top . y < < std : : endl ;
std : : cout < < " left: " < < left . x < < " , " < < left . y < < std : : endl ;
std : : cout < < " bot: " < < bot . x < < " , " < < bot . y < < std : : endl ;
2020-11-30 17:02:52 +01:00
// adding edge points to hull
m_points [ i_left ] . setFillColor ( sf : : Color : : Blue ) ;
m_hullPoints . push_back ( m_points [ i_left ] ) ;
m_points [ i_top ] . setFillColor ( sf : : Color : : Blue ) ;
m_hullPoints . push_back ( m_points [ i_top ] ) ;
m_points [ i_right ] . setFillColor ( sf : : Color : : Blue ) ;
m_hullPoints . push_back ( m_points [ i_right ] ) ;
m_points [ i_bot ] . setFillColor ( sf : : Color : : Blue ) ;
m_hullPoints . push_back ( m_points [ i_bot ] ) ;
// building lines between edge points
2020-11-30 18:08:26 +01:00
// hull points shall be clockwise, but lines have to be counterclockwise
// because only checking elems right of lines
Point pt1 ( right . x , right . y ) ;
2020-11-30 17:02:52 +01:00
Point pt2 ( top . x , top . y ) ;
2020-11-30 18:08:26 +01:00
Point pt3 ( left . x , left . y ) ;
2020-11-30 17:02:52 +01:00
Point pt4 ( bot . x , bot . y ) ;
m_lines . push_back ( Line ( pt1 , pt2 ) ) ;
m_lines . push_back ( Line ( pt2 , pt3 ) ) ;
m_lines . push_back ( Line ( pt3 , pt4 ) ) ;
m_lines . push_back ( Line ( pt4 , pt1 ) ) ;
// remove points in calculated rectangle
for ( int i = points - 1 ; i > = 0 ; i - - )
{
Point pt ( m_points [ i ] . getPosition ( ) . x , m_points [ i ] . getPosition ( ) . y ) ;
if ( IsPointInRectangle ( pt , pt1 , pt2 , pt3 , pt4 ) )
{
std : : cout < < " remove pt inside triangle -> " < < i < < " with pos: " < < pt . x ( ) < < " , " < < pt . y ( ) < < std : : endl ;
m_points . erase ( m_points . begin ( ) + i ) ;
}
// TODO: ugly workaround - remove hull points
else if ( ( pt . x ( ) = = pt1 . x ( ) & & pt . y ( ) = = pt1 . y ( ) ) | |
( pt . x ( ) = = pt2 . x ( ) & & pt . y ( ) = = pt2 . y ( ) ) | |
( pt . x ( ) = = pt3 . x ( ) & & pt . y ( ) = = pt3 . y ( ) ) | |
( pt . x ( ) = = pt4 . x ( ) & & pt . y ( ) = = pt4 . y ( ) ) )
{
m_points . erase ( m_points . begin ( ) + i ) ;
}
2020-11-27 03:09:50 +01:00
}
2020-11-30 18:08:26 +01:00
//setCurrentLine(); // set current line in next step
2020-11-27 03:09:50 +01:00
}
else
{
sf : : Vector2f left ( WIDTH , HEIGHT ) ;
sf : : Vector2f right ( 0 , 0 ) ;
2020-11-29 23:32:54 +01:00
int i_left = WIDTH ;
int i_right = 0 ;
size_t points = m_points . size ( ) ;
for ( size_t i = 0 ; i < points ; + + i )
2020-11-27 03:09:50 +01:00
{
2020-11-29 23:32:54 +01:00
sf : : Vector2f pos = m_points [ i ] . getPosition ( ) ;
2020-11-27 03:09:50 +01:00
float x = pos . x ;
2020-11-29 23:32:54 +01:00
if ( x < left . x )
{
i_left = i ;
left = pos ;
}
if ( x > right . x )
{
i_right = i ;
right = pos ;
}
2020-11-27 03:09:50 +01:00
}
2020-11-30 17:02:52 +01:00
// TODO: split points and use map
2020-11-29 23:32:54 +01:00
// adding starting points from most x to left
if ( i_left < i_right )
{
std : : swap ( i_left , i_right ) ;
}
for ( int i = 0 ; i < 2 ; + + i )
{
2020-11-30 17:02:52 +01:00
int idx = ( i = = 0 ) ? i_left : i_right ;
m_points [ idx ] . setFillColor ( sf : : Color : : Blue ) ;
m_hullPoints . push_back ( m_points [ idx ] ) ;
m_points . erase ( m_points . begin ( ) + idx ) ;
2020-11-29 23:32:54 +01:00
}
2020-11-29 04:04:25 +01:00
m_lines . push_back ( Line ( Point ( left . x , left . y ) , Point ( right . x , right . y ) ) ) ;
m_lines . push_back ( Line ( Point ( right . x , right . y ) , Point ( left . x , left . y ) ) ) ; // add first line in both directions to work with "right side"
2020-11-30 17:02:52 +01:00
// set current line just by taking the only one (in one direction)
2020-11-29 23:32:54 +01:00
m_curLineIdx = 1 ;
m_curLine = m_lines [ 1 ] ;
2020-11-27 03:09:50 +01:00
}
2020-11-26 22:17:36 +01:00
}
2020-11-27 03:09:50 +01:00
else if ( curStep = = 2 )
2020-11-26 22:17:36 +01:00
{
2020-11-29 04:04:25 +01:00
// second step: split board
m_textStatus . setString ( text + " split board... " ) ;
2020-11-29 23:32:54 +01:00
// get current line with points
2020-11-30 17:02:52 +01:00
setCurrentLine ( ) ;
2020-11-18 18:01:57 +01:00
}
2020-11-27 03:09:50 +01:00
else if ( curStep = = 3 )
2020-11-26 22:17:36 +01:00
{
2020-11-29 04:04:25 +01:00
// get line with more than one point -> or use m_curLine
// calc furthest point
// create new lines
2020-11-26 22:17:36 +01:00
// third step: draw triangle, remove inner points
2020-11-27 03:09:50 +01:00
m_textStatus . setString ( text + " find furthest point and draw triangle... " ) ;
2020-11-27 03:48:34 +01:00
2020-11-29 23:32:54 +01:00
sf : : Vector2f pos ;
2020-11-27 03:48:34 +01:00
float maxDistance = 0 ;
2020-11-29 23:32:54 +01:00
int i_cand = 0 ;
size_t points = m_points . size ( ) ;
for ( size_t i = 0 ; i < points ; + + i )
2020-11-27 03:48:34 +01:00
{
2020-11-29 23:32:54 +01:00
if ( m_points [ i ] . getFillColor ( ) = = sf : : Color : : Green ) continue ;
2020-11-29 04:04:25 +01:00
2020-11-29 23:32:54 +01:00
sf : : Vector2f cand = m_points [ i ] . getPosition ( ) ;
2020-11-30 00:39:15 +01:00
float distance = m_lines [ m_curLineIdx ] . distance_squared_to ( Point ( cand . x , cand . y ) ) ;
2020-11-27 03:48:34 +01:00
if ( distance > maxDistance )
{
2020-11-29 23:32:54 +01:00
i_cand = i ;
pos = cand ;
2020-11-27 03:48:34 +01:00
maxDistance = distance ;
}
}
if ( maxDistance > 0 )
{
2020-11-29 23:32:54 +01:00
// move point from all points to hull points
m_points [ i_cand ] . setFillColor ( sf : : Color : : Blue ) ;
m_hullPoints . push_back ( m_points [ i_cand ] ) ;
std : : cout < < " removing pt " < < m_points [ i_cand ] . getPosition ( ) . x < < " , " < < m_points [ i_cand ] . getPosition ( ) . y < < " at index " < < std : : to_string ( i_cand ) < < " after inserted to hullpoints " < < std : : endl ;
m_points . erase ( m_points . begin ( ) + i_cand ) ;
Point to = m_lines [ m_curLineIdx ] . to ( ) ;
Point from = m_lines [ m_curLineIdx ] . from ( ) ;
m_lines . push_back ( Line ( Point ( pos . x , pos . y ) , to ) ) ;
m_lines [ m_lines . size ( ) - 2 ] = Line ( from , Point ( pos . x , pos . y ) ) ; // updates list entry
2020-11-29 04:04:25 +01:00
}
else
{
m_lines . pop_back ( ) ; // remove last element -> TODO: directly use stack?
2020-11-27 03:48:34 +01:00
}
2020-11-26 22:17:36 +01:00
}
2020-11-27 03:09:50 +01:00
else if ( curStep = = 4 )
2020-11-26 22:17:36 +01:00
{
// fourth step: remove inner points
2020-11-27 03:09:50 +01:00
m_textStatus . setString ( text + " remove inner points... " ) ;
2020-11-29 04:04:25 +01:00
2020-11-29 23:32:54 +01:00
size_t lines = m_lines . size ( ) - 1 ;
2020-11-30 00:23:21 +01:00
if ( lines > 0 )
2020-11-29 04:04:25 +01:00
{
2020-11-29 23:32:54 +01:00
// assure clockwise order
Point pt1 = m_lines [ lines - 1 ] . from ( ) ;
Point pt2 = m_lines [ lines - 1 ] . to ( ) ;
Point pt3 = m_lines [ lines ] . to ( ) ;
if ( sign ( pt2 , pt1 , pt3 ) > 0 )
2020-11-29 04:04:25 +01:00
{
2020-11-29 23:32:54 +01:00
std : : swap ( pt1 , pt2 ) ;
2020-11-29 04:04:25 +01:00
}
2020-11-29 23:32:54 +01:00
size_t points = m_points . size ( ) ;
for ( int i = points - 1 ; i > = 0 ; i - - )
{
Point pt ( m_points [ i ] . getPosition ( ) . x , m_points [ i ] . getPosition ( ) . y ) ;
if ( IsPointInTriangle ( pt , pt1 , pt2 , pt3 ) )
{
std : : cout < < " remove pt inside triangle -> " < < i < < " with pos: " < < pt . x ( ) < < " , " < < pt . y ( ) < < std : : endl ;
m_points . erase ( m_points . begin ( ) + i ) ;
}
else
{
m_points [ i ] . setFillColor ( sf : : Color : : Green ) ;
}
}
}
//m_curLine = nullptr;
//m_curLineIdx = -1;
2020-11-26 22:17:36 +01:00
}
2020-11-27 03:09:50 +01:00
else if ( curStep = = 5 )
2020-11-26 22:17:36 +01:00
{
2020-11-27 03:09:50 +01:00
// fifth step: adding new hull point
2020-11-26 22:17:36 +01:00
2020-11-29 23:32:54 +01:00
m_curLineIdx = - 1 ;
//m_curLine = m_lines[lines - 1];
2020-11-27 03:09:50 +01:00
2020-11-30 00:23:21 +01:00
if ( m_points . size ( ) = = 0 ) m_textStatus . setString ( text + " finished calculating convex hull in " + std : : to_string ( ( m_step / 4 + 1 ) ) + " cycles " ) ;
2020-11-27 03:09:50 +01:00
else m_textStatus . setString ( text + " adding new hull point... " ) ;
2020-11-26 22:17:36 +01:00
}
2020-11-29 14:51:55 +01:00
else if ( m_step > 0 ) m_textStatus . setString ( text + " invalid status! " ) ;
2020-11-27 03:09:50 +01:00
if ( curStep ! = 5 | | m_points . size ( ) > 0 ) m_step + + ;
2020-11-19 09:46:02 +01:00
}
2020-11-29 23:48:18 +01:00
bool less ( sf : : CircleShape a , sf : : CircleShape b )
{
float centerx = WIDTH / 2 ;
float centery = HEIGHT / 2 ;
float ax = a . getPosition ( ) . x ;
float ay = a . getPosition ( ) . y ;
float bx = b . getPosition ( ) . x ;
float by = b . getPosition ( ) . y ;
if ( ax - centerx > = 0 & & bx - centerx < 0 )
return true ;
if ( ax - centerx < 0 & & bx - centerx > = 0 )
return false ;
if ( ax - centerx = = 0 & & bx - centerx = = 0 ) {
if ( ay - centery > = 0 | | by - centery > = 0 )
return ay > by ;
return by > ay ;
}
// compute the cross product of vectors (center -> a) x (center -> b)
2020-11-30 16:06:30 +01:00
int det = ( int ) ( ( ax - centerx ) * ( by - centery ) - ( bx - centerx ) * ( ay - centery ) ) ;
2020-11-29 23:48:18 +01:00
if ( det < 0 )
return true ;
if ( det > 0 )
return false ;
// points a and b are on the same line from the center
// check which point is closer to the center
2020-11-30 16:06:30 +01:00
int d1 = ( int ) ( ( ax - centerx ) * ( ax - centerx ) + ( ay - centery ) * ( ay - centery ) ) ;
int d2 = ( int ) ( ( bx - centerx ) * ( bx - centerx ) + ( by - centery ) * ( by - centery ) ) ;
2020-11-29 23:48:18 +01:00
return d1 > d2 ;
}
2020-11-27 03:09:50 +01:00
void Display : : render ( sf : : RenderWindow & window )
2020-11-19 09:46:02 +01:00
{
2020-11-27 03:09:50 +01:00
window . clear ( sf : : Color : : White ) ;
2020-11-29 23:32:54 +01:00
// draw already calculated hull points
2020-11-29 23:48:18 +01:00
std : : sort ( m_hullPoints . begin ( ) , m_hullPoints . end ( ) , less ) ; // sort clockwise
2020-11-29 23:32:54 +01:00
size_t elements = m_hullPoints . size ( ) ;
for ( size_t i = 0 ; i < elements ; + + i )
2020-11-27 03:09:50 +01:00
{
2020-11-29 23:32:54 +01:00
window . draw ( m_hullPoints [ i ] ) ;
2020-11-29 14:51:55 +01:00
2020-11-29 23:32:54 +01:00
sf : : Vertex ptTo ;
if ( i < elements - 1 ) ptTo = sf : : Vertex ( m_hullPoints [ i + 1 ] . getPosition ( ) , sf : : Color : : Blue ) ;
else ptTo = sf : : Vertex ( m_hullPoints [ 0 ] . getPosition ( ) , sf : : Color : : Blue ) ;
sf : : Vertex line [ ] = { sf : : Vertex ( sf : : Vector2f ( m_hullPoints [ i ] . getPosition ( ) ) , sf : : Color : : Blue ) , ptTo } ;
2020-11-27 03:09:50 +01:00
2020-11-29 23:32:54 +01:00
window . draw ( line , 2 , sf : : Lines ) ;
2020-11-29 04:04:25 +01:00
}
// always print remaining points
2020-11-29 23:32:54 +01:00
elements = m_points . size ( ) ;
for ( size_t i = 0 ; i < elements ; + + i )
2020-11-27 03:09:50 +01:00
{
window . draw ( m_points [ i ] ) ;
2020-11-29 23:32:54 +01:00
}
// seperately print labels for points
elements = m_labels . size ( ) ;
for ( size_t i = 0 ; i < elements ; + + i )
{
2020-11-27 03:09:50 +01:00
window . draw ( m_labels [ i ] ) ;
}
2020-11-29 04:04:25 +01:00
// draw line the algorithm is currently working on
2020-11-29 23:32:54 +01:00
if ( m_curLineIdx ! = - 1 )
2020-11-27 03:09:50 +01:00
{
2020-11-29 04:04:25 +01:00
sf : : Vertex line [ ] =
{
2020-11-29 23:32:54 +01:00
sf : : Vertex ( sf : : Vector2f ( m_curLine . from ( ) . x ( ) , m_curLine . from ( ) . y ( ) ) , sf : : Color : : Red ) ,
sf : : Vertex ( sf : : Vector2f ( m_curLine . to ( ) . x ( ) , m_curLine . to ( ) . y ( ) ) , sf : : Color : : Red )
2020-11-29 04:04:25 +01:00
} ;
window . draw ( line , 2 , sf : : Lines ) ;
2020-11-27 03:09:50 +01:00
}
2020-11-29 04:04:25 +01:00
// show amount of steps and current status
2020-11-27 03:09:50 +01:00
window . draw ( m_textStatus ) ;
window . display ( ) ;
2020-11-18 18:01:57 +01:00
}