Skip to content

Commit

Permalink
Fix multiply duplicated spikes
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Nov 9, 2023
1 parent 5ba24f0 commit 6bd0cdc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct point {
typedef std::pair<point, point> segment;

void fix_opposites(std::vector<segment> &segs) {
std::map<segment, size_t> opposites;
std::multimap<segment, size_t> opposites;
segment erased = std::make_pair(point(INT_MAX, INT_MAX), point(INT_MAX, INT_MAX));

for (size_t i = 0; i < segs.size(); i++) {
Expand All @@ -47,11 +47,16 @@ void fix_opposites(std::vector<segment> &segs) {
continue;
}

auto f = opposites.find(segs[i]);
if (f != opposites.end()) {
auto f = opposites.equal_range(segs[i]);
for (; f.first != f.second; ++f.first) {
if (segs[f.first->second] == erased) {
continue;
}

segs[i] = erased;
segs[f->second] = erased;
opposites.erase(f);
segs[f.first->second] = erased;
opposites.erase(f.first);
break;
}
}

Expand Down

0 comments on commit 6bd0cdc

Please sign in to comment.