ladybug-tools / ladybug-geometry

🐞 📦 A library with geometry objects used throughout the Ladybug Tools core libraries
https://www.ladybug.tools/ladybug-geometry/docs/
GNU Affero General Public License v3.0
26 stars 23 forks source link

feat(hash): Add __hash__ methods that agree with __eq__ to all objects #81

Closed chriswmackey closed 4 years ago

chriswmackey commented 4 years ago

I realized that we were overwriting the eq method on a number of objects without overwriting the hash method, which I have come to realize is strongly discouraged in Python. So this commit fixes this by adding hash methods that agree with the eq operator. This should also allow us to create sets of these geometry objects if we so desire.

The only thing I didn't implement that might be worthwhile to implement in the future is that I am not caching the hash value once it is calculated, which is something that we could do given that all of the geometry objects are immutable. This will allow for quicker hashing if we plan to hash the object multiple times but it also uses up a little more memory per object to store the hash. Right now, we really don't end up hashing the object multiple times in any of our typical workflows such that I think the trade-off isn't worth it. However, we should reconsider this if we find cases in the future where we are hashing the objects multiple times.

ladybugbot commented 4 years ago

:tada: This PR is included in version 1.9.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: