When using the usual formulas to calculate intersection between two 2D segments, ie here, if you round the result to an integer, you get non-symmetric results.
That is, sometimes, due to rounding errors, I get that intersection(A,B)!=intersection(B,A)
.
The best solution is to keep working with floats, and compare the results up to a certain precision. However, I must round the results to integers after calculating the intersection, I cannot keep working with floats.
My best solution so far was to use some full order on the segments in the plane, and have intersection
to always compare the smaller segment to the larger segment.
Is there a better method? Am I missing something?