Skip to content

Commit 61e3769

Browse files
authored
Add As methods to all Maths types (#480)
1 parent e1fdce1 commit 61e3769

23 files changed

+243
-1
lines changed

src/Maths/Silk.NET.Maths/Box2D.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,15 @@ public override int GetHashCode()
153153
{
154154
return !value1.Equals(value2);
155155
}
156+
157+
/// <summary>
158+
/// Returns this box casted to <typeparamref name="TOther"></typeparamref>
159+
/// </summary>
160+
/// <typeparam name="TOther">The type to cast to</typeparam>
161+
/// <returns>The casted box</returns>
162+
public Box2D<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
163+
{
164+
return new(Min.As<TOther>(), Max.As<TOther>());
165+
}
156166
}
157167
}

src/Maths/Silk.NET.Maths/Box3D.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,15 @@ public override int GetHashCode()
158158
{
159159
return !value1.Equals(value2);
160160
}
161+
162+
/// <summary>
163+
/// Returns this box casted to <typeparamref name="TOther"></typeparamref>
164+
/// </summary>
165+
/// <typeparam name="TOther">The type to cast to</typeparam>
166+
/// <returns>The casted box</returns>
167+
public Box3D<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
168+
{
169+
return new(Min.As<TOther>(), Max.As<TOther>());
170+
}
161171
}
162172
}

src/Maths/Silk.NET.Maths/Circle.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,15 @@ public override int GetHashCode()
152152
{
153153
return !value1.Equals(value2);
154154
}
155+
156+
/// <summary>
157+
/// Returns this circle casted to <typeparamref name="TOther"></typeparamref>
158+
/// </summary>
159+
/// <typeparam name="TOther">The type to cast to</typeparam>
160+
/// <returns>The casted circle</returns>
161+
public Circle<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
162+
{
163+
return new(Center.As<TOther>(), Scalar.As<T, TOther>(Radius));
164+
}
155165
}
156166
}

src/Maths/Silk.NET.Maths/Cube.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,15 @@ public override int GetHashCode()
173173
{
174174
return !value1.Equals(value2);
175175
}
176+
177+
/// <summary>
178+
/// Returns this circle casted to <typeparamref name="TOther"></typeparamref>
179+
/// </summary>
180+
/// <typeparam name="TOther">The type to cast to</typeparam>
181+
/// <returns>The casted cube</returns>
182+
public Cube<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
183+
{
184+
return new(Origin.As<TOther>(), Max.As<TOther>());
185+
}
176186
}
177187
}

src/Maths/Silk.NET.Maths/Matrix2X2.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,5 +405,15 @@ public static explicit operator Matrix2X2<ulong>(Matrix2X2<T> from)
405405
public static explicit operator Matrix2X2<long>(Matrix2X2<T> from)
406406
=> new(Scalar.As<T, long>(from.M11), Scalar.As<T, long>(from.M12), Scalar.As<T, long>(from.M21),
407407
Scalar.As<T, long>(from.M22));
408+
409+
/// <summary>
410+
/// Returns this matrix casted to <typeparamref name="TOther"></typeparamref>
411+
/// </summary>
412+
/// <typeparam name="TOther">The type to cast to</typeparam>
413+
/// <returns>The casted matrix</returns>
414+
public Matrix2X2<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
415+
{
416+
return new(Row1.As<TOther>(), Row2.As<TOther>());
417+
}
408418
}
409419
}

src/Maths/Silk.NET.Maths/Matrix2X3.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,5 +445,15 @@ public static explicit operator Matrix2X3<ulong>(Matrix2X3<T> from)
445445
public static explicit operator Matrix2X3<long>(Matrix2X3<T> from)
446446
=> new(Scalar.As<T, long>(from.M11), Scalar.As<T, long>(from.M12), Scalar.As<T, long>(from.M13),
447447
Scalar.As<T, long>(from.M21), Scalar.As<T, long>(from.M22), Scalar.As<T, long>(from.M23));
448+
449+
/// <summary>
450+
/// Returns this matrix casted to <typeparamref name="TOther"></typeparamref>
451+
/// </summary>
452+
/// <typeparam name="TOther">The type to cast to</typeparam>
453+
/// <returns>The casted matrix</returns>
454+
public Matrix2X3<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
455+
{
456+
return new(Row1.As<TOther>(), Row2.As<TOther>());
457+
}
448458
}
449459
}

