Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

Vector3i class
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=23&t=532
Page 1 of 1

Author:  ianjosephfischer [ Sun Aug 25, 2013 6:41 am ]
Post subject:  Vector3i class

Here is a Vector3 int class I use and you are welcome to use in your projects. May come in handy for people using Cubiquity.

Attachments:
File comment: Serializable vector int class.
Vector3i.cs.txt [3.95 KiB]
Downloaded 764 times

Author:  David Williams [ Sun Aug 25, 2013 7:58 am ]
Post subject:  Re: Vector3i class

Interesting, thanks. We do actually have the IntVector3 class but it's rather basic by comparison. I think we can use yours instead if you can say the code is under the zlib license (or public domain). We'll have to think about the class name though.

Also, what is the purpose of the shift-by-2 in GetHashCode()?

Author:  ianjosephfischer [ Sun Aug 25, 2013 8:14 pm ]
Post subject:  Re: Vector3i class

Feel free to call the class whatever you like. Just when ever I port your code that is one of the first things I do is convert the vector class.

The reason for overwriting GetHashCode can be found in http://stackoverflow.com/questions/7329 ... ethashcode.
It has to be done when overwriting the equals. The code of the shifting comes directly from Unity's Vector3 version. I used "ISpy" which is a program that can decompile dlls and I opened "UnityEngine.dll". Then went to its "UnityEngine" namespace and looked up Vector3. I choose to use their version because I did not want to spend extra time figuring out what they needed there but if it worked on floats (32 bit objects) then it should work on ints and produce similar results.

All I can assume is that it is making a value to use for comparison vs another vector similar to the Equal code in which the values are specifically readable to see what is going on during the comparison. It is probably used in sorted containers such as maps.

Author:  David Williams [ Mon Aug 26, 2013 8:44 am ]
Post subject:  Re: Vector3i class

I think it's fine - the main requirement seems to be that equal objects have equal hash codes and it fulfils that. However, we do need to be careful with licensing, and if it came out of Unity then we will reimplement just that function before we can claim it is open source. I think we can just hash the three ints separately and XOR the results, so that isn't a problem.

Apart from that, can you state that you are happy for that code to be under the zlib license? Just write "The zlib license is fine" or something, and I'll add it to the repository.

Author:  ianjosephfischer [ Mon Aug 26, 2013 9:24 pm ]
Post subject:  Re: Vector3i class

The zlib license is fine

Author:  David Williams [ Tue Aug 27, 2013 8:55 am ]
Post subject:  Re: Vector3i class

Great, thanks, I've logged an issue so it will get put in the repository at some point soon.

Author:  ianjosephfischer [ Sun Oct 27, 2013 6:52 am ]
Post subject:  Re: Vector3i class

Added a small fix for equality operators in cases where a vector3i is null, if one is then i report they are equal if they both are.

Alternatively i can throw some exception or error, whatever you think is best.

Attachments:
Vector3i.cs.txt [5.65 KiB]
Downloaded 714 times

Author:  David Williams [ Sun Oct 27, 2013 9:32 am ]
Post subject:  Re: Vector3i class

Great, I've added this to the repository.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/