@@ -672,11 +672,29 @@ static LayerIsland *get_fill_island(Layer &layer,
672672 // Sort the extrusion range into its LayerIsland.
673673 // Traverse the slices in an increasing order of bounding box size, so that the islands inside another islands are tested first,
674674 // so we can just test a point inside ExPolygon::contour and we may skip testing the holes.
675+ // That is because layer.lslices() is topologically sorted.
675676 auto point_inside_surface = [&layer](const size_t lslice_idx, const Point &point) {
676677 const BoundingBox &bbox = layer.lslices_ex [lslice_idx].bbox ;
677678 return point.x () >= bbox.min .x () && point.x () < bbox.max .x () && point.y () >= bbox.min .y () && point.y () < bbox.max .y () &&
678679 layer.lslices ()[lslice_idx].contour .contains (point);
679680 };
681+ #ifdef _DEBUG
682+ // check topological sort
683+ if (layer.lslices ().size () > 1 ) {
684+ std::vector<BoundingBox> bboxes;
685+ bboxes.emplace_back (layer.lslices ()[0 ].contour .points );
686+ for (size_t check_idx = 1 ; check_idx < layer.lslices ().size (); ++check_idx) {
687+ assert (bboxes.size () == check_idx);
688+ bboxes.emplace_back (layer.lslices ()[check_idx].contour .points );
689+ for (size_t bigger_idx = 0 ; bigger_idx < check_idx; ++bigger_idx) {
690+ // higher idx can be inside holes, but not the opposite!
691+ if (bboxes[check_idx].contains (bboxes[bigger_idx])) {
692+ assert (!layer.lslices ()[check_idx].contour .contains (layer.lslices ()[bigger_idx].contour .first_point ()));
693+ }
694+ }
695+ }
696+ }
697+ #endif
680698 int lslice_idx = int (layer.lslices_ex .size ()) - 1 ;
681699 for (; lslice_idx >= 0 ; --lslice_idx)
682700 if (point_inside_surface (lslice_idx, point))
@@ -759,6 +777,7 @@ static void insert_ironings_into_islands(Layer &layer, uint32_t layer_region_id,
759777 // Sort the extrusion range into its LayerIsland.
760778 // Traverse the slices in an increasing order of bounding box size, so that the islands inside another islands are tested first,
761779 // so we can just test a point inside ExPolygon::contour and we may skip testing the holes.
780+ // That is because layer.lslices() is topologically sorted.
762781 auto point_inside_surface = [&layer](const size_t lslice_idx, const Point &point) {
763782 const BoundingBox &bbox = layer.lslices_ex [lslice_idx].bbox ;
764783 return point.x () >= bbox.min .x () && point.x () < bbox.max .x () &&
0 commit comments