-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.cs
More file actions
161 lines (134 loc) · 4.69 KB
/
Math.cs
File metadata and controls
161 lines (134 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
namespace TerminalEngine
{
#pragma warning disable IDE1006 // Naming Styles
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
#pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
public struct float2(float? a, float? b) :
#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
IEquatable<float>,
IEquatable<float2>,
IComparer<float2>,
IIncrementOperators<float2>,
IDecrementOperators<float2>,
IComparable<float2>,
IMinMaxValue<float2>
{
public static float2 DefaultValue => new(0, 0);
public static float2 MaxValue => new(float.MinValue, float.MaxValue);
public static float2 MinValue => new(float.MinValue, float.MaxValue);
public float a { get; set; } = a ?? 0f;
public float b { get; set; } = b ?? 0f;
public readonly int Compare(float2 x, float2 y)
{
return x < y ? -1 : x > y ? 1 : 0;
}
public readonly int CompareTo(float2 other)
{
return Compare(this, other);
}
public readonly bool Equals(float2 other)
{
return other.a == a && other.b == b;
}
public readonly override string ToString()
{
return string.Format("{0},{1}", a, b);
}
public readonly string ToString(string format = "{0},{1}")
{
return string.Format(format, a, b);
}
public readonly override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is float2 f2 && Equals(f2);
}
public readonly bool Equals(float other)
{
return a == other && b == other;
}
public static bool operator ==(float2 left, float2 right)
{
return left.Equals(right);
}
public static bool operator !=(float2 left, float2 right)
{
return !(left == right);
}
public static bool operator <(float2 left, float2 right)
{
return left.CompareTo(right) < 0;
}
public static bool operator <=(float2 left, float2 right)
{
return left.CompareTo(right) <= 0;
}
public static bool operator >(float2 left, float2 right)
{
return left.CompareTo(right) > 0;
}
public static bool operator >=(float2 left, float2 right)
{
return left.CompareTo(right) >= 0;
}
public static float2 operator ++(float2 value)
{
return new(value.a++, value.b++);
}
public static float2 operator --(float2 value)
{
return new(value.a--, value.b--);
}
public static float2 operator *(float2 left, float2 right)
{
return new(left.a * right.a, left.b * right.b);
}
public static float2 operator *(float2 left, float right)
{
return new(left.a * right, left.b * right);
}
public static float2 operator /(float2 left, float2 right)
{
return new(left.a / right.a, left.b / right.b);
}
public static float2 operator /(float2 left, float right)
{
return new(left.a * right, left.b * right);
}
public static float2 operator +(float2 left, float2 right)
{
return new(left.a + right.a, left.b + right.b);
}
public static float2 operator +(float2 left, float right)
{
return new(left.a + right, left.b + right);
}
public static float2 operator -(float2 left, float2 right)
{
return new(left.a - right.a, left.b - right.b);
}
public static float2 operator -(float2 left, float right)
{
return new(left.a - right, left.b - right);
}
public static float2 operator +(float2 value)
{
return new(+value.a, +value.b);
}
public static float2 operator -(float2 value)
{
return new(-value.a, -value.b);
}
public static implicit operator Position(float2 val)
{
return new((int)val.a, (int)val.b);
}
public static implicit operator float2(Position val)
{
return new(val.x, val.y);
}
}
#pragma warning restore IDE1006 // Naming Styles
}