mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 01:15:53 +08:00
SPE-1949 Fixed selection of closest point to center
This commit is contained in:
parent
15931c2ef4
commit
df3e55d4a8
@ -1921,6 +1921,26 @@ uint32_t priv::find_closest_point_index(const Point &p,
|
||||
const std::vector<bool> &mask)
|
||||
{
|
||||
SearchData sd = create_search_data(shapes, mask);
|
||||
if (sd.tree.nodes().size() == 0){
|
||||
// no lines in expolygon, check whether exist point to start
|
||||
double closest_square_distance = INFINITY;
|
||||
uint32_t closest_id = -1;
|
||||
for (uint32_t i = 0; i < mask.size(); i++)
|
||||
if (mask[i]){
|
||||
ExPolygonsIndex ei = s2i.cvt(i);
|
||||
const Point& s_p = ei.is_contour()?
|
||||
shapes[ei.expolygons_index].contour[ei.point_index]:
|
||||
shapes[ei.expolygons_index].holes[ei.hole_index()][ei.point_index];
|
||||
double square_distance = (p - s_p).cast<double>().squaredNorm();
|
||||
if (closest_id >= mask.size() ||
|
||||
closest_square_distance > square_distance) {
|
||||
closest_id = i;
|
||||
closest_square_distance = square_distance;
|
||||
}
|
||||
}
|
||||
assert(closest_id < mask.size());
|
||||
return closest_id;
|
||||
}
|
||||
size_t line_idx = std::numeric_limits<size_t>::max();
|
||||
Vec2d hit_point;
|
||||
Vec2d p_d = p.cast<double>();
|
||||
@ -2226,6 +2246,10 @@ priv::ProjectionDistances priv::choose_best_distance(
|
||||
|
||||
// Select point from shapes(text contour) which is closest to center (all in 2d)
|
||||
uint32_t unfinished_index = find_closest_point_index(start, shapes, s2i, mask_distances);
|
||||
assert(unfinished_index < s2i.get_count());
|
||||
if (unfinished_index >= s2i.get_count())
|
||||
// no point to select
|
||||
return result;
|
||||
|
||||
#ifdef DEBUG_OUTPUT_DIR
|
||||
Connections connections;
|
||||
|
Loading…
x
Reference in New Issue
Block a user