Skip to content

Commit ab2e6a1

Browse files
authored
Change Color, QAngle to record struct
1 parent 1abbc8f commit ab2e6a1

2 files changed

Lines changed: 6 additions & 63 deletions

File tree

Types/Color.cs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,16 @@
22

33
namespace Datamodel;
44

5-
public struct Color : IEquatable<Color>
5+
public record struct Color(byte R, byte G, byte B, byte A)
66
{
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]);
119

12-
public Color(byte r, byte g, byte b, byte a)
10+
public void ToBytes(Span<byte> bytes)
1311
{
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;
1813
}
1914

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-
2915
public byte[] ToBytes()
3016
=> 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-
}
4417
}

Types/QAngle.cs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,8 @@
33

44
namespace Datamodel;
55

6-
public struct QAngle : IEquatable<QAngle>
6+
public record struct QAngle(float Pitch, float Yaw, float Roll)
77
{
8-
public float Pitch;
9-
public float Yaw;
10-
public float Roll;
11-
12-
public QAngle(float pitch, float yaw, float roll)
13-
{
14-
Pitch = pitch;
15-
Yaw = yaw;
16-
Roll = roll;
17-
}
18-
198
public static implicit operator Vector3(QAngle q) => new(q.Pitch, q.Yaw, q.Roll);
209
public static implicit operator QAngle(Vector3 v) => new(v.X, v.Y, v.Z);
21-
22-
public static bool operator ==(QAngle first, QAngle second)
23-
=> first.Pitch == second.Pitch && first.Yaw == second.Yaw && first.Roll == second.Roll;
24-
25-
public static bool operator !=(QAngle a, QAngle b)
26-
=> !(a == b);
27-
28-
public readonly override int GetHashCode()
29-
=> HashCode.Combine(Pitch, Yaw, Roll);
30-
31-
public readonly bool Equals(QAngle other)
32-
=> this == other;
33-
34-
public readonly override bool Equals(object obj)
35-
{
36-
if (obj is QAngle q)
37-
return this == q;
38-
return false;
39-
}
4010
}

0 commit comments

Comments
 (0)