-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocationF.cs
117 lines (96 loc) · 2.74 KB
/
LocationF.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
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
using ElfKingdom;
namespace SkillZ
{
public class LocationF
{
public float x;
public float y;
public LocationF() { }
public LocationF(float x, float y)
{
this.x = x;
this.y = y;
}
public static LocationF operator /(LocationF location, float b)
{
location.x /= b;
location.y /= b;
return location;
}
public static LocationF operator -(LocationF location, LocationF b)
{
location.x -= b.x;
location.y -= b.y;
return location;
}
public static LocationF operator +(LocationF location, LocationF b)
{
location.x += b.x;
location.y += b.y;
return location;
}
public static LocationF operator *(LocationF location, float b)
{
location.x *= b;
location.y *= b;
return location;
}
public float Dot(LocationF l2)
{
return x * l2.x + y * l2.y;
}
public float Magnitude()
{
return Mathf.Sqrt(y * y + x * x);
}
public LocationF Normalized()
{
float magnitude = Magnitude();
if (magnitude > 0)
{
return this / magnitude;
}
else
{
return new LocationF(0, 0);
}
}
public Location GetIntLocation()
{
return new Location(Mathf.RoundToInt(y), Mathf.RoundToInt(x));
}
public float Distance(MapObject target)
{
return Mathf.Sqrt(Mathf.Pow(x - target.GetLocation().Col, 2) + Mathf.Pow(y - target.GetLocation().Row, 2));
}
public bool InRange(MapObject target, float distance)
{
return Distance(target) <= distance;
}
public override string ToString()
{
return $"LocationF({x},{y})";
}
public override bool Equals(object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if(obj is Location)
{
if (!GetType().Equals(obj.GetType())) return false;
Location other = (Location)obj;
return Mathf.RoundToInt(x) == other.Col && Mathf.RoundToInt(y) == other.Row;
}
else
{
if (!GetType().Equals(obj.GetType())) return false;
LocationF other = (LocationF)obj;
return x == other.x && y == other.y;
}
}
public override int GetHashCode()
{
return Mathf.RoundToInt(x);
}
}
}