Manually implement equality on `AxisSpec`

fixes 76a30e5d7
This commit is contained in:
YoshiRulz 2024-09-08 19:30:29 +10:00
parent 0f74595cdb
commit 799f838f13
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 23 additions and 1 deletions

View File

@ -1,9 +1,19 @@
using System.Runtime.CompilerServices;
using BizHawk.Common;
namespace BizHawk.Emulation.Common
{
public readonly record struct AxisSpec
public readonly struct AxisSpec : IEquatable<AxisSpec>
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(AxisSpec a, AxisSpec b)
=> a.Equals(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(AxisSpec a, AxisSpec b)
=> !a.Equals(b);
/// <summary>
/// Gets the axis constraints that apply artificial constraints to float values
/// For instance, a N64 controller's analog range is actually larger than the amount allowed by the plastic that artificially constrains it to lower values
@ -34,5 +44,17 @@ namespace BizHawk.Emulation.Common
Neutral = neutral;
Range = range;
}
public bool Equals(AxisSpec other)
=> Range == other.Range
&& Neutral == other.Neutral
&& IsReversed == other.IsReversed
&& Constraint == other.Constraint;
public override bool Equals(object? obj)
=> obj is AxisSpec other && Equals(other);
public override int GetHashCode()
=> HashCode.Combine(Range.Start, Range.EndInclusive, Neutral, IsReversed, Constraint);
}
}