blob: 807446162ebffb6b5a5687eff984e08b4e8a389a (
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
package bezier.geom;
/**
* Represents a two-dimensional point.
*
* @author bjculkin
*
*/
public class TDPoint {
/**
* The x coordinate.
*/
public final double x;
/**
* The y coordinate.
*/
public final double y;
/**
* Create a new two-dimensional point.
*
* @param x
* The x coordinate.
* @param y
* The y coordinate.
*/
public TDPoint(double x, double y) {
this.x = x;
this.y = y;
}
/**
* Create a new two-dimensional point.
*
* @param x
* The x coordinate.
* @param y
* The y coordinate.
* @return A point with those coordinates.
*/
public static TDPoint p2(double x, double y) {
return new TDPoint(x, y);
}
/**
* Return a new scaled point.
*
* @param s
* The amount to scale by.
* @return A point scaled by the specified amount.
*/
public TDPoint multiply(double s) {
return p2(x * s, y * s);
}
/**
* Add two points together.
*
* @param p1
* The first point to add.
* @param p2
* The second point to add.
* @return The sum of the points.
*/
public static TDPoint add(TDPoint p1, TDPoint p2) {
return p2(p1.x + p2.x, p1.y + p2.y);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TDPoint other = (TDPoint) obj;
if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
return false;
if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
return false;
return true;
}
@Override
public String toString() {
return "TDPoint [x=" + x + ", y=" + y + "]";
}
/**
* Convert this point to a two-dimensional homogeneous point.
*
* @return A homogeneous version of this point.
*/
public TDHPoint toTDHPoint() {
return new TDHPoint(x, y);
}
}
|