System.DoubleNumerics by weingartner machinen bau

<PackageReference Include="System.DoubleNumerics" Version="3.1.0" />

 Matrix3x2

public struct Matrix3x2 : IEquatable<Matrix3x2>
using System.Globalization; namespace System.DoubleNumerics { public struct Matrix3x2 : IEquatable<Matrix3x2> { public double M11; public double M12; public double M21; public double M22; public double M31; public double M32; private static readonly Matrix3x2 _identity = new Matrix3x2(1, 0, 0, 1, 0, 0); public static Matrix3x2 Identity => _identity; public bool IsIdentity => M11 == 1 && M22 == 1 && M12 == 0 && M21 == 0 && M31 == 0 && M32 == 0; public Vector2 Translation { get { return new Vector2(M31, M32); } set { M31 = value.X; M32 = value.Y; } } public Matrix3x2(double m11, double m12, double m21, double m22, double m31, double m32) { M11 = m11; M12 = m12; M21 = m21; M22 = m22; M31 = m31; M32 = m32; } public static Matrix3x2 CreateTranslation(Vector2 position) { Matrix3x2 result = default(Matrix3x2); result.M11 = 1; result.M12 = 0; result.M21 = 0; result.M22 = 1; result.M31 = position.X; result.M32 = position.Y; return result; } public static Matrix3x2 CreateTranslation(double xPosition, double yPosition) { Matrix3x2 result = default(Matrix3x2); result.M11 = 1; result.M12 = 0; result.M21 = 0; result.M22 = 1; result.M31 = xPosition; result.M32 = yPosition; return result; } public static Matrix3x2 CreateScale(double xScale, double yScale) { Matrix3x2 result = default(Matrix3x2); result.M11 = xScale; result.M12 = 0; result.M21 = 0; result.M22 = yScale; result.M31 = 0; result.M32 = 0; return result; } public static Matrix3x2 CreateScale(double xScale, double yScale, Vector2 centerPoint) { double m = centerPoint.X * (1 - xScale); double m2 = centerPoint.Y * (1 - yScale); Matrix3x2 result = default(Matrix3x2); result.M11 = xScale; result.M12 = 0; result.M21 = 0; result.M22 = yScale; result.M31 = m; result.M32 = m2; return result; } public static Matrix3x2 CreateScale(Vector2 scales) { Matrix3x2 result = default(Matrix3x2); result.M11 = scales.X; result.M12 = 0; result.M21 = 0; result.M22 = scales.Y; result.M31 = 0; result.M32 = 0; return result; } public static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint) { double m = centerPoint.X * (1 - scales.X); double m2 = centerPoint.Y * (1 - scales.Y); Matrix3x2 result = default(Matrix3x2); result.M11 = scales.X; result.M12 = 0; result.M21 = 0; result.M22 = scales.Y; result.M31 = m; result.M32 = m2; return result; } public static Matrix3x2 CreateScale(double scale) { Matrix3x2 result = default(Matrix3x2); result.M11 = scale; result.M12 = 0; result.M21 = 0; result.M22 = scale; result.M31 = 0; result.M32 = 0; return result; } public static Matrix3x2 CreateScale(double scale, Vector2 centerPoint) { double m = centerPoint.X * (1 - scale); double m2 = centerPoint.Y * (1 - scale); Matrix3x2 result = default(Matrix3x2); result.M11 = scale; result.M12 = 0; result.M21 = 0; result.M22 = scale; result.M31 = m; result.M32 = m2; return result; } public static Matrix3x2 CreateSkew(double radiansX, double radiansY) { double m = Math.Tan(radiansX); double m2 = Math.Tan(radiansY); Matrix3x2 result = default(Matrix3x2); result.M11 = 1; result.M12 = m2; result.M21 = m; result.M22 = 1; result.M31 = 0; result.M32 = 0; return result; } public static Matrix3x2 CreateSkew(double radiansX, double radiansY, Vector2 centerPoint) { double num = Math.Tan(radiansX); double num2 = Math.Tan(radiansY); double m = (0 - centerPoint.Y) * num; double m2 = (0 - centerPoint.X) * num2; Matrix3x2 result = default(Matrix3x2); result.M11 = 1; result.M12 = num2; result.M21 = num; result.M22 = 1; result.M31 = m; result.M32 = m2; return result; } public static Matrix3x2 CreateRotation(double radians) { radians = Math.IEEERemainder(radians, 6.283185307179586); double num; double num2; if (radians > -1.7453292519943296E-05 && radians < 1.7453292519943296E-05) { num = 1; num2 = 0; } else if (radians > 1.5707788735023767 && radians < 1.5708137800874165) { num = 0; num2 = 1; } else if (radians < -3.141575200297273 || radians > 3.141575200297273) { num = -1; num2 = 0; } else if (radians > -1.5708137800874165 && radians < -1.5707788735023767) { num = 0; num2 = -1; } else { num = Math.Cos(radians); num2 = Math.Sin(radians); } Matrix3x2 result = default(Matrix3x2); result.M11 = num; result.M12 = num2; result.M21 = 0 - num2; result.M22 = num; result.M31 = 0; result.M32 = 0; return result; } public static Matrix3x2 CreateRotation(double radians, Vector2 centerPoint) { radians = Math.IEEERemainder(radians, 6.283185307179586); double num; double num2; if (radians > -1.7453292519943296E-05 && radians < 1.7453292519943296E-05) { num = 1; num2 = 0; } else if (radians > 1.5707788735023767 && radians < 1.5708137800874165) { num = 0; num2 = 1; } else if (radians < -3.141575200297273 || radians > 3.141575200297273) { num = -1; num2 = 0; } else if (radians > -1.5708137800874165 && radians < -1.5707788735023767) { num = 0; num2 = -1; } else { num = Math.Cos(radians); num2 = Math.Sin(radians); } double m = centerPoint.X * (1 - num) + centerPoint.Y * num2; double m2 = centerPoint.Y * (1 - num) - centerPoint.X * num2; Matrix3x2 result = default(Matrix3x2); result.M11 = num; result.M12 = num2; result.M21 = 0 - num2; result.M22 = num; result.M31 = m; result.M32 = m2; return result; } public double GetDeterminant() { return M11 * M22 - M21 * M12; } public static bool Invert(Matrix3x2 matrix, out Matrix3x2 result) { double num = matrix.M11 * matrix.M22 - matrix.M21 * matrix.M12; if (!(Math.Abs(num) < 5E-324)) { double num2 = 1 / num; result.M11 = matrix.M22 * num2; result.M12 = (0 - matrix.M12) * num2; result.M21 = (0 - matrix.M21) * num2; result.M22 = matrix.M11 * num2; result.M31 = (matrix.M21 * matrix.M32 - matrix.M31 * matrix.M22) * num2; result.M32 = (matrix.M31 * matrix.M12 - matrix.M11 * matrix.M32) * num2; return true; } result = new Matrix3x2(NaN, NaN, NaN, NaN, NaN, NaN); return false; } public static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, double amount) { Matrix3x2 result = default(Matrix3x2); result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount; result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount; result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount; result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount; result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount; result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount; return result; } public static Matrix3x2 Negate(Matrix3x2 value) { Matrix3x2 result = default(Matrix3x2); result.M11 = 0 - value.M11; result.M12 = 0 - value.M12; result.M21 = 0 - value.M21; result.M22 = 0 - value.M22; result.M31 = 0 - value.M31; result.M32 = 0 - value.M32; return result; } public static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 + value2.M11; result.M12 = value1.M12 + value2.M12; result.M21 = value1.M21 + value2.M21; result.M22 = value1.M22 + value2.M22; result.M31 = value1.M31 + value2.M31; result.M32 = value1.M32 + value2.M32; return result; } public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 - value2.M11; result.M12 = value1.M12 - value2.M12; result.M21 = value1.M21 - value2.M21; result.M22 = value1.M22 - value2.M22; result.M31 = value1.M31 - value2.M31; result.M32 = value1.M32 - value2.M32; return result; } public static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; return result; } public static Matrix3x2 Multiply(Matrix3x2 value1, double value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 * value2; result.M12 = value1.M12 * value2; result.M21 = value1.M21 * value2; result.M22 = value1.M22 * value2; result.M31 = value1.M31 * value2; result.M32 = value1.M32 * value2; return result; } public static Matrix3x2 operator -(Matrix3x2 value) { Matrix3x2 result = default(Matrix3x2); result.M11 = 0 - value.M11; result.M12 = 0 - value.M12; result.M21 = 0 - value.M21; result.M22 = 0 - value.M22; result.M31 = 0 - value.M31; result.M32 = 0 - value.M32; return result; } public static Matrix3x2 operator +(Matrix3x2 value1, Matrix3x2 value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 + value2.M11; result.M12 = value1.M12 + value2.M12; result.M21 = value1.M21 + value2.M21; result.M22 = value1.M22 + value2.M22; result.M31 = value1.M31 + value2.M31; result.M32 = value1.M32 + value2.M32; return result; } public static Matrix3x2 operator -(Matrix3x2 value1, Matrix3x2 value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 - value2.M11; result.M12 = value1.M12 - value2.M12; result.M21 = value1.M21 - value2.M21; result.M22 = value1.M22 - value2.M22; result.M31 = value1.M31 - value2.M31; result.M32 = value1.M32 - value2.M32; return result; } public static Matrix3x2 operator *(Matrix3x2 value1, Matrix3x2 value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; return result; } public static Matrix3x2 operator *(Matrix3x2 value1, double value2) { Matrix3x2 result = default(Matrix3x2); result.M11 = value1.M11 * value2; result.M12 = value1.M12 * value2; result.M21 = value1.M21 * value2; result.M22 = value1.M22 * value2; result.M31 = value1.M31 * value2; result.M32 = value1.M32 * value2; return result; } public static bool operator ==(Matrix3x2 value1, Matrix3x2 value2) { return value1.M11 == value2.M11 && value1.M22 == value2.M22 && value1.M12 == value2.M12 && value1.M21 == value2.M21 && value1.M31 == value2.M31 && value1.M32 == value2.M32; } public static bool operator !=(Matrix3x2 value1, Matrix3x2 value2) { return value1.M11 != value2.M11 || value1.M12 != value2.M12 || value1.M21 != value2.M21 || value1.M22 != value2.M22 || value1.M31 != value2.M31 || value1.M32 != value2.M32; } public bool Equals(Matrix3x2 other) { return M11 == other.M11 && M22 == other.M22 && M12 == other.M12 && M21 == other.M21 && M31 == other.M31 && M32 == other.M32; } public override bool Equals(object obj) { if (!(obj is Matrix3x2)) return false; return Equals((Matrix3x2)obj); } public override string ToString() { CultureInfo currentCulture = CultureInfo.CurrentCulture; return string.Format(currentCulture, "{{ {{M11:{0} M12:{1}}} {{M21:{2} M22:{3}}} {{M31:{4} M32:{5}}} }}", M11.ToString(currentCulture), M12.ToString(currentCulture), M21.ToString(currentCulture), M22.ToString(currentCulture), M31.ToString(currentCulture), M32.ToString(currentCulture)); } public override int GetHashCode() { return M11.GetHashCode() + M12.GetHashCode() + M21.GetHashCode() + M22.GetHashCode() + M31.GetHashCode() + M32.GetHashCode(); } } }