Slick Forums

Discuss the Slick 2D Library
It is currently Sat Feb 17, 2018 9:17 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun May 30, 2010 7:28 pm 
Offline

Joined: Wed May 19, 2010 4:50 pm
Posts: 28
Slick has it, but phys2d does not. Obviously, equals() and hashcode() are used for important goodies like collections.

The main reason I don't do it myself is because I can't commit to your repo. And if I wrote something, I don't know if you'd be willing to include it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2010 8:58 am 
Offline

Joined: Wed May 19, 2010 4:50 pm
Posts: 28
Added to phys2d Vector2f (copied from Slick's Vector2f implementation):

Code:
   
   /**
    * @see java.lang.Object#equals(java.lang.Object)
    */
   public boolean equals(Object other)
   {   
      if (other == null) return false;
       if (other == this) return true;
      if (other instanceof Vector2f) {
         Vector2f o = ((Vector2f) other);
         return (o.x == x) && (o.y == y);
      }
      
      return false;
   }
   
   /**
    * @see java.lang.Object#hashCode()
    */
   public int hashCode() {
        return 997 * ((int)x) ^ 991 * ((int)y); //large primes!
   }


...Would be nice if this were included in phys2d, so I don't have to keep it in a separate repository. :wink:


Last edited by NickZA on Mon May 31, 2010 8:38 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2010 7:38 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
There is no reason to include equals or hashCode() in any interface (eg ROVector2f) - they are already available via Object.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2010 8:37 pm 
Offline

Joined: Wed May 19, 2010 4:50 pm
Posts: 28
Hmm, good point. I removed that from the above post.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group