blob: 40553a970b3875bac0f28e030660c512acfeaa33 (
plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
package bezier.geom;
/**
* A two-dimensional homogeneous point.
*
* @author bjculkin
*
*/
public class TDHPoint extends TDPoint {
/**
* The homogeneous coordinate for the point.
*/
public final double z;
/**
* Create a new two-dimensional homogeneous point.
*
* @param x
* The x coordinate.
* @param y
* The y coordinate.
* @param z
* The homogeneous coordinate.
*/
public TDHPoint(double x, double y, double z) {
super(x, y);
this.z = z;
}
/**
* Create a new two-dimensional homogeneous point.
*
* The homogeneous coordinate is set to 1.
*
* @param x
* The x coordinate.
* @param y
* The y coordinate.
*/
public TDHPoint(double x, double y) {
this(x, y, 1);
}
/**
* Convert this point to a plain two-dimensional point.
*
* @return A two-dimensional version of this point.
*/
public TDPoint toTDPoint() {
/*
* Convert back down by dividing each coordinate by the homogeneous value.
*/
return new TDPoint(x / z, y / z);
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
long temp;
temp = Double.doubleToLongBits(z);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
TDHPoint other = (TDHPoint) obj;
if (Double.doubleToLongBits(z) != Double.doubleToLongBits(other.z))
return false;
return true;
}
@Override
public String toString() {
return "TDHPoint [z=" + z + ", x=" + x + ", y=" + y + "]";
}
}
|