Skip to content
Snippets Groups Projects
Commit 5e3a64fc authored by 3541's avatar 3541
Browse files

Point: Implement hashCode

This makes Point's hashCode implementation consistent with its equals
method, and allows the use of Point as a HashMap key.
parent b16e211a
Branches
No related tags found
1 merge request!1Point: Implement hashCode
package bagel.util;
import java.util.Objects;
/**
* Immutable class that represents a 2D point in space.
*/
......@@ -42,6 +44,11 @@ public class Point {
}
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
public double distanceTo(Point b) {
return asVector().sub(b.asVector()).length();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment