114{
115 std::vector<std::vector<double>> crossings(ny);
116 auto add_crossings = [&](
const Polygon &polygon) {
117 const Points &pts = polygon.points;
118 for (size_t i = 0; i < pts.size(); ++i) {
120 const Vec2d b =
unscaled(pts[i + 1 == pts.size() ? 0 : i + 1]);
121 if (a.y() == b.y())
122 continue;
123 const auto [lo, hi] = std::minmax(a.y(), b.y());
124 const int j0 = std::max(0, int(std::ceil((lo - origin.y()) / cell)));
125 const int j1 = std::min(ny, int(std::ceil((hi - origin.y()) / cell)));
126 for (int j = j0; j < j1; ++j) {
127 const double y = origin.y() + j * cell;
128 crossings[j].push_back(a.x() + (b.x() - a.x()) * (y - a.y()) / (b.y() - a.y()));
129 }
130 }
131 };
132 for (const ExPolygon &expolygon : expolygons) {
133 add_crossings(expolygon.contour);
134 for (const Polygon &hole : expolygon.holes)
135 add_crossings(hole);
136 }
137 for (int j = 0; j < ny; ++j) {
138 std::vector<double> &xs = crossings[j];
139 std::sort(xs.begin(), xs.end());
140 for (size_t k = 0; k + 1 < xs.size(); k += 2) {
141 const int i0 = std::max(0, int(std::ceil((xs[k] - origin.x()) / cell)));
142 const int i1 = std::min(nx, int(std::ceil((xs[k + 1] - origin.x()) / cell)));
143 std::fill(nodes +
size_t(j) * nx + std::min(i0, i1), nodes +
size_t(j) * nx + i1,
InfF);
144 }
145 }
146}
Definition Polygon.hpp:31
constexpr Eigen::Matrix< Tout, 2, EigenArgs... > unscaled(const Slic3r::Point &v) noexcept
Definition Arrange.cpp:81
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67