mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 14:25:56 +08:00
use geometry orientation
This commit is contained in:
parent
9c9880aba8
commit
e27734266f
@ -2,12 +2,3 @@
|
|||||||
|
|
||||||
using namespace Slic3r::sla;
|
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:
|
public:
|
||||||
PointUtils() = delete;
|
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
|
} // namespace Slic3r::sla
|
||||||
|
@ -214,20 +214,26 @@ Slic3r::Polygon VoronoiGraphUtils::to_polygon(const VD::cell_type & cell,
|
|||||||
const Slic3r::Points &points,
|
const Slic3r::Points &points,
|
||||||
double maximal_distance)
|
double maximal_distance)
|
||||||
{
|
{
|
||||||
const VD::edge_type *edge = cell.incident_edge();
|
|
||||||
Lines lines;
|
Lines lines;
|
||||||
Point center = points[cell.source_index()];
|
Point center = points[cell.source_index()];
|
||||||
// Convenient way to iterate edges around Voronoi cell.
|
// Convenient way to iterate edges around Voronoi cell.
|
||||||
|
const VD::edge_type *edge = cell.incident_edge();
|
||||||
do {
|
do {
|
||||||
assert(edge->is_linear());
|
assert(edge->is_linear());
|
||||||
if (edge->is_primary()) {
|
if (!edge->is_primary()) {
|
||||||
std::optional<Line> line = to_line(*edge, points, maximal_distance);
|
edge = edge->next();
|
||||||
if (line.has_value()) {
|
continue;
|
||||||
if (!PointUtils::is_ccw(line->a, line->b, center))
|
|
||||||
std::swap(line->a, line->b);
|
|
||||||
lines.push_back(line.value());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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();
|
edge = edge->next();
|
||||||
} while (edge != cell.incident_edge());
|
} while (edge != cell.incident_edge());
|
||||||
LineUtils::sort_CCW(lines, center);
|
LineUtils::sort_CCW(lines, center);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user