using Robust.Shared.Maths; using Robust.Shared.Serialization; using System; using JetBrains.Annotations; namespace Robust.Shared.Map { /// /// Contains the coordinates of a position on the rendering screen. /// [PublicAPI] [Serializable, NetSerializable] public readonly struct ScreenCoordinates : IEquatable { /// /// Position on the rendering screen. /// public readonly Vector2 Position; /// /// Screen position on the X axis. /// public float X => Position.X; /// /// Screen position on the Y axis. /// public float Y => Position.Y; /// /// The window which the coordinates are on. /// public readonly WindowId Window; /// /// Constructs a new instance of ScreenCoordinates. /// /// Position on the rendering screen. /// Window for the coordinates. public ScreenCoordinates(Vector2 position, WindowId window) { Position = position; Window = window; } /// /// Constructs a new instance of ScreenCoordinates. /// /// X axis of a position on the screen. /// Y axis of a position on the screen. /// Window for the coordinates. public ScreenCoordinates(float x, float y, WindowId window) { Position = new Vector2(x, y); Window = window; } public bool IsValid => Window != WindowId.Invalid; /// public override string ToString() { return $"({Position.X}, {Position.Y}, W{Window.Value})"; } /// public bool Equals(ScreenCoordinates other) { return Position.Equals(other.Position) && Window == other.Window; } /// public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; return obj is ScreenCoordinates other && Equals(other); } /// public override int GetHashCode() { return HashCode.Combine(Position, Window); } /// /// Check for equality by value between two objects. /// public static bool operator ==(ScreenCoordinates a, ScreenCoordinates b) { return a.Equals(b); } /// /// Check for inequality by value between two objects. /// public static bool operator !=(ScreenCoordinates a, ScreenCoordinates b) { return !a.Equals(b); } public void Deconstruct(out Vector2 pos, out WindowId window) { pos = Position; window = Window; } } }