mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 22:16:09 +08:00
use geometry orientation
This commit is contained in:
parent
9c9880aba8
commit
e27734266f
@ -2,12 +2,3 @@
|
||||
|
||||
using namespace Slic3r::sla;
|
||||
|
||||
bool PointUtils::is_ccw(const Point &p1, const Point &p2, const Point ¢er)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -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 ¢er);
|
||||
};
|
||||
|
||||
} // namespace Slic3r::sla
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user