-
Notifications
You must be signed in to change notification settings - Fork 0
/
Location.cs
72 lines (56 loc) · 1.4 KB
/
Location.cs
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
using UnityEngine;
public class Location
{
public int Row { get; set; }
public int Col { get; set; }
public Location() { }
public Location(int row, int col)
{
Row = row;
Col = col;
}
public Location(Location loc)
{
Row = loc.Row;
Col = loc.Col;
}
public Vector2 ToVector()
{
return new Vector2(Col, -Row);
}
public override string ToString()
{
return "(" + Row + ", " + Col + ")";
}
public double DistanceTo(Location loc)
{
return Util.L1Distance(this, loc);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
Location other = obj as Location;
return Col == other.Col
&& Row == other.Row;
}
public static bool operator ==(Location l1, Location l2)
{
return l1.Equals(l2);
}
public static bool operator !=(Location l1, Location l2)
{
return !(l1 == l2);
}
public override int GetHashCode()
{
int hash = 13;
hash = (hash * 7) + Row.GetHashCode();
hash = (hash * 7) + Col.GetHashCode();
return hash;
}
}