Closed GoogleCodeExporter closed 9 years ago
[deleted comment]
This is because even parameterized collections, like, say ArrayList<Vector2D>,
use
equals(Object), not equals(Vector2D) when determining if an element is in the
list.
This is counter-intuitive because, in contrast, sorting collections like
PriorityQueue do do use the parameterized compareTo method, as specified by
Comparable<Vector2D>.
The set/list actually will return true for containing the same exact Vector2D
because
it will default to identity (==) in the base Object class equals, but it will
not
return true for contains when given a Vector2D that should be considered
equivalent
(x and y equal).
The included code should address the issue. It's possible that magnitude need
not be
considered for equality.
I will add this to the repository before project 2.
Original comment by b1m...@gmail.com
on 20 Feb 2008 at 10:32
Just as a side comment, you shouldn't depend too much on comparing floating
point
numbers for equality, unless you're being really careful. It's not hard to
stumble
into two different calculations that should mathematically result in the same
vector,
that would end up giving different Vector2Ds due to floating-point arithmetic
limitations.
Original comment by jfa...@gmail.com
on 13 Mar 2008 at 4:01
Original comment by jfa...@gmail.com
on 25 Mar 2008 at 10:47
Original issue reported on code.google.com by
a1tetris...@gmail.com
on 20 Feb 2008 at 9:08