This tool uses three different views to demonstrate the workings of the Weiler-Atherton clipping algorithm. The main view is the large graphical area that displays the actual polygons and illustrates how the polygons are affected by the algorithm. The second view is the point list view, which is located just below the main view. This view represents the data structure that is actually used within the algorithm to store polygons. The third view is the console on the right, which is used to output step-by-step details about the algorithm.
There are three distinct phases involved in walking through the algorithm: specifying the polygons, finding the intersections and identifying the clipped regions. In the later two phases, navigation is done with the "Back" and "Forward" buttons. These will advance or reverse the algorithm by a single step. If the Shift button is held, these buttons will move to the start or the end of the current phase, allowing the user to skip over sections that are already understood.
The first step is to specify the two polygons, the clipping region and the subject polygon that will be clipped to the clipping region. This can be done simply by clicking in the main view to specify the vertices of the polygons. When the polygon is complete, the "Polygon Complete" button closes the polygon. It is important for the algorithm that both polygons are simple. A simple polygon is a polygon that has no intersecting edges. If a non-simple polygon is specified, it will not be accepted. It is also important for the algorithm that the points of the polygon are ordered in the counter-clockwise direction. The tool, however, will automatically reorder the points if specified in the reverse order. At this point, the points of the polygon will be labeled with capital letters if it is the subject polygon and lower case letters if it is the clipping region.
In this phase of the algorithm, every edge of the subject polygon is checked against every edge of the clipping polygon to find intersections. In the main view, the edges being compared will be highlighted in green and the intersection (which may be offscreen) is represented as a small red circle. If the intersection is kept, the point turns yellow and is labeled with a number. In the point list view, the lists update as the intersection points are added to both lists.
In the final phase, the algorithm iterates over the subject polygon identifying the regions inside of the clipping polygon. In the main view, the current point under consideration is labeled in red. Points marked as visited are yellow and a yellow line marks the border of a region to be output as it is collected. When an entire region has been identified, it turns green. In the point list view, the same color scheme is used to mark the points. In addition, a line indicating the flow of the algorithm through the point lists is shown as clipped regions are identified. When the region is fully traversed, the line turns gray so as to not be confused with later lines.