Skip to content

Commit a113834

Browse files
authored
Merge pull request #91 from neogeek/hotfix/added-struct-equality
[hotfix] Added struct equality.
2 parents bd9400e + 096b6a8 commit a113834

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
using System;
12
using System.Runtime.InteropServices;
23

34
namespace RhythmGameUtilities
45
{
56

67
[StructLayout(LayoutKind.Sequential)]
7-
public struct Note
8+
public struct Note : IEquatable<Note>
89
{
910

1011
public int Position;
@@ -13,6 +14,28 @@ public struct Note
1314

1415
public int Length;
1516

17+
public override int GetHashCode() => (Position, HandPosition, Length).GetHashCode();
18+
19+
public bool Equals(Note other)
20+
{
21+
return Position == other.Position && HandPosition == other.HandPosition && Length == other.Length;
22+
}
23+
24+
public override bool Equals(object obj)
25+
{
26+
return obj is Note other && Equals(other);
27+
}
28+
29+
public static bool operator ==(Note left, Note right)
30+
{
31+
return left.Equals(right);
32+
}
33+
34+
public static bool operator !=(Note left, Note right)
35+
{
36+
return !(left == right);
37+
}
38+
1639
}
1740

1841
}

UnityPackage/Structs/Note.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
using System;
12
using System.Runtime.InteropServices;
23

34
namespace RhythmGameUtilities
45
{
56

67
[StructLayout(LayoutKind.Sequential)]
7-
public struct Note
8+
public struct Note : IEquatable<Note>
89
{
910

1011
public int Position;
@@ -13,6 +14,28 @@ public struct Note
1314

1415
public int Length;
1516

17+
public override int GetHashCode() => (Position, HandPosition, Length).GetHashCode();
18+
19+
public bool Equals(Note other)
20+
{
21+
return Position == other.Position && HandPosition == other.HandPosition && Length == other.Length;
22+
}
23+
24+
public override bool Equals(object obj)
25+
{
26+
return obj is Note other && Equals(other);
27+
}
28+
29+
public static bool operator ==(Note left, Note right)
30+
{
31+
return left.Equals(right);
32+
}
33+
34+
public static bool operator !=(Note left, Note right)
35+
{
36+
return !(left == right);
37+
}
38+
1639
}
1740

1841
}

0 commit comments

Comments
 (0)