using System; using System.Runtime.InteropServices; using Newtonsoft.Json; namespace Robust.Shared.Maths { [JsonObject(MemberSerialization.Fields)] [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Vector2u : IEquatable { /// /// The X component of the Vector2i. /// public uint X; /// /// The Y component of the Vector2i. /// public uint Y; /// /// Construct a vector from its coordinates. /// /// X coordinate /// Y coordinate public Vector2u(uint x, uint y) { X = x; Y = y; } public readonly void Deconstruct(out uint x, out uint y) { x = X; y = Y; } /// /// Compare a vector to another vector and check if they are equal. /// /// Other vector to check. /// True if the two vectors are equal. public readonly bool Equals(Vector2u other) { return X == other.X && Y == other.Y; } /// /// Compare a vector to an object and check if they are equal. /// /// Other object to check. /// True if Object and vector are equal. public override readonly bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; return obj is Vector2u vec && Equals(vec); } /// /// Returns the hash code for this instance. /// /// A unique hash code for this instance. public override readonly int GetHashCode() { unchecked { return ((int) X * 397) ^ (int) Y; } } public static Vector2u operator /(Vector2u vector, uint divider) { return new(vector.X / divider, vector.Y / divider); } public static implicit operator Vector2(Vector2u vector) { return new(vector.X, vector.Y); } public static explicit operator Vector2u(Vector2 vector) { return new((uint) vector.X, (uint) vector.Y); } public static explicit operator Vector2i(Vector2u vector) { return new((int) vector.X, (int) vector.Y); } } }