-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
63 lines (54 loc) · 1.57 KB
/
Graph.java
File metadata and controls
63 lines (54 loc) · 1.57 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
/**
* Created by sayleebhide on 11/30/17.
*/
import java.util.ArrayList;
public class Graph
{
ArrayList<Vertex> vertices = new ArrayList<>();
int numberOfVertices;
public Graph()
{
numberOfVertices = 0;
}
public Vertex addVertex(Vertex vert)
{
if( getVertex(vert.point.x,vert.point.y) == null )
{
vertices.add(vert);
numberOfVertices++;
return vert;
}
else
return getVertex(vert.point.x,vert.point.y);
}
public Vertex getVertex(double x, double y)
{
Vertex p;
String coordinates[] = new String[4];
double coordDouble[] = new double[4];
for(int i = 0; i < vertices.size(); i++)
{
p = vertices.get(i);
coordinates[0] = Double.toString(x);
coordinates[1] = Double.toString(y);
coordinates[2] = Double.toString(p.point.x);
coordinates[3] = Double.toString(p.point.y);
for( int s = 0; s < 4; s++)
{
if(coordinates[s].length() > 6)
{
coordinates[s] = coordinates[s].substring(0,8);
}
coordDouble[s] = Double.parseDouble(coordinates[s]);
}
if( coordDouble[0] == coordDouble[2]
&& coordDouble[1] == coordDouble[3] )
return p;
}
return null;
}
public ArrayList<Vertex> getAllVertices()
{
return vertices;
}
}