Improve performance when bed are large

This commit is contained in:
SoftFever 2024-05-11 23:26:02 +08:00
parent 98caf561ef
commit 8f77755535
3 changed files with 13 additions and 10 deletions

View file

@ -5065,8 +5065,11 @@ std::vector<Vec2f> 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<Vec2f> cells;
std::vector<Vec2f> 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<Vec2f> 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<Vec2f> 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)