-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPosition.cs
More file actions
88 lines (72 loc) · 2.87 KB
/
Position.cs
File metadata and controls
88 lines (72 loc) · 2.87 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
using System;
namespace CreatureScriptsParser
{
[Serializable]
public struct Position
{
public float x;
public float y;
public float z;
public float orientation;
public Position(float x, float y, float z)
{ this.x = x; this.y = y; this.z = z; orientation = 0.0f; }
public Position(float x, float y, float z, float o)
{ this.x = x; this.y = y; this.z = z; orientation = o; }
public bool IsValid()
{
return x != 0.0f && y != 0.0f;
}
public double GetExactDist2dSq(Position mainPos, Position comparePos)
{
double dx = mainPos.x - comparePos.x; double dy = mainPos.y - comparePos.y;
return dx * dx + dy * dy;
}
public float GetExactDist2d(Position comparePos)
{
return (float)Math.Sqrt(GetExactDist2dSq(this, comparePos));
}
public float GetDistance(Position comparePos)
{
return (float)Math.Sqrt(Math.Pow((x - comparePos.x), 2) + Math.Pow((y - comparePos.y), 2) + Math.Pow((z - comparePos.z), 2));
}
public static Position operator -(Position firstPos, Position secondPos)
{
float x = firstPos.x - secondPos.x;
float y = firstPos.y - secondPos.y;
float z = firstPos.z - secondPos.z;
return new Position(x, y, z);
}
public static bool operator ==(Position firstPos, Position secondPos)
{
return firstPos.x == secondPos.x && firstPos.y == secondPos.y && firstPos.z == secondPos.z && firstPos.orientation == secondPos.orientation;
}
public static bool operator !=(Position firstPos, Position secondPos)
{
return firstPos.x != secondPos.x || firstPos.y != secondPos.y || firstPos.z != secondPos.z || firstPos.orientation != secondPos.orientation;
}
public bool Equals(Position other)
{
return x.Equals(other.x) && y.Equals(other.y) && z.Equals(other.z) && orientation.Equals(other.orientation);
}
public override bool Equals(object obj)
{
return obj is Position other && Equals(other);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = x.GetHashCode();
hashCode = (hashCode * 397) ^ y.GetHashCode();
hashCode = (hashCode * 397) ^ z.GetHashCode();
hashCode = (hashCode * 397) ^ orientation.GetHashCode();
return hashCode;
}
}
public override string ToString()
{
string position = x.GetValueWithoutComma() + "f, " + y.GetValueWithoutComma() + "f, " + z.GetValueWithoutComma() + "f, " + orientation.GetValueWithoutComma() + "f";
return position.Replace(", 0f", ", 0.0f");
}
}
}