Rounding

By using integer coordinates for all polygons, the Clipper Library has side-stepped the thorny issue of numerical robustness that otherwise plagues geometric computations with floating point values. However, rounding polygon coordinates to integers has introduced its own complications.

Firstly, there's the issue of precision. This is easily dealt with by using scaling. To increase precision, input polygon coordinates are 'scaled up' (usually by a factor of 10) before being passed to the Clipper object, and the solution polygons returned are later scaled back down.

While all vertices have integer coordinates, points of intersection typically occur at non-integer coordinates, and consequently they have to be 'moved' (via rounding) to their closest integer coordinates. Unfortunately, this 'moving' can occasionally cause tiny self-intersection artefacts.

For example, in the image on the left, the area of intersection of 2 polygons is highlighted in bright green. In this unscaled image (where one unit equals one pixel), we can see that rounding has negligible affect on the clipped solution, even though a tiny self-intersecting artefact has been removed.



This second image is a 30X 'close up' of the first image focusing on the points of intersection. The three 'black dots' highlight the actual points of intersection (with their fractional coordinates displayed). The smaller 'red dots' show where these points of intersection will be moved to when rounding is applied. With a little care you should be able to see how rounding in this example reverses the orientation of these vertices causing a 'self-intersection artefact'.

Although self-intersection artefacts are always tiny (having sub-pixel dimensions) they can cause problems if they're ignored and polygons are assumed to be 'simple' as is the case with Clipper's Orientation function.

Since Clipper's Orientation function requires the orientation of the three bottom-most vertices of a polygon to accurately reflect the orientation of the whole polygon, Clipper detects and removes any 'self-intersection artefacts' occurring at the bottom of output polygons.