diff --git a/csharp/Lib/Units/Composite/Ac3Bus.cs b/csharp/Lib/Units/Composite/Ac3Bus.cs index 82c2068ed..2301c1d97 100644 --- a/csharp/Lib/Units/Composite/Ac3Bus.cs +++ b/csharp/Lib/Units/Composite/Ac3Bus.cs @@ -1,7 +1,9 @@ +using System.Collections; + namespace InnovEnergy.Lib.Units.Composite; -public record Ac3Bus +public record Ac3Bus : IReadOnlyList { public required AcPhase L1 { get; init; } public required AcPhase L2 { get; init; } @@ -17,4 +19,23 @@ public record Ac3Bus L2 = AcPhase.Zero, L3 = AcPhase.Zero, }; + + public IEnumerator GetEnumerator() + { + yield return L1; + yield return L2; + yield return L3; + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public Int32 Count => 3; + + public AcPhase this[Int32 index] => index switch + { + 0 => L1, // it's retarded + 1 => L2, + 2 => L3, + _ => throw new ArgumentOutOfRangeException(nameof(index)) + }; } \ No newline at end of file diff --git a/csharp/Lib/Units/Generator/Average.cs b/csharp/Lib/Units/Generator/Average.cs deleted file mode 100644 index 6ec0c6ad5..000000000 --- a/csharp/Lib/Units/Generator/Average.cs +++ /dev/null @@ -1,11 +0,0 @@ - -// ReSharper disable once CheckNamespace -namespace InnovEnergy.Lib.Units; - -public readonly struct Average -{ - public Average(Double value) => throw new NotImplementedException(); - public Double Value => throw new NotImplementedException(); - - public static Average operator |(Average left, Average right) => new((left.Value + right.Value) / 2); -} \ No newline at end of file diff --git a/csharp/Lib/Units/Generator/Operators.cs b/csharp/Lib/Units/Generator/Operators.cs deleted file mode 100644 index 1c28c9427..000000000 --- a/csharp/Lib/Units/Generator/Operators.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using InnovEnergy.Lib.Utils; - -// ReSharper disable once CheckNamespace -namespace InnovEnergy.Lib.Units; - -[SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")] -public readonly struct Operators -{ - public static String Unit => throw new NotImplementedException(); - public static String Symbol => throw new NotImplementedException(); - - #if !HAS_CONSTRUCTOR - public Operators(Double value) => Value = value; - #endif - - public Double Value { get; } - public override String ToString() => Value.RoundToSignificantDigits(Units.DisplaySignificantDigits) + Unit; - - // scalar multiplication - - public static Operators operator *(Double scalar, Operators t) => new Operators(scalar * t.Value); - public static Operators operator *(Operators t, Double scalar) => new Operators(scalar * t.Value); - public static Operators operator /(Operators t, Double scalar) => new Operators(t.Value / scalar); - - // addition - - public static Operators operator +(Operators left, Operators right) => new Operators(left.Value + right.Value); - public static Operators operator -(Operators left, Operators right) => new Operators(left.Value - right.Value); - public static Operators operator -(Operators t) => new Operators(-t.Value); - - // compare - - public static Boolean operator ==(Operators left, Operators right) => left.Value == right.Value; - public static Boolean operator !=(Operators left, Operators right) => left.Value != right.Value; - public static Boolean operator > (Operators left, Operators right) => left.Value > right.Value; - public static Boolean operator < (Operators left, Operators right) => left.Value < right.Value; - public static Boolean operator >=(Operators left, Operators right) => left.Value >= right.Value; - public static Boolean operator <=(Operators left, Operators right) => left.Value <= right.Value; - - // conversion - - public static implicit operator Operators(Double d) => new Operators(d); - - // equality - - public Boolean Equals(Operators other) => Value == other.Value; - public override Boolean Equals(Object? obj) => obj is Operators other && Equals(other); - public override Int32 GetHashCode() => Value.GetHashCode(); - -} \ No newline at end of file diff --git a/csharp/Lib/Units/Generator/Parallel.cs b/csharp/Lib/Units/Generator/Parallel.cs deleted file mode 100644 index 942cb416e..000000000 --- a/csharp/Lib/Units/Generator/Parallel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Diagnostics.CodeAnalysis; - -// ReSharper disable once CheckNamespace -namespace InnovEnergy.Lib.Units; - -public readonly struct Parallel -{ - public Parallel(Double value) => throw new NotImplementedException(); - public Double Value => throw new NotImplementedException(); - - public static Parallel operator |(Parallel left, Parallel right) => new((left.Value * right.Value) / (left.Value + right.Value)); -} \ No newline at end of file diff --git a/csharp/Lib/Units/Generator/Sum.cs b/csharp/Lib/Units/Generator/Sum.cs deleted file mode 100644 index 30b06abff..000000000 --- a/csharp/Lib/Units/Generator/Sum.cs +++ /dev/null @@ -1,11 +0,0 @@ - -// ReSharper disable once CheckNamespace -namespace InnovEnergy.Lib.Units; - -public readonly struct Sum -{ - public Sum(Double value) => throw new NotImplementedException(); - public Double Value => throw new NotImplementedException(); - - public static Sum operator |(Sum left, Sum right) => new(left.Value + right.Value); -} \ No newline at end of file diff --git a/csharp/Lib/Units/Power/AcPower.cs b/csharp/Lib/Units/Power/AcPower.cs deleted file mode 100644 index d1aadbc7f..000000000 --- a/csharp/Lib/Units/Power/AcPower.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace InnovEnergy.Lib.Units.Power; - -public abstract class AcPower : Power -{ - protected AcPower(Double value) : base(value) - { - } -} \ No newline at end of file diff --git a/csharp/Lib/Units/Power/ActivePower.cs b/csharp/Lib/Units/Power/ActivePower.cs index 0fb663a80..0c418850f 100644 --- a/csharp/Lib/Units/Power/ActivePower.cs +++ b/csharp/Lib/Units/Power/ActivePower.cs @@ -1,7 +1,7 @@ namespace InnovEnergy.Lib.Units.Power; -public sealed class ActivePower : AcPower +public sealed class ActivePower : Power { public override String Symbol => "W"; @@ -13,7 +13,5 @@ public sealed class ActivePower : AcPower public static implicit operator Double(ActivePower d) => d.Value; public static ActivePower operator -(ActivePower d) => -d.Value; - - } diff --git a/csharp/Lib/Units/Power/ApparentPower.cs b/csharp/Lib/Units/Power/ApparentPower.cs index 7704929ea..51038a742 100644 --- a/csharp/Lib/Units/Power/ApparentPower.cs +++ b/csharp/Lib/Units/Power/ApparentPower.cs @@ -1,6 +1,6 @@ namespace InnovEnergy.Lib.Units.Power; -public sealed class ApparentPower : AcPower +public sealed class ApparentPower : Power { public override String Symbol => "VA"; diff --git a/csharp/Lib/Units/Power/ReactivePower.cs b/csharp/Lib/Units/Power/ReactivePower.cs index ee6bb35cd..d94005600 100644 --- a/csharp/Lib/Units/Power/ReactivePower.cs +++ b/csharp/Lib/Units/Power/ReactivePower.cs @@ -1,6 +1,6 @@ namespace InnovEnergy.Lib.Units.Power; -public sealed class ReactivePower : AcPower +public sealed class ReactivePower : Power { public override String Symbol => "var";