named regioninfos that holds RegionInfo objects representing the partitions.
To build this list, the program considers each circle in turn. It builds a RegionInfo object to represent the circle and then calls the RegionInfo object's MakeIntersections method.
The MakeIntersections method loops through the RegionInfo objects that are already in the list. For each object "other" in the list, it considers how "other" and the current object "this" partition their areas. If the two objects overlap, then they divide their are into three pieces:
- this intersect other
- this - other
- other - this
If the regions overlap, the code:
- Replaces "other" with "other" - "this"
- Replaces "this" with "this" - "other"
- Adds "this" intersect "other" to a new list of RegionInfo objects
After it has compared "this" to all of the RegionInfos in the old list, it adds any intersection objects in the new list to the old list.
After it has finished comparing every circle to the list, the partition is complete.
After building the partition, the Paint event handler loops through the RegionInfo objects calling their Draw methods. The Draw method fills a partition with a color that depends on the partition's count (so partitions with larger counts get brighter colors). It then uses techniques described in the example Find a Region's centroid in Visual Basic .NET to find the partition's centroid and draws the count there.
(Note that you can use this technique to partition an area with regions of any shape, not just circles.)