SPE-1949 Fixed selection of closest point to center

This commit is contained in:
Filip Sykala - NTB T15p 2023-10-16 14:41:34 +02:00
parent 15931c2ef4
commit df3e55d4a8

View File

@ -1921,6 +1921,26 @@ uint32_t priv::find_closest_point_index(const Point &p,
const std::vector<bool> &mask) const std::vector<bool> &mask)
{ {
SearchData sd = create_search_data(shapes, 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(); size_t line_idx = std::numeric_limits<size_t>::max();
Vec2d hit_point; Vec2d hit_point;
Vec2d p_d = p.cast<double>(); Vec2d p_d = p.cast<double>();
@ -2226,7 +2246,11 @@ priv::ProjectionDistances priv::choose_best_distance(
// Select point from shapes(text contour) which is closest to center (all in 2d) // 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); 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 #ifdef DEBUG_OUTPUT_DIR
Connections connections; Connections connections;
connections.reserve(shapes.size()); connections.reserve(shapes.size());