-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathPoint2D.java
More file actions
41 lines (30 loc) · 756 Bytes
/
Point2D.java
File metadata and controls
41 lines (30 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.psjava.ds.geometry;
import org.psjava.StrictEqualityTester;
public class Point2D<T> {
public static <T> Point2D<T> create(T x, T y) {
return new Point2D<T>(x, y);
}
private final T x;
private final T y;
private Point2D(T x, T y) {
this.x = x;
this.y = y;
}
public T x() {
return x;
}
public T y() {
return y;
}
@Override
public final boolean equals(Object o) {
return StrictEqualityTester.areEqual(this, o, (a, b) -> a.x.equals(b.x) && a.y.equals(b.y));
}
public final int hashCode() {
return x.hashCode() ^ y.hashCode();
}
@Override
public String toString() {
return "(" + x + "," + y + ")";
}
}