Skip to content

Commit

Permalink
avoid boxing in RGB Equals
Browse files Browse the repository at this point in the history
  • Loading branch information
adamabdelhamed committed Dec 31, 2024
1 parent 59c0b03 commit 1b51b2b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions PowerArgs/HelperTypesPublic/RGB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PowerArgs;
[ArgReviverType]
public readonly struct RGB
public readonly struct RGB : IEquatable<RGB>
{
public static readonly float MaxDistance = (float)Math.Sqrt((255 * 255) + (255 * 255) + (255 * 255));

Expand Down Expand Up @@ -98,12 +98,11 @@ public RGB(byte r, byte g, byte b)
this.B = b;
}

public bool Equals(RGB other) => this.R == other.R && this.G == other.G && this.B == other.B;

public override bool Equals(object obj)
{
if (obj is RGB == false) return false;
var other = (RGB)obj;
if (other == null) return false;
return this.R == other.R && this.G == other.G && this.B == other.B;
return obj is RGB rgb && Equals(rgb);
}

public bool EqualsIn(in RGB obj)
Expand Down

0 comments on commit 1b51b2b

Please sign in to comment.