|
2 | 2 |
|
3 | 3 | namespace Datamodel; |
4 | 4 |
|
5 | | -public struct Color : IEquatable<Color> |
| 5 | +public record struct Color(byte R, byte G, byte B, byte A) |
6 | 6 | { |
7 | | - public byte R; |
8 | | - public byte G; |
9 | | - public byte B; |
10 | | - public byte A; |
| 7 | + public static Color FromBytes(ReadOnlySpan<byte> bytes) |
| 8 | + => new(bytes[0], bytes[1], bytes[2], bytes[3]); |
11 | 9 |
|
12 | | - public Color(byte r, byte g, byte b, byte a) |
| 10 | + public void ToBytes(Span<byte> bytes) |
13 | 11 | { |
14 | | - R = r; |
15 | | - G = g; |
16 | | - B = b; |
17 | | - A = a; |
| 12 | + bytes[0] = R; bytes[1] = G; bytes[2] = B; bytes[3] = A; |
18 | 13 | } |
19 | 14 |
|
20 | | - public static bool operator ==(Color first, Color second) |
21 | | - => first.R == second.R && first.G == second.G && first.B == second.B && first.A == second.A; |
22 | | - |
23 | | - public static bool operator !=(Color a, Color b) |
24 | | - => !(a == b); |
25 | | - |
26 | | - public static Color FromBytes(ReadOnlySpan<byte> bytes) |
27 | | - => new(bytes[0], bytes[1], bytes[2], bytes[3]); |
28 | | - |
29 | 15 | public byte[] ToBytes() |
30 | 16 | => new byte[] { R, G, B, A }; |
31 | | - |
32 | | - public override int GetHashCode() |
33 | | - => HashCode.Combine(R, G, B, A); |
34 | | - |
35 | | - public bool Equals(Color other) |
36 | | - => this == other; |
37 | | - |
38 | | - public override bool Equals(object obj) |
39 | | - { |
40 | | - if (obj is Color color) |
41 | | - return this == color; |
42 | | - return false; |
43 | | - } |
44 | 17 | } |
0 commit comments