From 799f838f136e3322818364b9b8ca0994a6eb4fac Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 8 Sep 2024 19:30:29 +1000 Subject: [PATCH] Manually implement equality on `AxisSpec` fixes 76a30e5d7 --- .../Base Implementations/Axes/AxisSpec.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs b/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs index e8565426b0..24664ccba0 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisSpec.cs @@ -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 { + [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); + /// /// 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); } }