forked from RonenNess/UnityUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.cs
More file actions
executable file
·123 lines (110 loc) · 2.88 KB
/
Point.cs
File metadata and controls
executable file
·123 lines (110 loc) · 2.88 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Represent a point on the path-finding grid.
* Based on code and tutorial by Sebastian Lague (https://www.youtube.com/channel/UCmtyQOKKmrMVaKuRXz02jbQ).
*
* Author: Ronen Ness.
* Since: 2016.
*/
namespace NesScripts.Controls.PathFind
{
/// <summary>
/// A 2d point on the grid
/// </summary>
public struct Point
{
// point X
public int x;
// point Y
public int y;
/// <summary>
/// Init the point with values.
/// </summary>
public Point(int iX, int iY)
{
this.x = iX;
this.y = iY;
}
/// <summary>
/// Init the point with a single value.
/// </summary>
public Point(Point b)
{
x = b.x;
y = b.y;
}
/// <summary>
/// Get point hash code.
/// </summary>
public override int GetHashCode()
{
return x ^ y;
}
/// <summary>
/// Compare points.
/// </summary>
public override bool Equals(System.Object obj)
{
// check type
if (!(obj.GetType() == typeof(PathFind.Point)))
return false;
// check if other is null
Point p = (Point)obj;
if (ReferenceEquals(null, p))
{
return false;
}
// Return true if the fields match:
return (x == p.x) && (y == p.y);
}
/// <summary>
/// Compare points.
/// </summary>
public bool Equals(Point p)
{
// check if other is null
if (ReferenceEquals(null, p))
{
return false;
}
// Return true if the fields match:
return (x == p.x) && (y == p.y);
}
/// <summary>
/// Check if points are equal in value.
/// </summary>
public static bool operator ==(Point a, Point b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}
if (ReferenceEquals(null, a))
{
return false;
}
if (ReferenceEquals(null, b))
{
return false;
}
// Return true if the fields match:
return a.x == b.x && a.y == b.y;
}
/// <summary>
/// Check if points are not equal in value.
/// </summary>
public static bool operator !=(Point a, Point b)
{
return !(a == b);
}
/// <summary>
/// Set point value.
/// </summary>
public Point Set(int iX, int iY)
{
this.x = iX;
this.y = iY;
return this;
}
}
}