#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <utility>
#include <vector>
using namespace LibBoard;
{
int sign = 0;
if (p != a && p != b) {
double wp = v1.
x * v2.
y - v1.
y * v2.
x;
if (std::abs(wp) < 1e-8) {
if ((a - p) * (b - p) < 0.0) {
return true;
}
}
if ((sign > 0 && wp < 0.0) || (sign < 0 && wp > 0.0)) {
return true;
}
sign = (wp > 0.0) ? 1 : -1;
}
}
if (sign == -1) {
std::swap(a, b);
}
return false;
}
int main(int, char *[])
{
Style::setDefaultLineWidth(0.5);
Style::setDefaultPenColor(Color::Blue);
Style::setDefaultFillColor(Color::Null);
std::vector<Point> points;
int n = 25;
while (n--) {
points.push_back(
Point(4 * (Tools::boardRand() % 50), 4 * (Tools::boardRand() % 50)));
}
typedef std::pair<Point, Point> Segment;
std::vector<Segment> segments;
for (size_t a = 0; a < points.size(); ++a) {
for (size_t b = a + 1; b < points.size(); ++b) {
segments.push_back(Segment(pa, pb));
}
}
}
Segment segment = segments.front();
std::vector<Point> polyline;
const Point stop = segment.first;
do {
polyline.push_back(segment.first);
for (const Segment & s : segments) {
if (s.first == segment.second) {
segment = s;
break;
}
}
} while (segment.first != stop);
board <<
Polyline(polyline, Path::ClosedPath, Color::Cyan,
Color(
"#a0a0c0"), 0.5);
board <<
Dot(p.x, p.y, Color::Blue, 1.0);
}
}