diff --git a/src/libslic3r/EdgeGrid.cpp b/src/libslic3r/EdgeGrid.cpp index 4985b788e4..c1c8fbcd98 100644 --- a/src/libslic3r/EdgeGrid.cpp +++ b/src/libslic3r/EdgeGrid.cpp @@ -1307,9 +1307,9 @@ Polygons EdgeGrid::Grid::contours_simplified(coord_t offset, bool fill_holes) co // 1) Collect the lines. std::vector lines; EndPointMapType start_point_to_line_idx; - for (int r = 0; r <= int(m_rows); ++ r) { - for (int c = 0; c <= int(m_cols); ++ c) { - int addr = (r + 1) * cell_cols + c + 1; + for (coord_t r = 0; r <= coord_t(m_rows); ++ r) { + for (coord_t c = 0; c <= coord_t(m_cols); ++ c) { + size_t addr = (r + 1) * cell_cols + c + 1; bool left = cell_inside[addr - 1]; bool top = cell_inside[addr - cell_cols]; bool current = cell_inside[addr]; diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index 86d9241656..e95222f502 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -40,7 +40,7 @@ using coord_t = int32_t; #else //FIXME At least FillRectilinear2 and std::boost Voronoi require coord_t to be 32bit. -typedef int64_t coord_t; +using coord_t = int64_t; #endif using coordf_t = double; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 1191bf55f3..b4778e3932 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5065,8 +5065,11 @@ std::vector GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve Vec2d vmin(build_volume.min.x(), build_volume.min.y()), vmax(build_volume.max.x(), build_volume.max.y()); BoundingBoxf bbox(vmin, vmax); std::vector cells; + std::vector cells_ret; auto min_x = start_point.x() - step(0) * int((start_point.x() - bbox.min.x()) / step(0)); auto min_y = start_point.y() - step(1) * int((start_point.y() - bbox.min.y()) / step(1)); + cells.reserve(((bbox.max.x() - min_x) / step(0)) * ((bbox.max.y() - min_y) / step(1))); + cells_ret.reserve(cells.size()); for (float x = min_x; x < bbox.max.x() - step(0) / 2; x += step(0)) for (float y = min_y; y < bbox.max.y() - step(1) / 2; y += step(1)) { @@ -5093,10 +5096,10 @@ std::vector GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve for (auto it = cells.begin(); it != cells.end(); ) { - if (inst_hull_2d.contains(Point(scale_(it->x()), scale_(it->y())))) - it = cells.erase(it); - else - it++; + if (!inst_hull_2d.contains(Point(scale_(it->x()), scale_(it->y())))) + cells_ret.push_back(*it); + + it++; } } } @@ -5106,8 +5109,8 @@ std::vector GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve start(0) = bbox.center()(0); start(1) = bbox.center()(1); } - std::sort(cells.begin(), cells.end(), [start](const Vec2f& cell1, const Vec2f& cell2) {return (cell1 - start).norm() < (cell2 - start).norm(); }); - return cells; + std::sort(cells_ret.begin(), cells_ret.end(), [start](const Vec2f& cell1, const Vec2f& cell2) {return (cell1 - start).norm() < (cell2 - start).norm(); }); + return cells_ret; } Vec2f GLCanvas3D::get_nearest_empty_cell(const Vec2f start_point, const Vec2f step)