-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.java
More file actions
63 lines (57 loc) · 971 Bytes
/
Edge.java
File metadata and controls
63 lines (57 loc) · 971 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.ArrayList;
public class Edge
{
public Vertex a;
public Vertex b;
public int direction;
public ArrayList<Vertex> edgeSquares;
public Edge(Vertex a, Vertex b, int direction)
{
this.a = a;
this.b = b;
this.direction = direction;
edgeSquares = new ArrayList<Vertex>();
addLine(a.y, a.x, b.y, b.x);
}
public void addSquare(Vertex v)
{
edgeSquares.add(v);
}
public void removeSquare(Vertex v)
{
edgeSquares.remove(v);
}
public void addLine(int y1, int x1, int y2, int x2)
{
if (y1 == y2)
{
while (x1 > x2)
{
x1--;
addSquare(new Vertex(y1, x1, 0));
}
while (x1 < x2)
{
x1++;
addSquare(new Vertex(y1, x1, 0));
}
}
else
{
while (y1 > y2)
{
y1--;
addSquare(new Vertex(y1, x1, 0));
}
while (y1 < y2)
{
y1++;
addSquare(new Vertex(y1, x1, 0));
}
}
}
public String toString()
{
return "E: " + a.x + "," + a.y + " - " + b.x + "," + b.y;
}
}