From 6d995fe7378083ecb111c34552121f9d10d80812 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 30 Apr 2024 13:38:32 -0500 Subject: [PATCH] color: change eql to switch statement --- src/Cell.zig | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Cell.zig b/src/Cell.zig index 75cc03e..e9d5fc4 100644 --- a/src/Cell.zig +++ b/src/Cell.zig @@ -106,16 +106,23 @@ pub const Color = union(enum) { rgb: [3]u8, pub fn eql(a: Color, b: Color) bool { - if (a == .default and b == .default) - return true - else if (a == .index and b == .index) - return a.index == b.index - else if (a == .rgb and b == .rgb) - return a.rgb[0] == b.rgb[0] and - a.rgb[1] == b.rgb[1] and - a.rgb[2] == b.rgb[2] - else - return false; + switch (a) { + .default => return b == .default, + .index => |a_idx| { + switch (b) { + .index => |b_idx| return a_idx == b_idx, + else => return false, + } + }, + .rgb => |a_rgb| { + switch (b) { + .rgb => |b_rgb| return a_rgb[0] == b_rgb[0] and + a_rgb[1] == b_rgb[1] and + a_rgb[2] == b_rgb[2], + else => return false, + } + }, + } } pub fn rgbFromUint(val: u24) Color {