Slick Forums
http://slick.ninjacave.com/forum/

RFE: net.phys2d.math.Vector2f equals() and hashcode()
http://slick.ninjacave.com/forum/viewtopic.php?f=9&t=2512
Page 1 of 1

Author:  NickZA [ Sun May 30, 2010 7:28 pm ]
Post subject:  RFE: net.phys2d.math.Vector2f equals() and hashcode()

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?

Author:  NickZA [ Mon May 31, 2010 8:58 am ]
Post subject: 

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:

Author:  MatthiasM [ Mon May 31, 2010 7:38 pm ]
Post subject: 

There is no reason to include equals or hashCode() in any interface (eg ROVector2f) - they are already available via Object.

Author:  NickZA [ Mon May 31, 2010 8:37 pm ]
Post subject: 

Hmm, good point. I removed that from the above post.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/