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>
Don't use perror when errno has not been set

For non-syscall-related error messages, use the classical fprintf to
print an informative error message.

Signed-off-by: Celelibi <celelibi@gmail.com>
Use a separated function for system error handling

This function, system_error, basically just calls perror and exit. It
allows to emergency quit when a syscall return an error with only one
line of code.

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

s/clic/clique/

Signed-off-by: Celelibi <celelibi@gmail.com>
Converted end-of-line to unix-style

Because git doesn't like the DOS style.

Signed-off-by: Celelibi <celelibi@gmail.com>
Mark the unexported functions as static

Some functions are only used by the scanline algorithm and thus should
be static since they're not even exported to the .h.

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

This comment was saying "add if necessary". And it have already been added.

Signed-off-by: Celelibi <celelibi@gmail.com>
Rework sorting of active_edge to make it simpler

The code that pick the smallest head of two lists has been made a
function. So that the main code is clearer.

Signed-off-by: Celelibi <celelibi@gmail.com>
Corrected a few bits of indentation

Try not to make lines larger than 80 columns and indent the multi-lines
/**/ comments. And add some spaces around keywords.

Signed-off-by: Celelibi <celelibi@gmail.com>
ScanLine: move active edge addition

Move the active edge addition at the beginning of the loop so that it
will be merged with the code of initial filling of the active edges.

Signed-off-by: Celelibi <celelibi@gmail.com>
ScanLine: merge initial and in-run active edge addition

Those were basically the same code with only a few optimisations for the
initial active edge addition. Moreover, those optimisation should be
gone soon.

Signed-off-by: Celelibi <celelibi@gmail.com>
ScanLine: simpler handling of horizontal edges

When an active edge ends and is linked to an horizontal one, don't try
to be smart, we'll need to re-sort the active edge list anyway. Just
remove it and let the normal active edge addition handle the addition
(or not) of the next edge.

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