-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntVector2.cs
More file actions
97 lines (79 loc) · 1.95 KB
/
IntVector2.cs
File metadata and controls
97 lines (79 loc) · 1.95 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
96
97
using UnityEngine;
[System.Serializable]
public struct IntVector2
{
public static IntVector2 zero = new IntVector2(0,0);
public static IntVector2 neg1 = new IntVector2(-1,-1);
public static IntVector2 one = new IntVector2(1,1);
public static IntVector2 north = new IntVector2(0,1);
public static IntVector2 south = new IntVector2(0,-1);
public static IntVector2 east = new IntVector2(1,0);
public static IntVector2 west = new IntVector2(-1,0);
public static IntVector2 northeast = new IntVector2(1,1);
public static IntVector2 northwest = new IntVector2(-1,1);
public static IntVector2 southeast = new IntVector2(1,-1);
public static IntVector2 southwest = new IntVector2(-1,-1);
public int x;
public int y;
public IntVector2(int x1, int y1)
{
x = x1;
y = y1;
}
public IntVector2 Right()
{
return new IntVector2(x+1, y);
}
public IntVector2 Left()
{
return new IntVector2(x-1, y);
}
public IntVector2 Up()
{
return new IntVector2(x, y+1);
}
public IntVector2 Down()
{
return new IntVector2(x, y-1);
}
public IntVector2 UpRight()
{
return new IntVector2(x+1, y+1);
}
public IntVector2 UpLeft()
{
return new IntVector2(x-1, y+1);
}
public IntVector2 DownRight()
{
return new IntVector2(x+1, y-1);
}
public IntVector2 DownLeft()
{
return new IntVector2(x-1, y-1);
}
public override string ToString()
{
return "["+x+","+y+"]";
}
public static explicit operator IntVector2(Vector2 v)
{
return new IntVector2((int)v.x, (int)v.y);
}
public override bool Equals(object obj)
{
return obj is IntVector2 && this == (IntVector2)obj;
}
public override int GetHashCode()
{
return x.GetHashCode() ^ y.GetHashCode();
}
public static bool operator ==(IntVector2 a, IntVector2 b )
{
return a.x == b.x && a.y == b.y;
}
public static bool operator !=(IntVector2 a, IntVector2 b )
{
return !(a == b);
}
}