-
Notifications
You must be signed in to change notification settings - Fork 0
Polygons
Relevant namespace: Polygons
Polygons make up the backbone of the implemented domain for GA. The central class is the Polygon, derived from IPolygon interface.
Every polygon holds the following data:
- Collection of vertices that define it (using
System.Drawing.Pointto represent a single vertex) - Vertices count
- Center coordinates - center is a point defined as the average of the polygon's most outlying vertices (left,right,top,bottom-most)
- Centroid coordinates - centroid is a point defined as the average of the polygon's every vertex
- Color (
System.Drawing.Color) to be used for the polygon's outline
Notes: The center point is useful mainly for visualization purposes, placing the polygon properly into a specified container.
Centroid on the other hand provides a more intuitive (for humans) definition of a shape's "middle" - if vertices are dense in one area and there is an outlier further away, it is more intuitive for a "middle" to gravitate more towards the densely populated area rather than using only the most extreme points for this placement.
The Polygon class contains additional methods for positional manipulation (various ways to shift/resize the whole shape), these are only introduced for easier visualization under different circumstances.
This class serves for randomly generating polygons. The approach used in this case is to generate N random unique angles in the range 0-359 (+ sort them, this takes away from complete randomness, but makes the result more sensible), then a random distance in a certain range is assigned to each angle and these parameters are used to calculate the coordinates of the vertex (origin is arbitrarily at [0,0]).
Visualizer provides extension methods to represent IPolygons using System.Graphics
The main methods are IPolygon.Draw and IPolygon.DrawIncomplete - both use the framework's defined method for DrawPolygon, but additionally mark all vertices locations with small circles. The difference between the two methods is that DrawIncomplete doesn't draw a connection between the first and last defined vertices of the polygon.
Visualizer can also mark the center and centroid of an IPolygon and resize polygons to fit into containers of given sizes.
XmlHandler is responsible for encoding and decoding polygons to convert between instances of polygons and their .xml equivalents.