Tuesday, March 03, 2009

the problem with package managers is...

...abandoned packages don't get updated very often. Hashing Tuple3d's didn't give the expected results. I was using ubuntu's vecmath package. The hashCode() values are the same, but the equals method falls back to Object.equals because the Tuple3d only defines Tuple3d.equals (Tuple3d). So you get very strange results if you're hashing with Tuple's.

Bugged!

The vecmath Tuple3d class doesn't define equals correctly.

the method missing (from the GPL2'd java3d vecmath) is

public boolean equals(Object t1)
{
try {
Tuple3d t2 = (Tuple3d) t1;
return(this.x == t2.x &&
this.y == t2.y && this.z == t2.z);
}
catch (ClassCastException e1) {return false;}
catch (NullPointerException e2) {return false;}

}

boolean equals (Tuple3d) isn't enough!

public class NewClass
{
public static void main (String[] args)
{
Vector3d v = new Vector3d(1,2,3);
Point3d p = new Point3d(1,2,3);

System.out.println(
v.equals( (Object)p));
System.out.println(
v.equals( (Object)new Point3d(1,2,3))
== v.equals( p ));
}
}

No comments:

Post a Comment