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
@@ -111,4 +111,4 @@ public class Cheby1Tests
Assert.Equal(iterativeResults[i], spanResults[i], 1e-10);
}
}
}
}
@@ -20,7 +20,10 @@ public class Cheby1ValidationTests
var filter = new Cheby1(20, 1.0); // Wn = 1/20
var input = new TSeries();
for (int i = 0; i < 100; i++) input.Add(new TValue(DateTime.UtcNow, 100)); // Impulse/Step
for (int i = 0; i < 100; i++)
{
input.Add(new TValue(DateTime.UtcNow, 100)); // Impulse/Step
}
var output = filter.Update(input);
+23 -3
View File
@@ -46,9 +46,14 @@ public sealed class Cheby1 : AbstractBase
public Cheby1(int period, double ripple = 1.0)
{
if (period < 2)
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be >= 2");
}
if (ripple <= 0)
{
throw new ArgumentOutOfRangeException(nameof(ripple), "Ripple must be > 0");
}
Period = period;
Ripple = ripple;
@@ -105,7 +110,10 @@ public sealed class Cheby1 : 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];
@@ -178,7 +186,9 @@ public sealed class Cheby1 : AbstractBase
_state.Filt1 = filt;
if (_state.Count < 2)
{
_state.Count++;
}
}
Last = new TValue(input.Time, filt);
@@ -197,12 +207,19 @@ public sealed class Cheby1 : AbstractBase
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period, double ripple = 1.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 (ripple <= 0)
{
throw new ArgumentOutOfRangeException(nameof(ripple), "Ripple must be > 0");
}
// Coefficients
double safeRipple = Math.Max(ripple, 0.01);
@@ -239,7 +256,10 @@ public sealed class Cheby1 : 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++)
@@ -285,4 +305,4 @@ public sealed class Cheby1 : AbstractBase
}
base.Dispose(disposing);
}
}
}