If e.g. ea.MinX
is NaN
, a
will be NaN
and both a > b
and a < b
will be false
. This means, there are objects which compare equal to every other object.
You first have to decide, how you want objects containing NaN
to be sorted.
An easy workaround might be to insert
if (double.IsNaN(a)) a = 0.0;
if (double.IsNaN(b)) b = 0.0;
As noted by @Seph and @Jeppe in comments, double.CompareTo
does the right thing, so the last line can be replaced by return a.CompareTo(b);
.