MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / eliminate_overlaps

Function eliminate_overlaps

src/svgfill/src/arrange_polygons.cpp:510–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

508};
509
510void eliminate_overlaps(DebugWriter& debug_writer, double OVERLAP_RESOLUTION_DISTANCE, std::vector<Polygon_2>& polygons) {
511 // solve overlaps by means of subtraction
512 // loop over overlaps and subtract the smaller polygon from the larger one
513
514 std::set<size_t> eliminated_polies;
515
516 /*
517 std::map<size_t, size_t> overlap_counts;
518 for (auto& p : overlaps) {
519 overlap_counts[p.first]++;
520 overlap_counts[p.second]++;
521 }
522 */
523
524 auto overlaps = find_overlaps(polygons);
525
526 for (const auto& edge : overlaps) {
527 // Skip eliminated
528 if (eliminated_polies.find(edge.first) != eliminated_polies.end() ||
529 eliminated_polies.find(edge.second) != eliminated_polies.end()) {
530 continue;
531 }
532
533 // Many overlaps indicate an aggregated polygon, skip them
534 /*
535 if (overlap_counts[edge.first] > 10 || overlap_counts[edge.second] > 10) {
536 if (overlap_counts[edge.first] > 10) {
537 eliminated_polies.insert(edge.first);
538 }
539 if (overlap_counts[edge.second] > 10) {
540 eliminated_polies.insert(edge.second);
541 }
542 continue;
543 }
544 */
545
546 // these are pointers now, because otherwise swap would not work?
547 auto* poly1 = &polygons[edge.first];
548 auto* poly2 = &polygons[edge.second];
549
550 // @todo this is applied during overlap processing, maybe better after the boolean operation,
551 // because they can be come small or narrow when overlaps are resolved
552
553 // Populate eliminated_polies with small polygons
554 // This can happen over time when modifications are made to the polygons to solve overlaps
555 bool skip = false;
556 if (poly1->area() < 1.e-2) {
557 eliminated_polies.insert(edge.first);
558 skip = true;
559 }
560 if (poly2->area() < 1.e-2) {
561 eliminated_polies.insert(edge.second);
562 skip = true;
563 }
564 // Small slivers are also just eliminated
565 if (!maybe_take_first_if_single_item(create_and_convert_offset_polygon(-1.e-1, *poly1))) {
566 eliminated_polies.insert(edge.first);
567 skip = true;

Callers 1

arrange_cgal_polygonsFunction · 0.85

Calls 12

find_overlapsFunction · 0.85
smooth_polygonFunction · 0.85
subtract_retain_largestFunction · 0.85
write_polygonMethod · 0.80
findMethod · 0.45
endMethod · 0.45
areaMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected