-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosition.java
More file actions
95 lines (80 loc) · 1.65 KB
/
Position.java
File metadata and controls
95 lines (80 loc) · 1.65 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
/**
* Various methods for LSD
* Allen Mitro
* June 09 2016
*/
public class Position
{
private int x;
private int y;
public Position()
{
x = 0;
y = 0;
}
public Position(int nx,int ny)
{
x = nx;
y = ny;
}
public Position (Position npos)
{
x = npos.getX();
y = npos.getY();
}
public Position (String npos)//string in form (x,y)
{
x = 0;
y = 0;
for(int a = 0;a<npos.length();a++)
{
if(npos.charAt(a)==',')
{
try
{x = Integer.parseInt(npos.substring(0,a));}
catch(Exception e)
{System.out.println("Could not parse "+npos.substring(0,a));}
try
{y = Integer.parseInt(npos.substring(a+1));}
catch(Exception e)
{System.out.println("Could not parse "+npos.substring(a+1));}
}
}
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public void setX(int nx)
{
x = nx;
}
public void setY(int ny)
{
y = ny;
}
public int distance(Position checkplace)
{
return Math.abs(x-checkplace.getX())+Math.abs(y-checkplace.getY());
}
public int distance(int nx, int ny)
{
return Math.abs(x-nx)+Math.abs(y-ny);
}
public boolean equals(Position somePos)
{
if(x == somePos.getX() && y == somePos.getY())
{
return true;
}
return false;
}
public String toString()
{
return "("+x+","+y+")";
}
}