-
Notifications
You must be signed in to change notification settings - Fork 0
/
PixelVertex.java
83 lines (70 loc) · 1.96 KB
/
PixelVertex.java
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
// import java.awt.Color;
import java.util.LinkedList;
public class PixelVertex{
private int x;
private int y;
private LinkedList<PixelVertex> neighbours;
public PixelVertex(int x, int y) {
this.x = x;
this.y = y;
neighbours = new LinkedList<PixelVertex>();
}
/* getX()
Return the x-coordinate of the pixel corresponding to this vertex.
*/
public int getX(){
return this.x;
}
/* getY()
Return the y-coordinate of the pixel corresponding to this vertex.
*/
public int getY(){
return this.y;
}
/* getNeighbours()
Return an array containing references to all neighbours of this vertex.
The size of the array must be equal to the degree of this vertex (and
the array may therefore contain no duplicates).
*/
public LinkedList<PixelVertex> getNeighbours(){
return this.neighbours;
}
/* addNeighbour(newNeighbour)
Add the provided vertex as a neighbour of this vertex.
*/
public void addNeighbour(PixelVertex newNeighbour){
if (!neighbours.contains(newNeighbour)) {
neighbours.add(newNeighbour);
}
}
/* removeNeighbour(neighbour)
If the provided vertex object is a neighbour of this vertex,
remove it from the list of neighbours.
*/
public void removeNeighbour(PixelVertex neighbour){
neighbours.remove(neighbour);
}
/* getDegree()
Return the degree of this vertex. Since the graph is simple,
the degree is equal to the number of distinct neighbours of this vertex.
*/
public int getDegree(){
return neighbours.size();
}
/* isNeighbour(otherVertex)
Return true if the provided PixelVertex object is a neighbour of this
vertex and false otherwise.
*/
public boolean isNeighbour(PixelVertex otherVertex){
return neighbours.contains(otherVertex);
}
public boolean equals(Object other) {
if (other instanceof PixelVertex) {
PixelVertex o = (PixelVertex) other;
return this.x == o.getX() && this.y == o.getY();
}
return false;
}
}
// testing github.dev
// WTF I HAVE FOUND