color: change eql to switch statement

This commit is contained in:
Tim Culverhouse 2024-04-30 13:38:32 -05:00
parent 2d48093d3a
commit 6d995fe737

View file

@ -106,16 +106,23 @@ pub const Color = union(enum) {
rgb: [3]u8, rgb: [3]u8,
pub fn eql(a: Color, b: Color) bool { pub fn eql(a: Color, b: Color) bool {
if (a == .default and b == .default) switch (a) {
return true .default => return b == .default,
else if (a == .index and b == .index) .index => |a_idx| {
return a.index == b.index switch (b) {
else if (a == .rgb and b == .rgb) .index => |b_idx| return a_idx == b_idx,
return a.rgb[0] == b.rgb[0] and else => return false,
a.rgb[1] == b.rgb[1] and }
a.rgb[2] == b.rgb[2] },
else .rgb => |a_rgb| {
return false; 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 { pub fn rgbFromUint(val: u24) Color {