mathnet / mathnet-spatial

Math.NET Spatial
http://spatial.mathdotnet.com
MIT License
376 stars 132 forks source link

Bug during null check #241

Open NilesDavis opened 2 months ago

NilesDavis commented 2 months ago

I came in a situation where I checked a Polygon2D if it was null or not and in any case it returned false. Try this code to reproduce:

Polygon2D polygon = null;
bool isNull = polygon == null;

The variable isNull should result in being true, but is not!

Essentially what is missing in the "=="-operator is something like this:

//both null
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
    return true;
//for null-condition
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
    return false;

This seems to be the same situation for nearly all classes of Euclidian namespace!

Or am I missing something? As mathnet-spatial mostly uses structs it is not that obvious

jkalias commented 2 months ago

Hi @NilesDavis,

Thanks for the feedback. This seems indeed like a bug. I don't need a proper definition for ==, neither for PolyLine2D which you say is implemented properly. Would you mind opening a PR (including unit tests)?

Thanks

NilesDavis commented 2 months ago

Hi @jkalias . To be honest, I wanted to, but I couldnt get the build Environment running for Standard 2.0 in VS2022. That kept me of doing it, sorry. You know the code is not the problem but tooling is... So you have it running that you can compile it?

Cheers, Nils