-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldPosition.cs
More file actions
87 lines (77 loc) · 3.14 KB
/
Copy pathWorldPosition.cs
File metadata and controls
87 lines (77 loc) · 3.14 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
using System;
using System.Globalization;
namespace CMAPI
{
/// <summary>Represents a position in Planet Crafter's three-dimensional world.</summary>
/// <remarks>
/// This CMAPI-owned value can be used by mods without referencing
/// <c>UnityEngine.Vector3</c>. Equality compares the three floating-point
/// components exactly.
/// </remarks>
public readonly struct WorldPosition : IEquatable<WorldPosition>
{
/// <summary>Gets the horizontal X coordinate.</summary>
public float X { get; }
/// <summary>Gets the vertical Y coordinate.</summary>
public float Y { get; }
/// <summary>Gets the horizontal Z coordinate.</summary>
public float Z { get; }
/// <summary>Creates a world position from three coordinates.</summary>
/// <param name="x">The horizontal X coordinate.</param>
/// <param name="y">The vertical Y coordinate.</param>
/// <param name="z">The horizontal Z coordinate.</param>
public WorldPosition(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>Checks whether this position exactly matches another position.</summary>
/// <param name="other">The position to compare.</param>
/// <returns><see langword="true"/> if all three coordinates are equal.</returns>
public bool Equals(WorldPosition other)
{
return X.Equals(other.X) &&
Y.Equals(other.Y) &&
Z.Equals(other.Z);
}
/// <inheritdoc/>
public override bool Equals(object? obj)
{
return obj is WorldPosition other && Equals(other);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return HashCode.Combine(X, Y, Z);
}
/// <summary>Formats the position as <c>(X, Y, Z)</c>.</summary>
/// <returns>A culture-invariant, human-readable coordinate string.</returns>
public override string ToString()
{
return string.Format(
CultureInfo.InvariantCulture,
"({0:0.##}, {1:0.##}, {2:0.##})",
X,
Y,
Z
);
}
/// <summary>Checks two positions for exact coordinate equality.</summary>
/// <param name="left">The first position to compare.</param>
/// <param name="right">The second position to compare.</param>
/// <returns><see langword="true"/> if all three coordinates are equal.</returns>
public static bool operator ==(WorldPosition left, WorldPosition right)
{
return left.Equals(right);
}
/// <summary>Checks two positions for any coordinate difference.</summary>
/// <param name="left">The first position to compare.</param>
/// <param name="right">The second position to compare.</param>
/// <returns><see langword="true"/> if any coordinate is different.</returns>
public static bool operator !=(WorldPosition left, WorldPosition right)
{
return !left.Equals(right);
}
}
}