Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Equals, GetHashCode, and Zero to Vector2 #26

Closed
wants to merge 4 commits into from
Closed

Added Equals, GetHashCode, and Zero to Vector2 #26

wants to merge 4 commits into from

Conversation

cuddlyogre
Copy link

I've implemented Equals, GetHashCode, and Vector2.zero.

Equals allows you to check if one Vector2's value is the same as another's.
GetHashCode lets it be used in a dictionary effectively.
Zero returns a Vector2 with its X and Y set to 0.

The commit I made the desired changes to is 1540bb0

Feel free to ignore the changes to the project files. I use 2012 but did not change anything specific to that version.

@LaurentGomila
Copy link
Member

Equals allows you to check if one Vector2's value is the same as another's.

I know nothing about this kind of functions in .Net, so excuse my noobish question, but is it really the "standard" way to do it? Doesn't .Net allows to overload operators, with more type-safety?

GetHashCode lets it be used in a dictionary effectively.

Same question here: is it the standard way?

Zero returns a Vector2 with its X and Y set to 0.

This is not part of the C++ API, so there's no reason to add it to the .Net binding.

Feel free to ignore the changes to the project files

Feel free to only commit what is meant to be merged :p
If I can't merge your pull request by just clicking "merge" (i.e. if it's not perfectly clean), it's unlikely to be merged one day.

@cuddlyogre
Copy link
Author

I was under the false impression that it was not recommended to overload operators on immutable objects. After further research, I found it would be best to overload the operators and do away with Equals(). Without Equals(), there is no need for GetHashCode().

Vector2.zero was just a nice shortcut I got used to, which would be nice to have, but is not nearly as critical as == and !=, so I will remove it from my next request.

@cuddlyogre cuddlyogre closed this Nov 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants