public class Vertex extends java.lang.Object implements java.lang.Comparable<Vertex>
Vertex
class.
This represents a vertex in a graph. Vertices can be either
2D or 3D vertices. Each Vertex
maintains a set of
incident edges and a set of adjacent vertices. The degree of the
Vertex
is also kept in a field. A boolean field
for checking whether a vertex has been visited is included for algorithm
purposes. Vertices are compared based on their Euclidean distance from the
origin using the Comparable interface.Vertex
is stored using the processing
PVector class.Constructor and Description |
---|
Vertex(float x,
float y)
This is the constructor for 2D
Vertex objects.
In this case the z-coordinate is set to 0. |
Vertex(float x,
float y,
float z)
This is the constructor for
Vertex objects. |
Vertex(int x,
int y)
This is the constructor for 2D
Vertex objects.
In this case the z-coordinate is set to 0. |
Vertex(int x,
int y,
int z)
This is the constructor for 3D
Vertex objects. |
Vertex(processing.core.PVector vector)
This is the constructor for
Vertex objects. |
Modifier and Type | Method and Description |
---|---|
void |
addIncidentEdge(Edge edge)
This add's an edge to the Vertex's list of incident edges.
|
int |
compareTo(Vertex otherVertex)
The method inhereted from the Comparable interface.
|
boolean |
equals(java.lang.Object obj)
Tests for the equality of two vertices.
|
java.util.TreeSet<Vertex> |
getAdjacentVertices()
Returns a sorted
TreeSet containing the adjacent
vertices to this Vertex . |
int |
getDegree()
Returns the degree of the
Vertex . |
java.util.TreeSet<Edge> |
getIncidentEdges()
Returns a sorted
TreeSet containing the incident edges
to this Vertex . |
processing.core.PVector |
getPVector()
Returns the PVector that holds the location of this vertex.
|
float |
getX()
Getter for the x-coordinate.
|
float |
getY()
Getter for the y-coordinate.
|
float |
getZ()
Getter for the z-coordinate.
|
boolean |
hasBeenVisited()
Returns true if the
Vertex has been marked as visited. |
boolean |
isAdjacentTo(Vertex v)
Tests whether this
Vertex is adjacent to the other
Vertex , meaning they are contained in an Edge . |
boolean |
isIncidentTo(Edge e)
Tests whether this
Vertex is incident to the given
Edge . |
void |
removeIncidentEdge(Edge edge)
This removes an edge from the Vertex's list of incident edges.
|
void |
setLocation(processing.core.PVector newLocation)
This changes the location of the
Vertex . |
void |
setVisited(boolean visited)
Setter for the boolean visited field.
|
void |
setX(float x)
Setter for the x-coordinate.
|
void |
setY(float y)
Setter for the y-coordinate.
|
void |
setZ(float z)
Setter for the z-coordinate.
|
public Vertex(processing.core.PVector vector)
Vertex
objects.vector
- the processing PVector whose location is to be copied to
this Vertex
public Vertex(int x, int y, int z)
Vertex
objects.x
- the x-coordinate.y
- the y-coordinate.z
- the z-coordinate.public Vertex(int x, int y)
Vertex
objects.
In this case the z-coordinate is set to 0.x
- the x-coordinate.y
- the y-coordinate.public Vertex(float x, float y, float z)
Vertex
objects.x
- the x-coordinate.y
- the y-coordinate.z
- the z-coordinate.public Vertex(float x, float y)
Vertex
objects.
In this case the z-coordinate is set to 0.x
- the x-coordinate.y
- the y-coordinate.public void addIncidentEdge(Edge edge)
Vertex
is incremented as a result.edge
- the Edge
to be added.public void removeIncidentEdge(Edge edge)
Vertex
is decremented as a result.edge
- the Edge
to be removed.public java.util.TreeSet<Vertex> getAdjacentVertices()
TreeSet
containing the adjacent
vertices to this Vertex
.public java.util.TreeSet<Edge> getIncidentEdges()
TreeSet
containing the incident edges
to this Vertex
.public processing.core.PVector getPVector()
public float getX()
public void setX(float x)
x
- the new x-coordinate.public float getY()
public void setY(float y)
y
- the new y-coordinate.public float getZ()
public void setZ(float z)
z
- the new z-coordinate.public void setLocation(processing.core.PVector newLocation)
Vertex
.newLocation
- the new PVector
location.public int getDegree()
Vertex
.public void setVisited(boolean visited)
visited
- the new boolean visited flag.public boolean hasBeenVisited()
Vertex
has been marked as visited.public boolean isAdjacentTo(Vertex v)
Vertex
is adjacent to the other
Vertex
, meaning they are contained in an Edge
.v
- the Vertex
in question.Edge
.public boolean isIncidentTo(Edge e)
Vertex
is incident to the given
Edge
.e
- the Edge
to be tested.Edge
is incident to this.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(Vertex otherVertex)
compareTo
in interface java.lang.Comparable<Vertex>
otherVertex
- the other Vertex
to be compared.Vertex
.