Add methods for vector2i lengths (#3829)

This commit is contained in:
metalgearsloth
2023-03-10 09:05:23 +11:00
committed by GitHub
parent 1688b2d9c3
commit f9042b3c9f

View File

@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.Json.Serialization;
using Robust.Shared.Utility;
@@ -49,6 +50,24 @@ namespace Robust.Shared.Maths
return new(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y));
}
/// <summary>
/// Gets the length (magnitude) of the vector.
/// </summary>
public readonly float Length
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => MathF.Sqrt(LengthSquared);
}
/// <summary>
/// Gets the squared length of the vector.
/// </summary>
public readonly float LengthSquared
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => X * X + Y * Y;
}
/// <summary>
/// Compare a vector to another vector and check if they are equal.
/// </summary>
@@ -64,7 +83,7 @@ namespace Robust.Shared.Maths
/// </summary>
/// <param name="obj">Other object to check.</param>
/// <returns>True if Object and vector are equal.</returns>
public override readonly bool Equals(object? obj)
public readonly override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is Vector2i vector && Equals(vector);
@@ -74,7 +93,7 @@ namespace Robust.Shared.Maths
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A unique hash code for this instance.</returns>
public override readonly int GetHashCode()
public readonly override int GetHashCode()
{
unchecked
{