It is currently Wed Dec 11, 2019 1:05 am


All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Vector3i class
PostPosted: Sun Aug 25, 2013 6:41 am 
User avatar

Joined: Sun Aug 25, 2013 4:13 am
Posts: 10
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 494 times
Top
Offline Profile  
Reply with quote  
 Post subject: Re: Vector3i class
PostPosted: Sun Aug 25, 2013 7:58 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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()?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Vector3i class
PostPosted: Sun Aug 25, 2013 8:14 pm 
User avatar

Joined: Sun Aug 25, 2013 4:13 am
Posts: 10
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Vector3i class
PostPosted: Mon Aug 26, 2013 8:44 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Vector3i class
PostPosted: Mon Aug 26, 2013 9:24 pm 
User avatar

Joined: Sun Aug 25, 2013 4:13 am
Posts: 10
The zlib license is fine


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Vector3i class
PostPosted: Tue Aug 27, 2013 8:55 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Great, thanks, I've logged an issue so it will get put in the repository at some point soon.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Vector3i class
PostPosted: Sun Oct 27, 2013 6:52 am 
User avatar

Joined: Sun Aug 25, 2013 4:13 am
Posts: 10
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 440 times
Top
Offline Profile  
Reply with quote  
 Post subject: Re: Vector3i class
PostPosted: Sun Oct 27, 2013 9:32 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Great, I've added this to the repository.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net