Skip to content

Commit 4b7b844

Browse files
committed
Use MTP, fix maths tests
1 parent 704aae2 commit 4b7b844

File tree

15 files changed

+1380
-1111
lines changed

15 files changed

+1380
-1111
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageVersion Include="NUnit.Analyzers" Version="4.11.2" />
1111
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
1212
<PackageVersion Include="NUnit" Version="4.4.0" />
13-
<PackageVersion Include="xunit" Version="2.9.3" />
13+
<PackageVersion Include="xunit.v3" Version="3.2.1" />
1414
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
1515
<!-- eng/benchmarks -->
1616
<PackageVersion Include="BenchmarkDotNet" Version="0.15.6" />
@@ -44,4 +44,4 @@
4444
<PackageVersion Include="Verify.DiffPlex" Version="3.1.2" />
4545
<PackageVersion Include="Verify.NUnit" Version="31.6.0" />
4646
</ItemGroup>
47-
</Project>
47+
</Project>

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"sdk": {
33
"version": "10.0.100",
44
"rollForward": "major"
5+
},
6+
"test": {
7+
"runner": "Microsoft.Testing.Platform"
58
}
69
}

sources/Maths/Maths/Plane.cs

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Silk.NET.Maths
1414
/// <typeparam name="T">The type used to store values.</typeparam>
1515
[Serializable]
1616
[DataContract]
17-
public struct Plane<T>
18-
: IEquatable<Plane<T>> where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
17+
public struct Plane<T> : IEquatable<Plane<T>>
18+
where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
1919
{
2020
/// <summary>The normal vector of the Plane.</summary>
2121
[DataMember]
@@ -58,22 +58,21 @@ public Plane(Vector4D<T> value)
5858
/// <param name="value1">The first Plane to compare.</param>
5959
/// <param name="value2">The second Plane to compare.</param>
6060
/// <returns>True if the Planes are equal; False otherwise.</returns>
61-
[MethodImpl((MethodImplOptions) 768)]
62-
public static bool operator ==(Plane<T> value1, Plane<T> value2)
63-
=> value1.Normal == value2.Normal && Scalar.Equal(value1.Distance, value2.Distance);
61+
[MethodImpl((MethodImplOptions)768)]
62+
public static bool operator ==(Plane<T> value1, Plane<T> value2) =>
63+
value1.Normal == value2.Normal && Scalar.Equal(value1.Distance, value2.Distance);
6464

6565
/// <summary>Returns a boolean indicating whether the two given Planes are not equal.</summary>
6666
/// <param name="value1">The first Plane to compare.</param>
6767
/// <param name="value2">The second Plane to compare.</param>
6868
/// <returns>True if the Planes are not equal; False if they are equal.</returns>
69-
[MethodImpl((MethodImplOptions) 768)]
70-
public static bool operator !=(Plane<T> value1, Plane<T> value2)
71-
=> !(value1 == value2);
69+
[MethodImpl((MethodImplOptions)768)]
70+
public static bool operator !=(Plane<T> value1, Plane<T> value2) => !(value1 == value2);
7271

7372
/// <summary>Returns a boolean indicating whether the given Object is equal to this Plane instance.</summary>
7473
/// <param name="obj">The Object to compare against.</param>
7574
/// <returns>True if the Object is equal to this Plane; False otherwise.</returns>
76-
[MethodImpl((MethodImplOptions) 768)]
75+
[MethodImpl((MethodImplOptions)768)]
7776
public override readonly bool Equals(object? obj)
7877
{
7978
return (obj is Plane<T> other) && Equals(other);
@@ -82,7 +81,7 @@ public override readonly bool Equals(object? obj)
8281
/// <summary>Returns a boolean indicating whether the given Plane is equal to this Plane instance.</summary>
8382
/// <param name="other">The Plane to compare this instance to.</param>
8483
/// <returns>True if the other Plane is equal to this instance; False otherwise.</returns>
85-
[MethodImpl((MethodImplOptions) 768)]
84+
[MethodImpl((MethodImplOptions)768)]
8685
public readonly bool Equals(Plane<T> other)
8786
{
8887
return Normal.Equals(other.Normal) && Scalar.Equal(Distance, other.Distance);
@@ -92,129 +91,135 @@ public readonly bool Equals(Plane<T> other)
9291
/// <returns>The hash code.</returns>
9392
public override readonly int GetHashCode()
9493
{
95-
return Normal.GetHashCode() + Distance.GetHashCode();
94+
return HashCode.Combine(Normal.GetHashCode(), Distance.GetHashCode());
9695
}
9796

9897
/// <summary>Returns a String representing this Plane instance.</summary>
9998
/// <returns>The string representation.</returns>
10099
public override readonly string ToString()
101100
{
102101
CultureInfo ci = CultureInfo.CurrentCulture;
103-
return string.Format(ci, "{{Normal:{0} D:{1}}}", Normal.ToString(), Distance.ToString("G", ci));
102+
return string.Format(
103+
ci,
104+
"{{Normal:{0} D:{1}}}",
105+
Normal.ToString(),
106+
Distance.ToString("G", ci)
107+
);
104108
}
105109

106110
/// <summary>
107111
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="Half"/>
108112
/// </summary>
109113
/// <param name="from">The source matrix</param>
110114
/// <returns>The <see cref="Half"/> matrix</returns>
111-
public static explicit operator Plane<Half>(Plane<T> from)
112-
=> new((Vector3D<Half>) from.Normal, Scalar.As<T, Half>(from.Distance));
115+
public static explicit operator Plane<Half>(Plane<T> from) =>
116+
new((Vector3D<Half>)from.Normal, Scalar.As<T, Half>(from.Distance));
113117

114118
/// <summary>
115119
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="float"/>
116120
/// </summary>
117121
/// <param name="from">The source matrix</param>
118122
/// <returns>The <see cref="float"/> matrix</returns>
119-
public static explicit operator Plane<float>(Plane<T> from)
120-
=> new((Vector3D<float>) from.Normal, Scalar.As<T, float>(from.Distance));
123+
public static explicit operator Plane<float>(Plane<T> from) =>
124+
new((Vector3D<float>)from.Normal, Scalar.As<T, float>(from.Distance));
121125

122126
/// <summary>
123127
/// Converts a <see cref="Plane{T}"/> into <see cref="System.Numerics.Plane"/>
124128
/// </summary>
125129
/// <param name="from">The source matrix</param>
126130
/// <returns>The <see cref="System.Numerics"/> matrix</returns>
127-
public static explicit operator System.Numerics.Plane(Plane<T> from)
128-
=> new((System.Numerics.Vector3) from.Normal, Scalar.As<T, float>(from.Distance));
129-
131+
public static explicit operator System.Numerics.Plane(Plane<T> from) =>
132+
new((System.Numerics.Vector3)from.Normal, Scalar.As<T, float>(from.Distance));
133+
130134
/// <summary>
131135
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="double"/>
132136
/// </summary>
133137
/// <param name="from">The source matrix</param>
134138
/// <returns>The <see cref="double"/> matrix</returns>
135-
public static explicit operator Plane<double>(Plane<T> from)
136-
=> new((Vector3D<double>) from.Normal, Scalar.As<T, double>(from.Distance));
139+
public static explicit operator Plane<double>(Plane<T> from) =>
140+
new((Vector3D<double>)from.Normal, Scalar.As<T, double>(from.Distance));
137141

138142
/// <summary>
139143
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="decimal"/>
140144
/// </summary>
141145
/// <param name="from">The source matrix</param>
142146
/// <returns>The <see cref="decimal"/> matrix</returns>
143-
public static explicit operator Plane<decimal>(Plane<T> from)
144-
=> new((Vector3D<decimal>) from.Normal, Scalar.As<T, decimal>(from.Distance));
147+
public static explicit operator Plane<decimal>(Plane<T> from) =>
148+
new((Vector3D<decimal>)from.Normal, Scalar.As<T, decimal>(from.Distance));
145149

146150
/// <summary>
147151
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="sbyte"/>
148152
/// </summary>
149153
/// <param name="from">The source matrix</param>
150154
/// <returns>The <see cref="sbyte"/> matrix</returns>
151-
public static explicit operator Plane<sbyte>(Plane<T> from)
152-
=> new((Vector3D<sbyte>) from.Normal, Scalar.As<T, sbyte>(from.Distance));
155+
public static explicit operator Plane<sbyte>(Plane<T> from) =>
156+
new((Vector3D<sbyte>)from.Normal, Scalar.As<T, sbyte>(from.Distance));
153157

154158
/// <summary>
155159
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="byte"/>
156160
/// </summary>
157161
/// <param name="from">The source matrix</param>
158162
/// <returns>The <see cref="byte"/> matrix</returns>
159-
public static explicit operator Plane<byte>(Plane<T> from)
160-
=> new((Vector3D<byte>) from.Normal, Scalar.As<T, byte>(from.Distance));
163+
public static explicit operator Plane<byte>(Plane<T> from) =>
164+
new((Vector3D<byte>)from.Normal, Scalar.As<T, byte>(from.Distance));
161165

162166
/// <summary>
163167
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="ushort"/>
164168
/// </summary>
165169
/// <param name="from">The source matrix</param>
166170
/// <returns>The <see cref="ushort"/> matrix</returns>
167-
public static explicit operator Plane<ushort>(Plane<T> from)
168-
=> new((Vector3D<ushort>) from.Normal, Scalar.As<T, ushort>(from.Distance));
171+
public static explicit operator Plane<ushort>(Plane<T> from) =>
172+
new((Vector3D<ushort>)from.Normal, Scalar.As<T, ushort>(from.Distance));
169173

170174
/// <summary>
171175
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="short"/>
172176
/// </summary>
173177
/// <param name="from">The source matrix</param>
174178
/// <returns>The <see cref="short"/> matrix</returns>
175-
public static explicit operator Plane<short>(Plane<T> from)
176-
=> new((Vector3D<short>) from.Normal, Scalar.As<T, short>(from.Distance));
179+
public static explicit operator Plane<short>(Plane<T> from) =>
180+
new((Vector3D<short>)from.Normal, Scalar.As<T, short>(from.Distance));
177181

178182
/// <summary>
179183
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="uint"/>
180184
/// </summary>
181185
/// <param name="from">The source matrix</param>
182186
/// <returns>The <see cref="uint"/> matrix</returns>
183-
public static explicit operator Plane<uint>(Plane<T> from)
184-
=> new((Vector3D<uint>) from.Normal, Scalar.As<T, uint>(from.Distance));
187+
public static explicit operator Plane<uint>(Plane<T> from) =>
188+
new((Vector3D<uint>)from.Normal, Scalar.As<T, uint>(from.Distance));
185189

186190
/// <summary>
187191
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="int"/>
188192
/// </summary>
189193
/// <param name="from">The source matrix</param>
190194
/// <returns>The <see cref="int"/> matrix</returns>
191-
public static explicit operator Plane<int>(Plane<T> from)
192-
=> new((Vector3D<int>) from.Normal, Scalar.As<T, int>(from.Distance));
195+
public static explicit operator Plane<int>(Plane<T> from) =>
196+
new((Vector3D<int>)from.Normal, Scalar.As<T, int>(from.Distance));
193197

194198
/// <summary>
195199
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="ulong"/>
196200
/// </summary>
197201
/// <param name="from">The source matrix</param>
198202
/// <returns>The <see cref="ulong"/> matrix</returns>
199-
public static explicit operator Plane<ulong>(Plane<T> from)
200-
=> new((Vector3D<ulong>) from.Normal, Scalar.As<T, ulong>(from.Distance));
203+
public static explicit operator Plane<ulong>(Plane<T> from) =>
204+
new((Vector3D<ulong>)from.Normal, Scalar.As<T, ulong>(from.Distance));
201205

202206
/// <summary>
203207
/// Converts a <see cref="Plane{T}"/> into one with a <typeparamref name="T"/> of <see cref="long"/>
204208
/// </summary>
205209
/// <param name="from">The source matrix</param>
206210
/// <returns>The <see cref="long"/> matrix</returns>
207-
public static explicit operator Plane<long>(Plane<T> from)
208-
=> new((Vector3D<long>) from.Normal, Scalar.As<T, long>(from.Distance));
209-
211+
public static explicit operator Plane<long>(Plane<T> from) =>
212+
new((Vector3D<long>)from.Normal, Scalar.As<T, long>(from.Distance));
213+
210214
/// <summary>
211215
/// Returns this plane casted to <typeparamref name="TOther"></typeparamref>
212216
/// </summary>
213217
/// <typeparam name="TOther">The type to cast to</typeparam>
214218
/// <returns>The casted plane</returns>
215-
public Plane<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
219+
public Plane<TOther> As<TOther>()
220+
where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
216221
{
217222
return new(Normal.As<TOther>(), Scalar.As<T, TOther>(Distance));
218223
}
219224
}
220-
}
225+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable

sources/Maths/Maths/Scalar.Bitwise/Scalar.Not.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ static partial class Scalar
1010
/// <summary>
1111
/// Performs Not on supported types
1212
/// </summary>
13-
public static T Not<T>(T value) where T : unmanaged
13+
public static T Not<T>(T value)
14+
where T : unmanaged
1415
{
1516
return Byte(value);
1617

@@ -19,113 +20,113 @@ static T Byte(T value)
1920
{
2021
if (typeof(T) == typeof(byte))
2122
{
22-
return (T) (object) (byte) (~ (byte) (object) value);
23+
return (T)(object)(byte)(~((byte)(object)value) & byte.MaxValue);
2324
}
2425

2526
return SByte(value);
2627
}
27-
28+
2829
[MethodImpl(MaxOpt)]
2930
static T SByte(T value)
3031
{
3132
if (typeof(T) == typeof(sbyte))
3233
{
33-
return (T) (object) (sbyte) (~ (sbyte) (object) value);
34+
return (T)(object)(sbyte)(~(sbyte)(object)value);
3435
}
3536

3637
return UInt16(value);
3738
}
38-
39+
3940
[MethodImpl(MaxOpt)]
4041
static T UInt16(T value)
4142
{
4243
if (typeof(T) == typeof(ushort))
4344
{
44-
return (T) (object) (ushort) (~ (ushort) (object) value);
45+
return (T)(object)(ushort)(~(ushort)(object)value);
4546
}
4647

4748
return Int16(value);
4849
}
49-
50+
5051
[MethodImpl(MaxOpt)]
5152
static T Int16(T value)
5253
{
5354
if (typeof(T) == typeof(short))
5455
{
55-
return (T) (object) (short) (~ (short) (object) value);
56+
return (T)(object)(short)(~(short)(object)value);
5657
}
5758

5859
return UInt32(value);
5960
}
60-
61+
6162
[MethodImpl(MaxOpt)]
6263
static T UInt32(T value)
6364
{
6465
if (typeof(T) == typeof(uint))
6566
{
66-
return (T) (object) (uint) (~ (uint) (object) value);
67+
return (T)(object)(uint)(~(uint)(object)value);
6768
}
6869

6970
return Int32(value);
7071
}
71-
72+
7273
[MethodImpl(MaxOpt)]
7374
static T Int32(T value)
7475
{
7576
if (typeof(T) == typeof(int))
7677
{
77-
return (T) (object) (int) (~ (int) (object) value);
78+
return (T)(object)(int)(~(int)(object)value);
7879
}
7980

8081
return UInt64(value);
8182
}
82-
83+
8384
[MethodImpl(MaxOpt)]
8485
static T UInt64(T value)
8586
{
8687
if (typeof(T) == typeof(ulong))
8788
{
88-
return (T) (object) (ulong) (~ (ulong) (object) value);
89+
return (T)(object)(ulong)(~(ulong)(object)value);
8990
}
9091

9192
return Int64(value);
9293
}
93-
94+
9495
[MethodImpl(MaxOpt)]
9596
static T Int64(T value)
9697
{
9798
if (typeof(T) == typeof(long))
9899
{
99-
return (T) (object) (long) (~ (long) (object) value);
100+
return (T)(object)(long)(~(long)(object)value);
100101
}
101102

102103
return Single(value);
103104
}
104-
105+
105106
[MethodImpl(MaxOpt)]
106107
static T Single(T value)
107108
{
108109
if (typeof(T) == typeof(float))
109110
{
110-
var res = ~ Unsafe.As<T, uint>(ref value);
111+
var res = ~Unsafe.As<T, uint>(ref value);
111112
return Unsafe.As<uint, T>(ref res);
112113
}
113114

114115
return Double(value);
115116
}
116-
117+
117118
[MethodImpl(MaxOpt)]
118119
static T Double(T value)
119120
{
120121
if (typeof(T) == typeof(double))
121122
{
122-
var res = ~ Unsafe.As<T, ulong>(ref value);
123+
var res = ~Unsafe.As<T, ulong>(ref value);
123124
return Unsafe.As<ulong, T>(ref res);
124125
}
125126

126127
return Other(value);
127128
}
128-
129+
129130
[MethodImpl(MaxOpt)]
130131
static T Other(T value)
131132
{
@@ -134,4 +135,4 @@ static T Other(T value)
134135
}
135136
}
136137
}
137-
}
138+
}

0 commit comments

Comments
 (0)