No closed polygon of less than 3 vertices

Because it's a bit surprising to close something you don't see.

Signed-off-by: Celelibi <celelibi@gmail.com>
Free the memory when you're done

Added a function that removes a polygon from a drawing, and a function
to free all polygons. The latter is called at the end of the main.

Signed-off-by: Celelibi <celelibi@gmail.com>
Make a function to draw squares

It is currently only used for selected vertex,but may be used to debug
too.

Signed-off-by: Celelibi <celelibi@gmail.com>
Only draw once the selected vertex or edge

The square around the selected vertex was drawn once for every polygon.
As well as the selected edge. They only need to be drawn once for the
whole drawing.

Signed-off-by: Celelibi <celelibi@gmail.com>
Make a dist2 function to simplify code

This function return the square of the distance between two points. It
is used by the functions closestVertex and closestEdge.

Signed-off-by: Celelibi <celelibi@gmail.com>
Simplify closestVertex

By restructuring a bit the blocking condition, the code can be put out
of the "else" branch, thus removing one level of indentation.

Signed-off-by: Celelibi <celelibi@gmail.com>
closestVertex simplification

By changing the do-while by a for, the code become more readable.

Signed-off-by: Celelibi <celelibi@gmail.com>
Use orthographic projection for closestEdge

With this, the edge selection is a lot more accurate.

Signed-off-by: Celelibi <celelibi@gmail.com>
Optimize orthographic projection distance

It no longer uses double. It now uses only integers.

Signed-off-by: Celelibi <celelibi@gmail.com>