src/Maths/Silk.NET.Maths/Matrix2X4.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,5 +544,15 @@ public static explicit operator Matrix2X4<long>(Matrix2X4<T> from)
544544
Scalar.As<T, long>(from.M21), Scalar.As<T, long>(from.M22),
545545
Scalar.As<T, long>(from.M23), Scalar.As<T, long>(from.M24)
546546
);
547+
548+
/// <summary>
549+
/// Returns this matrix casted to <typeparamref name="TOther"></typeparamref>
550+
/// </summary>
551+
/// <typeparam name="TOther">The type to cast to</typeparam>
552+
/// <returns>The casted matrix</returns>
553+
public Matrix2X4<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
554+
{
555+
return new(Row1.As<TOther>(), Row2.As<TOther>());
556+
}
547557
}
548558
}

src/Maths/Silk.NET.Maths/Matrix3X2.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,5 +523,15 @@ public static explicit operator Matrix3X2<long>(Matrix3X2<T> from)
523523
Scalar.As<T, long>(from.M21), Scalar.As<T, long>(from.M22),
524524
Scalar.As<T, long>(from.M31), Scalar.As<T, long>(from.M32)
525525
);
526+
527+
/// <summary>
528+
/// Returns this matrix casted to <typeparamref name="TOther"></typeparamref>
529+
/// </summary>
530+
/// <typeparam name="TOther">The type to cast to</typeparam>
531+
/// <returns>The casted matrix</returns>
532+
public Matrix3X2<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
533+
{
534+
return new(Row1.As<TOther>(), Row2.As<TOther>(), Row3.As<TOther>());
535+
}
526536
}
527537
}

src/Maths/Silk.NET.Maths/Matrix3X3.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,5 +532,15 @@ public static explicit operator Matrix3X3<long>(Matrix3X3<T> from)
532532
=> new(Scalar.As<T, long>(from.M11), Scalar.As<T, long>(from.M12), Scalar.As<T, long>(from.M13),
533533
Scalar.As<T, long>(from.M21), Scalar.As<T, long>(from.M22), Scalar.As<T, long>(from.M23),
534534
Scalar.As<T, long>(from.M31), Scalar.As<T, long>(from.M32), Scalar.As<T, long>(from.M33));
535+
536+
/// <summary>
537+
/// Returns this matrix casted to <typeparamref name="TOther"></typeparamref>
538+
/// </summary>
539+
/// <typeparam name="TOther">The type to cast to</typeparam>
540+
/// <returns>The casted matrix</returns>
541+
public Matrix3X3<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
542+
{
543+
return new(Row1.As<TOther>(), Row2.As<TOther>(), Row3.As<TOther>());
544+
}
535545
}
536546
}

src/Maths/Silk.NET.Maths/Matrix3X4.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,5 +618,15 @@ public static explicit operator Matrix3X4<long>(Matrix3X4<T> from)
618618
Scalar.As<T, long>(from.M31), Scalar.As<T, long>(from.M32),
619619
Scalar.As<T, long>(from.M33), Scalar.As<T, long>(from.M34)
620620
);
621+
622+
/// <summary>
623+
/// Returns this matrix casted to <typeparamref name="TOther"></typeparamref>
624+
/// </summary>
625+
/// <typeparam name="TOther">The type to cast to</typeparam>
626+
/// <returns>The casted matrix</returns>
627+
public Matrix3X4<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
628+
{
629+
return new(Row1.As<TOther>(), Row2.As<TOther>(), Row3.As<TOther>());
630+
}
621631
}
622632
}

0 commit comments

Comments
 (0)