Fix:skip_point error when gap overlap

jira: STUDIO-10852
Change-Id: Idbfdfe2513115b0fef540e0d681997be0a3719a4
This commit is contained in:
jiangkai.zhao 2025-03-25 15:30:54 +08:00 committed by lane.wei
parent 93e8f29e5d
commit baae89db17
1 changed files with 19 additions and 30 deletions

View File

@ -416,13 +416,22 @@ void insert_points(std::vector<PointWithFlag> &pl, int idx, Vec2f pos, int pair_
Polylines remove_points_from_polygon(const Polygon &polygon, const std::vector<Vec2f> &skip_points, double range, bool is_left, Polygon &insert_skip_pg)
{
assert(polygon.size() > 2);
Polylines result;
std::vector<PointWithFlag> new_pl; // add intersection points for gaps, where bool indicates whether it's a gap point.
std::vector<IntersectionInfo> inter_info;
Vec2f ray = is_left ? Vec2f(-1, 0) : Vec2f(1, 0);
auto polygon_box = get_extents(polygon);
Point anchor_point = is_left ? Point{polygon_box.max[0], polygon_box.min[1]} : polygon_box.min; // rd:ld
std::vector<Vec2f> points;
{
points.reserve(polygon.points.size());
for (auto &p : polygon.points) points.push_back(unscale(p).cast<float>());
int idx = polygon.closest_point_index(anchor_point);
Polyline tmp_poly = polygon.split_at_index(idx);
for (auto &p : tmp_poly) points.push_back(unscale(p).cast<float>());
points.pop_back();
}
for (int i = 0; i < skip_points.size(); i++) {
for (int j = 0; j < points.size(); j++) {
Vec2f& p1 = points[j];
@ -453,30 +462,7 @@ Polylines remove_points_from_polygon(const Polygon &polygon, const std::vector<V
for (auto &p : new_pl) insert_skip_pg.points.push_back(scaled(p.pos));
}
//assume that no interval is completely contained within another interval.
int beg = -1;
for (int i = 0; i < skip_points.size(); i++) {
if (beg != -1) break;
for (int j = 0; j < new_pl.size(); j++) {
if (new_pl[j].pair_idx == i && !new_pl[j].is_forward) {
bool is_include_pair = false;
int k = (j + 1) % new_pl.size();
while (k != j) {
if (new_pl[k].pair_idx == i && new_pl[k].is_forward) { break; }
if (new_pl[k].pair_idx != -1 && new_pl[k].pair_idx != i && new_pl[k].is_forward) {
is_include_pair = true;
break;
}
k = (k + 1) % new_pl.size();
}
if (!is_include_pair) {
beg = k;
break;
}
}
}
}
if (beg == -1) beg = 0;
int beg = 0;
bool skip = true;
int i = beg;
Polyline pl;
@ -494,7 +480,10 @@ Polylines remove_points_from_polygon(const Polygon &polygon, const std::vector<V
}
int left = new_pl[i].pair_idx;
int j = (i + 1) % new_pl.size();
while (j != beg && new_pl[j].pair_idx != left) j = (j + 1) % new_pl.size();
while (j != beg && new_pl[j].pair_idx != left) {
if (new_pl[j].pair_idx != -1 && !new_pl[j].is_forward) left = new_pl[j].pair_idx;
j = (j + 1) % new_pl.size();
}
i = j;
skip = true;
}