style patterns

This commit is contained in:
Miha Kralj
2026-01-25 16:01:45 -08:00
parent 2836f253c4
commit e59665c8f0
399 changed files with 6892 additions and 1323 deletions
+1 -1
View File
@@ -109,4 +109,4 @@ public class Cheby2Tests
Assert.Equal(iterativeResults[i], spanResults[i], 1e-10);
}
}
}
}
@@ -21,9 +21,11 @@ public class Cheby2ValidationTests
Assert.True(Math.Abs(result1) > 0);
// Verify stability (should decay towards zero for lowpass IIR)
for(int i=0; i<50; i++)
for (int i = 0; i < 50; i++)
{
filter.Update(new TValue(DateTime.UtcNow, 0.0));
}
Assert.True(Math.Abs(filter.Last.Value) < 1e-5);
}
}
}
+22 -2
View File
@@ -46,9 +46,14 @@ public sealed class Cheby2 : AbstractBase
public Cheby2(int period, double attenuation = 5.0)
{
if (period < 2)
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be >= 2");
}
if (attenuation <= 0)
{
throw new ArgumentOutOfRangeException(nameof(attenuation), "Attenuation must be > 0");
}
Period = period;
Attenuation = attenuation;
@@ -123,7 +128,10 @@ public sealed class Cheby2 : AbstractBase
public override TSeries Update(TSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
double[] values = source.Values.ToArray();
double[] results = new double[values.Length];
@@ -192,7 +200,9 @@ public sealed class Cheby2 : AbstractBase
_state.Filt1 = filt;
if (_state.Count < 2)
{
_state.Count++;
}
}
Last = new TValue(input.Time, filt);
@@ -211,12 +221,19 @@ public sealed class Cheby2 : AbstractBase
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period, double attenuation = 5.0)
{
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output spans must be of the same length.", nameof(output));
}
if (period < 2)
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be >= 2");
}
if (attenuation <= 0)
{
throw new ArgumentOutOfRangeException(nameof(attenuation), "Attenuation must be > 0");
}
// Coefficients
double safeAtten = Math.Max(attenuation, 0.1);
@@ -268,7 +285,10 @@ public sealed class Cheby2 : AbstractBase
if (source.Length > 0)
{
lastValid = source[0];
if (!double.IsFinite(lastValid)) lastValid = 0;
if (!double.IsFinite(lastValid))
{
lastValid = 0;
}
}
for (int i = 0; i < source.Length; i++)