From 1b51b2b9ccc07fa9959db8df57ea39f9b2f90b78 Mon Sep 17 00:00:00 2001 From: Adam Abdelhamed Date: Tue, 31 Dec 2024 13:34:30 -0500 Subject: [PATCH] avoid boxing in RGB Equals --- PowerArgs/HelperTypesPublic/RGB.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/PowerArgs/HelperTypesPublic/RGB.cs b/PowerArgs/HelperTypesPublic/RGB.cs index 1f7c942..b912b25 100644 --- a/PowerArgs/HelperTypesPublic/RGB.cs +++ b/PowerArgs/HelperTypesPublic/RGB.cs @@ -4,7 +4,7 @@ namespace PowerArgs; [ArgReviverType] -public readonly struct RGB +public readonly struct RGB : IEquatable { public static readonly float MaxDistance = (float)Math.Sqrt((255 * 255) + (255 * 255) + (255 * 255)); @@ -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)