From f65041c0ad50ab833ba7e90d9264d8be945b0e19 Mon Sep 17 00:00:00 2001 From: incredibleLeitman Date: Mon, 30 Nov 2020 18:08:26 +0100 Subject: [PATCH] fixed akl: order lines counterclockwise --- Display.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Display.cpp b/Display.cpp index 1bddb43..67c4278 100644 --- a/Display.cpp +++ b/Display.cpp @@ -127,15 +127,23 @@ void Display::setCurrentLine() positives++; break; // sufficient as candidate if at least one point is right } - /*positives += (sign(pt.getPosition().x, pt.getPosition().y, - cand.from().x(), cand.from().y(), - cand.to().x(), cand.to().y()) > 0) ? 1 : 0;*/ + /*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 + }*/ } if (positives > 0) { m_curLineIdx = lines - 1; m_curLine = m_lines[lines - 1]; + + 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; } else { @@ -209,6 +217,11 @@ void Display::update () } } + 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; + // adding edge points to hull m_points[i_left].setFillColor(sf::Color::Blue); m_hullPoints.push_back(m_points[i_left]); @@ -223,9 +236,11 @@ void Display::update () m_hullPoints.push_back(m_points[i_bot]); // building lines between edge points - Point pt1(left.x, left.y); + // hull points shall be clockwise, but lines have to be counterclockwise + // because only checking elems right of lines + Point pt1(right.x, right.y); Point pt2(top.x, top.y); - Point pt3(right.x, right.y); + Point pt3(left.x, left.y); Point pt4(bot.x, bot.y); m_lines.push_back(Line(pt1, pt2)); m_lines.push_back(Line(pt2, pt3)); @@ -251,7 +266,7 @@ void Display::update () } } - setCurrentLine(); + //setCurrentLine(); // set current line in next step } else {