All matrix types are no longer records.
This commit is contained in:
parent
8b4e61ce82
commit
99b3185f38
@ -1,6 +1,6 @@
|
|||||||
namespace Nerd_STF.Mathematics.Abstract;
|
namespace Nerd_STF.Mathematics.Abstract;
|
||||||
|
|
||||||
public interface IStaticMatrix<T> : IAverage<T>, IMatrix<T>, IMedian<T>,
|
public interface IStaticMatrix<T> : IAverage<T>, IEquatable<T>, IMatrix<T>, IMedian<T>,
|
||||||
IMatrixPresets<T> where T : IStaticMatrix<T>
|
IMatrixPresets<T> where T : IStaticMatrix<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -343,16 +343,14 @@ public class Matrix : IMatrix<Matrix, Matrix>
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals([NotNullWhen(true)] object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
if (obj == null) return base.Equals(obj);
|
if (obj is null) return base.Equals(obj);
|
||||||
Type t = obj.GetType();
|
else if (obj is Matrix m) return Equals(m);
|
||||||
if (t == typeof(Matrix)) return Equals((Matrix)obj);
|
else if (obj is Matrix2x2 m2x2) return Equals(m2x2);
|
||||||
else if (t == typeof(Matrix2x2)) return Equals((Matrix)obj);
|
else if (obj is Matrix3x3 m3x3) return Equals(m3x3);
|
||||||
else if (t == typeof(Matrix3x3)) return Equals((Matrix)obj);
|
else if (obj is Matrix4x4 m4x4) return Equals(m4x4);
|
||||||
else if (t == typeof(Matrix4x4)) return Equals((Matrix)obj);
|
return false;
|
||||||
|
|
||||||
return base.Equals(obj);
|
|
||||||
}
|
}
|
||||||
public bool Equals(Matrix? other)
|
public bool Equals(Matrix? other)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
namespace Nerd_STF.Mathematics.Algebra;
|
namespace Nerd_STF.Mathematics.Algebra;
|
||||||
|
|
||||||
public record class Matrix2x2 : IStaticMatrix<Matrix2x2>
|
public class Matrix2x2 : IStaticMatrix<Matrix2x2>
|
||||||
{
|
{
|
||||||
public static Matrix2x2 Identity => new(new[,]
|
public static Matrix2x2 Identity => new(new[,]
|
||||||
{
|
{
|
||||||
@ -312,6 +312,12 @@ public record class Matrix2x2 : IStaticMatrix<Matrix2x2>
|
|||||||
SetRow(rowB, dataA);
|
SetRow(rowB, dataA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is null) return false;
|
||||||
|
else if (obj is Matrix2x2 m2x2) return Equals(m2x2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public virtual bool Equals(Matrix2x2? other)
|
public virtual bool Equals(Matrix2x2? other)
|
||||||
{
|
{
|
||||||
if (other is null) return false;
|
if (other is null) return false;
|
||||||
@ -365,6 +371,8 @@ public record class Matrix2x2 : IStaticMatrix<Matrix2x2>
|
|||||||
public static Float2 operator /(Matrix2x2 a, Float2 b) => (Matrix)a / b;
|
public static Float2 operator /(Matrix2x2 a, Float2 b) => (Matrix)a / b;
|
||||||
public static Matrix2x2 operator ^(Matrix2x2 a, Matrix2x2 b) => // Single number multiplication.
|
public static Matrix2x2 operator ^(Matrix2x2 a, Matrix2x2 b) => // Single number multiplication.
|
||||||
new(a.r1c1 * b.r1c1, a.r1c2 * b.r1c2, a.r2c1 * b.r2c1, a.r2c2 * b.r2c2);
|
new(a.r1c1 * b.r1c1, a.r1c2 * b.r1c2, a.r2c1 * b.r2c1, a.r2c2 * b.r2c2);
|
||||||
|
public static bool operator ==(Matrix2x2 a, Matrix2x2 b) => a.Equals(b);
|
||||||
|
public static bool operator !=(Matrix2x2 a, Matrix2x2 b) => !a.Equals(b);
|
||||||
|
|
||||||
public static explicit operator Matrix2x2(Matrix m)
|
public static explicit operator Matrix2x2(Matrix m)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
namespace Nerd_STF.Mathematics.Algebra;
|
namespace Nerd_STF.Mathematics.Algebra;
|
||||||
|
|
||||||
public record class Matrix3x3 : IStaticMatrix<Matrix3x3>
|
public class Matrix3x3 : IStaticMatrix<Matrix3x3>
|
||||||
{
|
{
|
||||||
public static Matrix3x3 Identity => new(new[,]
|
public static Matrix3x3 Identity => new(new[,]
|
||||||
{
|
{
|
||||||
@ -435,6 +435,12 @@ public record class Matrix3x3 : IStaticMatrix<Matrix3x3>
|
|||||||
SetRow(rowB, dataA);
|
SetRow(rowB, dataA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is null) return false;
|
||||||
|
else if (obj is Matrix3x3 m3x3) return Equals(m3x3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public virtual bool Equals(Matrix3x3? other)
|
public virtual bool Equals(Matrix3x3? other)
|
||||||
{
|
{
|
||||||
if (other is null) return false;
|
if (other is null) return false;
|
||||||
@ -512,6 +518,8 @@ public record class Matrix3x3 : IStaticMatrix<Matrix3x3>
|
|||||||
new(a.r1c1 * b.r1c1, a.r1c2 * b.r1c2, a.r1c3 * b.r1c3,
|
new(a.r1c1 * b.r1c1, a.r1c2 * b.r1c2, a.r1c3 * b.r1c3,
|
||||||
a.r2c1 * b.r2c1, a.r2c2 * b.r2c2, a.r2c3 * b.r2c3,
|
a.r2c1 * b.r2c1, a.r2c2 * b.r2c2, a.r2c3 * b.r2c3,
|
||||||
a.r3c1 * b.r3c1, a.r3c2 * b.r3c2, a.r3c3 * b.r3c3);
|
a.r3c1 * b.r3c1, a.r3c2 * b.r3c2, a.r3c3 * b.r3c3);
|
||||||
|
public static bool operator ==(Matrix3x3 a, Matrix3x3 b) => a.Equals(b);
|
||||||
|
public static bool operator !=(Matrix3x3 a, Matrix3x3 b) => !a.Equals(b);
|
||||||
|
|
||||||
public static explicit operator Matrix3x3(Matrix m)
|
public static explicit operator Matrix3x3(Matrix m)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Nerd_STF.Mathematics.Algebra;
|
namespace Nerd_STF.Mathematics.Algebra;
|
||||||
|
|
||||||
public record class Matrix4x4 : IStaticMatrix<Matrix4x4>
|
public class Matrix4x4 : IStaticMatrix<Matrix4x4>
|
||||||
{
|
{
|
||||||
public static Matrix4x4 Identity => new(new[,]
|
public static Matrix4x4 Identity => new(new[,]
|
||||||
{
|
{
|
||||||
@ -530,6 +530,12 @@ public record class Matrix4x4 : IStaticMatrix<Matrix4x4>
|
|||||||
SetRow(rowB, dataA);
|
SetRow(rowB, dataA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is null) return false;
|
||||||
|
else if (obj is Matrix4x4 m4x4) return Equals(m4x4);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public virtual bool Equals(Matrix4x4? other)
|
public virtual bool Equals(Matrix4x4? other)
|
||||||
{
|
{
|
||||||
if (other is null) return false;
|
if (other is null) return false;
|
||||||
@ -639,6 +645,8 @@ public record class Matrix4x4 : IStaticMatrix<Matrix4x4>
|
|||||||
a.r2c1 * b.r2c1, a.r2c2 * b.r2c2, a.r2c3 * b.r2c3, a.r2c4 * b.r2c4,
|
a.r2c1 * b.r2c1, a.r2c2 * b.r2c2, a.r2c3 * b.r2c3, a.r2c4 * b.r2c4,
|
||||||
a.r3c1 * b.r3c1, a.r3c2 * b.r3c2, a.r3c3 * b.r3c3, a.r3c4 * b.r3c4,
|
a.r3c1 * b.r3c1, a.r3c2 * b.r3c2, a.r3c3 * b.r3c3, a.r3c4 * b.r3c4,
|
||||||
a.r4c1 * b.r4c1, a.r4c2 * b.r4c2, a.r4c3 * b.r4c3, a.r4c4 * b.r4c4);
|
a.r4c1 * b.r4c1, a.r4c2 * b.r4c2, a.r4c3 * b.r4c3, a.r4c4 * b.r4c4);
|
||||||
|
public static bool operator ==(Matrix4x4 a, Matrix4x4 b) => a.Equals(b);
|
||||||
|
public static bool operator !=(Matrix4x4 a, Matrix4x4 b) => !a.Equals(b);
|
||||||
|
|
||||||
public static explicit operator Matrix4x4(Matrix m)
|
public static explicit operator Matrix4x4(Matrix m)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
namespace Nerd_STF.Mathematics.Algebra;
|
namespace Nerd_STF.Mathematics.Algebra;
|
||||||
|
|
||||||
public record class ProjectionMatrix : Matrix3x3
|
public class ProjectionMatrix : Matrix3x3
|
||||||
{
|
{
|
||||||
// TODO: i need to remove the record check from everything, add new equals comparitors
|
// TODO: i need to remove the record check from everything, add new equals comparitors
|
||||||
// and re-implement IsValidProjectionMatrix
|
// and re-implement IsValidProjectionMatrix
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user