use geometry orientation

This commit is contained in:
Filip Sykala 2021-03-18 12:10:09 +01:00 committed by Lukas Matena
parent 9c9880aba8
commit e27734266f
3 changed files with 14 additions and 20 deletions

View File

@ -2,12 +2,3 @@
using namespace Slic3r::sla;
bool PointUtils::is_ccw(const Point &p1, const Point &p2, const Point &center)
{
Slic3r::Point v1 = p1 - center;
Slic3r::Point v2 = p2 - center;
double cross_product = v1.x() * (double) v2.y() -
v2.x() * (double) v1.y();
return cross_product > 0;
}

View File

@ -14,9 +14,6 @@ class PointUtils
{
public:
PointUtils() = delete;
// is point p1 to p2 in counter clock wise order against center?
static bool is_ccw(const Point &p1, const Point &p2, const Point &center);
};
} // namespace Slic3r::sla

View File

@ -214,20 +214,26 @@ Slic3r::Polygon VoronoiGraphUtils::to_polygon(const VD::cell_type & cell,
const Slic3r::Points &points,
double maximal_distance)
{
const VD::edge_type *edge = cell.incident_edge();
Lines lines;
Point center = points[cell.source_index()];
// Convenient way to iterate edges around Voronoi cell.
const VD::edge_type *edge = cell.incident_edge();
do {
assert(edge->is_linear());
if (edge->is_primary()) {
std::optional<Line> line = to_line(*edge, points, maximal_distance);
if (line.has_value()) {
if (!PointUtils::is_ccw(line->a, line->b, center))
std::swap(line->a, line->b);
lines.push_back(line.value());
}
if (!edge->is_primary()) {
edge = edge->next();
continue;
}
std::optional<Line> line = to_line(*edge, points, maximal_distance);
if (!line.has_value()) {
edge = edge->next();
continue;
}
Geometry::Orientation o = Geometry::orient(center, line->a, line->b);
assert(o != Geometry::Orientation::ORIENTATION_COLINEAR);
if (o == Geometry::Orientation::ORIENTATION_CW)
std::swap(line->a, line->b);
lines.push_back(line.value());
edge = edge->next();
} while (edge != cell.incident_edge());
LineUtils::sort_CCW(lines, center);