22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System ;
5+ using System . Numerics ;
56using System . Runtime . CompilerServices ;
67using System . Runtime . Serialization ;
78
@@ -14,7 +15,7 @@ namespace Silk.NET.Maths
1415 [ DataContract ]
1516 public struct Box2D < T >
1617 : IEquatable < Box2D < T > >
17- where T : unmanaged , IFormattable , IEquatable < T > , IComparable < T >
18+ where T : INumber < T >
1819 {
1920 /// <summary>
2021 /// The min.
@@ -148,9 +149,9 @@ public Box2D<T> GetScaled(Vector2D<T> scale, Vector2D<T> anchor)
148149 /// <typeparam name="TScale">The type of the scale.</typeparam>
149150 /// <returns>The calculated box.</returns>
150151 public Box2D < T > GetScaled < TScale > ( Vector2D < TScale > scale , Vector2D < T > anchor )
151- where TScale : unmanaged , IFormattable , IEquatable < TScale > , IComparable < TScale >
152+ where TScale : INumber < TScale >
152153 {
153- return this . As < TScale > ( ) . GetScaled ( scale , anchor . As < TScale > ( ) ) . As < T > ( ) ;
154+ return this . AsTruncating < TScale > ( ) . GetScaled ( scale , anchor . AsTruncating < TScale > ( ) ) . AsTruncating < T > ( ) ;
154155 }
155156
156157 /// <summary>
@@ -209,9 +210,44 @@ public override int GetHashCode()
209210 /// </summary>
210211 /// <typeparam name="TOther">The type to cast to</typeparam>
211212 /// <returns>The casted box</returns>
212- public Box2D < TOther > As < TOther > ( ) where TOther : unmanaged, IFormattable , IEquatable < TOther > , IComparable < TOther >
213+ [ Obsolete ( "Use AsChecked, AsSaturating, or AsTruncating instead." , error : false ) ]
214+ public Box2D < TOther > As < TOther > ( )
215+ where TOther : INumber < TOther >
213216 {
214217 return new ( Min . As < TOther > ( ) , Max . As < TOther > ( ) ) ;
215218 }
219+
220+ /// <summary>
221+ /// Returns this box casted to <typeparamref name="TOther"></typeparamref>
222+ /// </summary>
223+ /// <typeparam name="TOther">The type to cast to</typeparam>
224+ /// <returns>The casted box</returns>
225+ public Box2D < TOther > AsChecked < TOther > ( )
226+ where TOther : INumber < TOther >
227+ {
228+ return new ( Min . AsChecked < TOther > ( ) , Max . AsChecked < TOther > ( ) ) ;
229+ }
230+
231+ /// <summary>
232+ /// Returns this box casted to <typeparamref name="TOther"></typeparamref>
233+ /// </summary>
234+ /// <typeparam name="TOther">The type to cast to</typeparam>
235+ /// <returns>The casted box</returns>
236+ public Box2D < TOther > AsSaturating < TOther > ( )
237+ where TOther : INumber < TOther >
238+ {
239+ return new ( Min . AsSaturating < TOther > ( ) , Max . AsSaturating < TOther > ( ) ) ;
240+ }
241+
242+ /// <summary>
243+ /// Returns this box casted to <typeparamref name="TOther"></typeparamref>
244+ /// </summary>
245+ /// <typeparam name="TOther">The type to cast to</typeparam>
246+ /// <returns>The casted box</returns>
247+ public Box2D < TOther > AsTruncating < TOther > ( )
248+ where TOther : INumber < TOther >
249+ {
250+ return new ( Min . AsTruncating < TOther > ( ) , Max . AsTruncating < TOther > ( ) ) ;
251+ }
216252 }
217- }
253+ }
0 commit comments