Comparing Lines – IEqualityComparer (AutoCAD .net)

It’s not very often that I write something on the Autocad .net API, so here’s something which you, I suppose, will need one day:

 

If you want to compare two lines, with a tolerance, in a collection then you’d need a LineComparer. The MSDN guide says that one should inherit from EqualityComparer, so unquestioningly, I did their bidding. The results are as below.

Take careful note of the Hashcode. You want lines that are similar – and are within the tolerance to return the same hashcode. If they are outside the tolerance then the chances of two different lines returning the same hashcode is minimal.

Lines are equal if their start and ends points are equal (or vice versa). They are also more or less equal if they return the same hash code. In such cases, then the equals method is run.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *