A bit of clean-up in FillRectilinear2.cpp

This commit is contained in:
bubnikv 2017-07-11 11:42:21 +02:00
parent c7d16699a4
commit c52c31a855

View File

@ -989,104 +989,6 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
SegmentedIntersectionLine &sil = segs[i_seg];
// Sort the intersection points using exact rational arithmetic.
std::sort(sil.intersections.begin(), sil.intersections.end());
#if 0
// Verify the order, bubble sort the intersections until sorted.
bool modified = false;
do {
modified = false;
for (size_t i = 1; i < sil.intersections.size(); ++ i) {
size_t iContour1 = sil.intersections[i-1].iContour;
size_t iContour2 = sil.intersections[i].iContour;
const Points &contour1 = poly_with_offset.contour(iContour1).points;
const Points &contour2 = poly_with_offset.contour(iContour2).points;
size_t iSegment1 = sil.intersections[i-1].iSegment;
size_t iPrev1 = ((iSegment1 == 0) ? contour1.size() : iSegment1) - 1;
size_t iSegment2 = sil.intersections[i].iSegment;
size_t iPrev2 = ((iSegment2 == 0) ? contour2.size() : iSegment2) - 1;
bool swap = false;
if (iContour1 == iContour2 && iSegment1 == iSegment2) {
// The same segment, it has to be vertical.
myassert(iPrev1 == iPrev2);
swap = contour1[iPrev1].y > contour1[iContour1].y;
#ifdef SLIC3R_DEBUG
if (swap)
printf("Swapping when single vertical segment\n");
#endif
} else {
// Segments are in a general position. Here an exact airthmetics may come into play.
coord_t y1max = std::max(contour1[iPrev1].y, contour1[iSegment1].y);
coord_t y2min = std::min(contour2[iPrev2].y, contour2[iSegment2].y);
if (y1max < y2min) {
// The segments are separated, nothing to do.
} else {
// Use an exact predicate to verify, that segment1 is below segment2.
const Point *a = &contour1[iPrev1];
const Point *b = &contour1[iSegment1];
const Point *c = &contour2[iPrev2];
const Point *d = &contour2[iSegment2];
#ifdef SLIC3R_DEBUG
const Point x1(sil.pos, sil.intersections[i-1].pos);
const Point x2(sil.pos, sil.intersections[i ].pos);
bool successive = false;
#endif /* SLIC3R_DEBUG */
// Sort the points in the two segments by x.
if (a->x > b->x)
std::swap(a, b);
if (c->x > d->x)
std::swap(c, d);
myassert(a->x <= sil.pos);
myassert(c->x <= sil.pos);
myassert(b->x >= sil.pos);
myassert(d->x >= sil.pos);
// Sort the two segments, so the segment <a,b> will be on the left of <c,d>.
bool upper_more_left = false;
if (a->x > c->x) {
upper_more_left = true;
std::swap(a, c);
std::swap(b, d);
}
if (a == c) {
// The segments iSegment1 and iSegment2 are directly connected.
myassert(iContour1 == iContour2);
myassert(iSegment1 == iPrev2 || iPrev1 == iSegment2);
std::swap(c, d);
myassert(a != c && b != c);
#ifdef SLIC3R_DEBUG
successive = true;
#endif /* SLIC3R_DEBUG */
}
#ifdef SLIC3R_DEBUG
else if (b == d) {
// The segments iSegment1 and iSegment2 are directly connected.
myassert(iContour1 == iContour2);
myassert(iSegment1 == iPrev2 || iPrev1 == iSegment2);
myassert(a != c && b != c);
successive = true;
}
#endif /* SLIC3R_DEBUG */
Orientation o = orient(*a, *b, *c);
myassert(o != ORIENTATION_COLINEAR);
swap = upper_more_left != (o == ORIENTATION_CW);
#ifdef SLIC3R_DEBUG
if (swap)
printf(successive ?
"Swapping when iContour1 == iContour2 and successive segments\n" :
"Swapping when exact predicate\n");
#endif
}
}
if (swap) {
// Swap the intersection points, but keep the original positions, so they stay sorted by the y axis.
std::swap(sil.intersections[i-1], sil.intersections[i]);
std::swap(sil.intersections[i-1].pos_p, sil.intersections[i].pos_p);
std::swap(sil.intersections[i-1].pos_q, sil.intersections[i].pos_q);
modified = true;
}
}
} while (modified);
#endif
// Assign the intersection types, remove duplicate or overlapping intersection points.
// When a loop vertex touches a vertical line, intersection point is generated for both segments.
// If such two segments are oriented equally, then one of them is removed.
@ -1574,8 +1476,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
#ifdef SLIC3R_DEBUG
// Verify, that there are no duplicate points in the sequence.
for (Polylines::iterator it = polylines_out.begin(); it != polylines_out.end(); ++ it)
myassert(! it->has_duplicate_points());
for (Polyline &polyline : polylines_out)
myassert(! polyline.has_duplicate_points());
#endif /* SLIC3R_DEBUG */
return true;