--- a/polygon_clip.hh 2020-05-01 19:47:41.108664761 +0300 +++ b/polygon_clip.hh 2020-06-26 20:47:17.522478319 +0300 @@ -25,10 +25,11 @@ if((outside < 0 && outsidenext > 0) || (outside > 0 && outsidenext < 0)) { - auto factor = outside / (outside - outsidenext); - // Create a new point b between *current and *next like this: current + (next-current) * factor - auto b = *current + ((*next - *current) * factor); + // The two conditions produces mathematically identical results, but because of floating point, + // there may be rounding differences between adjacent walls depending on winding direction. + auto b = (outside < outsidenext) ? (*current + (*next - *current) * (outside / (outside - outsidenext))) + : (*next + (*current - *next) * (outsidenext / (outsidenext - outside))); if(keep) { current = std::next(points.insert(std::next(current), std::move(b))); } else { *current = std::move(b); ++current; }