diff --git a/src/Titano.Core/Math/Matrix3.cs b/src/Titano.Core/Math/Matrix3.cs index 73b877cb..3e1bfc91 100644 --- a/src/Titano.Core/Math/Matrix3.cs +++ b/src/Titano.Core/Math/Matrix3.cs @@ -1,16 +1,7 @@ namespace Titano.Core.Mathematics; /// A 3-vector in double precision (colour triplets, homogeneous 2-D points). -public readonly record struct Vector3D(double X, double Y, double Z) -{ - public static Vector3D operator +(Vector3D a, Vector3D b) => new(a.X + b.X, a.Y + b.Y, a.Z + b.Z); - - public static Vector3D operator -(Vector3D a, Vector3D b) => new(a.X - b.X, a.Y - b.Y, a.Z - b.Z); - - public static Vector3D operator *(Vector3D a, double s) => new(a.X * s, a.Y * s, a.Z * s); - - public static double Dot(Vector3D a, Vector3D b) => a.X * b.X + a.Y * b.Y + a.Z * b.Z; -} +public readonly record struct Vector3D(double X, double Y, double Z); /// Row-major 3×3 matrix in double precision for colour-space and planar projective work. public readonly record struct Matrix3( @@ -47,9 +38,6 @@ public readonly record struct Matrix3( m.M21 * v.X + m.M22 * v.Y + m.M23 * v.Z, m.M31 * v.X + m.M32 * v.Y + m.M33 * v.Z); - public static Matrix3 operator *(Matrix3 m, double s) => new( - m.M11 * s, m.M12 * s, m.M13 * s, m.M21 * s, m.M22 * s, m.M23 * s, m.M31 * s, m.M32 * s, m.M33 * s); - public double Determinant => M11 * (M22 * M33 - M23 * M32) - M12 * (M21 * M33 - M23 * M31) + M13 * (M21 * M32 - M22 * M31); diff --git a/src/Titano.Core/Math/Point2.cs b/src/Titano.Core/Math/Point2.cs index 848095ae..d1c1522c 100644 --- a/src/Titano.Core/Math/Point2.cs +++ b/src/Titano.Core/Math/Point2.cs @@ -14,6 +14,4 @@ public readonly record struct Point2(double X, double Y) public double Length => Math.Sqrt(X * X + Y * Y); public static double Distance(Point2 a, Point2 b) => (a - b).Length; - - public static Point2 Lerp(Point2 a, Point2 b, double t) => new(a.X + (b.X - a.X) * t, a.Y + (b.Y - a.Y) * t); } diff --git a/tests/Titano.Core.Tests/Math/StatisticsTests.cs b/tests/Titano.Core.Tests/Math/StatisticsTests.cs index 0161826b..b845d789 100644 --- a/tests/Titano.Core.Tests/Math/StatisticsTests.cs +++ b/tests/Titano.Core.Tests/Math/StatisticsTests.cs @@ -119,9 +119,18 @@ public sealed class StatisticsTests var random = new Random(11); var values = Enumerable.Range(0, 501).Select(_ => random.NextDouble() < 0.1 ? double.NaN : random.NextDouble() * 10 - 5).ToArray(); double Run() => Statistics.Median(values) + Statistics.MedianAbsoluteDeviation(values) + Statistics.TrimmedMean(values, 0.02, 0.02) - + Statistics.Percentile(values, 0.9) + Statistics.Mean(values) + Statistics.StandardDeviation(values); + + Statistics.Percentile(values, 0.9) + Statistics.Mean(values) + Statistics.StandardDeviation(values) + Statistics.Rms(values); var first = Run(); Assert.True(double.IsFinite(first)); Assert.Equal(first, Run()); } + + [Test] + public void MomentsOfAKnownSet() + { + double[] values = [2, 4, double.NaN, 4, 4, 5, 5, 7, 9]; + Assert.Approximately(5, Statistics.Mean(values), 1e-12); + Assert.Approximately(Math.Sqrt(32.0 / 7), Statistics.StandardDeviation(values), 1e-12); + Assert.Approximately(Math.Sqrt(232.0 / 8), Statistics.Rms(values), 1e-12); + } }