Files
QIDISlicer/src/libslic3r/IntersectionPoints.cpp

51 lines
1.9 KiB
C++
Raw Normal View History

2023-06-10 10:14:12 +08:00
#include "IntersectionPoints.hpp"
2023-12-27 18:02:35 +08:00
#include <libslic3r/AABBTreeLines.hpp>
2023-06-10 10:14:12 +08:00
2023-12-27 18:02:35 +08:00
//NOTE: using CGAL SweepLines is slower !!! (example in git history)
2023-06-10 10:14:12 +08:00
2023-12-27 18:02:35 +08:00
namespace {
using namespace Slic3r;
IntersectionsLines compute_intersections(const Lines &lines)
2023-06-10 10:14:12 +08:00
{
2023-12-27 18:02:35 +08:00
if (lines.size() < 3)
return {};
2023-06-10 10:14:12 +08:00
2023-12-27 18:02:35 +08:00
auto tree = AABBTreeLines::build_aabb_tree_over_indexed_lines(lines);
IntersectionsLines result;
for (uint32_t li = 0; li < lines.size()-1; ++li) {
2023-06-10 10:14:12 +08:00
const Line &l = lines[li];
2023-12-27 18:02:35 +08:00
auto intersections = AABBTreeLines::get_intersections_with_line<false, Point, Line>(lines, tree, l);
for (const auto &[p, node_index] : intersections) {
if (node_index - 1 <= li)
continue;
if (const Line &l_ = lines[node_index];
l_.a == l.a ||
l_.a == l.b ||
l_.b == l.a ||
l_.b == l.b )
// it is duplicit point not intersection
continue;
2023-06-10 10:14:12 +08:00
2023-12-27 18:02:35 +08:00
// NOTE: fix AABBTree to compute intersection with double preccission!!
Vec2d intersection_point = p.cast<double>();
2023-06-10 10:14:12 +08:00
2023-12-27 18:02:35 +08:00
result.push_back(IntersectionLines{li, static_cast<uint32_t>(node_index), intersection_point});
2023-06-10 10:14:12 +08:00
}
}
2023-12-27 18:02:35 +08:00
return result;
2023-06-10 10:14:12 +08:00
}
2023-12-27 18:02:35 +08:00
} // namespace
2023-06-10 10:14:12 +08:00
2023-12-27 18:02:35 +08:00
namespace Slic3r {
IntersectionsLines get_intersections(const Lines &lines) { return compute_intersections(lines); }
IntersectionsLines get_intersections(const Polygon &polygon) { return compute_intersections(to_lines(polygon)); }
IntersectionsLines get_intersections(const Polygons &polygons) { return compute_intersections(to_lines(polygons)); }
IntersectionsLines get_intersections(const ExPolygon &expolygon) { return compute_intersections(to_lines(expolygon)); }
IntersectionsLines get_intersections(const ExPolygons &expolygons) { return compute_intersections(to_lines(expolygons)); }
2023-06-10 10:14:12 +08:00
}
2023-12-27 18:02:35 +08:00