clean up powers

This commit is contained in:
ig 2023-09-01 10:03:29 +02:00
parent 05f0a7e9f9
commit 20c3e95666
9 changed files with 25 additions and 99 deletions

View File

@ -1,7 +1,9 @@
using System.Collections;
namespace InnovEnergy.Lib.Units.Composite;
public record Ac3Bus
public record Ac3Bus : IReadOnlyList<AcPhase>
{
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<AcPhase> 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))
};
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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));
}

View File

@ -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);
}

View File

@ -1,8 +0,0 @@
namespace InnovEnergy.Lib.Units.Power;
public abstract class AcPower : Power
{
protected AcPower(Double value) : base(value)
{
}
}

View File

@ -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;
}

View File

@ -1,6 +1,6 @@
namespace InnovEnergy.Lib.Units.Power;
public sealed class ApparentPower : AcPower
public sealed class ApparentPower : Power
{
public override String Symbol => "VA";

View File

@ -1,6 +1,6 @@
namespace InnovEnergy.Lib.Units.Power;
public sealed class ReactivePower : AcPower
public sealed class ReactivePower : Power
{
public override String Symbol => "var";