-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeature.java
More file actions
112 lines (93 loc) · 3.17 KB
/
Copy pathFeature.java
File metadata and controls
112 lines (93 loc) · 3.17 KB
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
112
import java.lang.Comparable;
import java.lang.NullPointerException;
// A class to contain a feature.
public class Feature implements Comparable
{
// The variables associated with a feature.
public Point start; // The starting point.
public int theta; // Theta value (in degrees).
public int length; // The length (in cells).
public int type; // The type of feature (player 1 or player 2).
// The constructor.
public Feature()
{
start = new Point();
theta = -1;
length = -1;
type = -1;
}
// A constructor that allows specification of all these.
public Feature(int r, int c, int theta, int length, int type)
{
start = new Point(r, c);
this.theta = theta;
this.length = length;
this.type = type;
}
// Get the starting point.
public Point getStart()
{
return start;
}
// Get the ending point.
public Point getEnd()
{
// Declare local variables.
Point end = new Point();
double hypo = 1.0f;
// Find the hypotenuse of the "triangle."
if ((theta / 45) % 2 == 1) hypo = Math.sqrt(2);
// Compute end point.
end.r = start.r - Math.max(0, (length - 1)) * (int)Math.round(hypo * Math.sin((theta) * Math.PI / 180));
end.c = start.c + Math.max(0, (length - 1)) * (int)Math.round(hypo * Math.cos((theta) * Math.PI / 180));
// Return.
return end;
}
// Get the previous point (i.e. following the length to -1).
public Point getPrevious()
{
// Declare local variables.
Point prev = new Point();
double hypo = 1.0f;
// Find the hypotenuse of the "triangle."
if ((theta / 45) % 2 == 1) hypo = Math.sqrt(2);
// Compute previous point.
prev.r = start.r - (int)Math.round(hypo * Math.sin((theta + 180) * Math.PI / 180));
prev.c = start.c + (int)Math.round(hypo * Math.cos((theta + 180) * Math.PI / 180));
// Return.
return prev;
}
// Get the next point (i.e. following the length to len+1).
public Point getNext()
{
// Declare local variables.
Point next = new Point();
double hypo = 1.0f;
// Find the hypotenuse of the "triangle."
if ((theta / 45) % 2 == 1) hypo = Math.sqrt(2);
// Compute next point.
next.r = start.r - length * (int)Math.round(hypo * Math.sin((theta) * Math.PI / 180));
next.c = start.c + length * (int)Math.round(hypo * Math.cos((theta) * Math.PI / 180));
// Return.
return next;
}
// Check equality with another object.
public boolean equals(Object o)
{
//if (type == ((Feature)o).type && length == ((Feature)o).length) return true;
if (length == ((Feature)o).length) return true;
else return false;
}
// Compare this to another object.
public int compareTo(Object o)
{
//if (o == null) throw java.lang.NullPointerException;
if (length == ((Feature)o).length) return 0;
else if (length > ((Feature)o).length) return -1;
else if (length < ((Feature)o).length) return 1;
//if (type == ((Feature)o).type && length == ((Feature)o).length) return 0;
//else if (type > ((Feature)o).type || (type == ((Feature)o).type && length > ((Feature)o).length)) return -1;
//else if (type < ((Feature)o).type || (type == ((Feature)o).type && length < ((Feature)o).length)) return 1;
return 1;
}
}