add Units
This commit is contained in:
parent
8a722f2426
commit
0bf0f884f6
|
@ -91,6 +91,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backend", "app\Backend\Back
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FossilTui", "app\FossilTui\FossilTui.csproj", "{C40264BB-C834-4C48-9B3F-6BEF8F37C0ED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Units", "lib\Units\Units.csproj", "{C04FB6DA-23C6-46BB-9B21-8F4FBA32FFF7}"
|
||||
EndProject
|
||||
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -240,6 +242,10 @@ Global
|
|||
{C40264BB-C834-4C48-9B3F-6BEF8F37C0ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C40264BB-C834-4C48-9B3F-6BEF8F37C0ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C40264BB-C834-4C48-9B3F-6BEF8F37C0ED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C04FB6DA-23C6-46BB-9B21-8F4FBA32FFF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C04FB6DA-23C6-46BB-9B21-8F4FBA32FFF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C04FB6DA-23C6-46BB-9B21-8F4FBA32FFF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C04FB6DA-23C6-46BB-9B21-8F4FBA32FFF7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{CF4834CB-91B7-4172-AC13-ECDA8613CD17} = {145597B4-3E30-45E6-9F72-4DD43194539A}
|
||||
|
@ -284,5 +290,6 @@ Global
|
|||
{A56F58C2-B265-435B-A985-53B4D6F49B1A} = {145597B4-3E30-45E6-9F72-4DD43194539A}
|
||||
{C40264BB-C834-4C48-9B3F-6BEF8F37C0ED} = {145597B4-3E30-45E6-9F72-4DD43194539A}
|
||||
{F162D50B-4B99-496D-8354-1FB68E992B2D} = {D846B46B-46FF-4EF7-9B9D-DDBEF9533C56}
|
||||
{C04FB6DA-23C6-46BB-9B21-8F4FBA32FFF7} = {AD5B98A8-AB7F-4DA2-B66D-5B4E63E7D854}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
36e3a7f5349a4b6ca48316c35ee500d6385e011f
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,34 @@
|
|||
namespace InnovEnergy.Units;
|
||||
|
||||
public readonly struct Current
|
||||
{
|
||||
public static String Unit => "A";
|
||||
public static String Symbol => "I";
|
||||
|
||||
public Decimal Value { get; }
|
||||
|
||||
public Current(Decimal value) => Value = value;
|
||||
|
||||
public override String ToString() => Value + Unit;
|
||||
|
||||
|
||||
// parallel
|
||||
public static Current operator |(Current left, Current right) => new Current(left.Value + right.Value);
|
||||
|
||||
// scalar multiplication
|
||||
public static Current operator *(Decimal scalar , Current current) => new Current(scalar * current.Value);
|
||||
public static Current operator *(Current current, Decimal scalar) => new Current(scalar * current.Value);
|
||||
public static Current operator *(Int32 scalar , Current current) => new Current(scalar * current.Value);
|
||||
public static Current operator *(Current current, Int32 scalar) => new Current(scalar * current.Value);
|
||||
public static Current operator /(Current current, Decimal scalar) => new Current(current.Value / scalar);
|
||||
public static Current operator /(Current current, Int32 scalar) => new Current(current.Value / scalar);
|
||||
|
||||
// P=UI
|
||||
public static Power operator *(Current current, Voltage voltage) => new Power(current.Value * voltage.Value);
|
||||
|
||||
// U=RI
|
||||
public static Voltage operator *(Current current, Resistance resistance) => new Voltage(resistance.Value* current.Value);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
namespace InnovEnergy.Units;
|
||||
|
||||
public readonly struct Power
|
||||
{
|
||||
public static String Unit => "W";
|
||||
public static String Symbol => "P";
|
||||
|
||||
public Decimal Value { get; }
|
||||
|
||||
public Power(Decimal value) => Value = value;
|
||||
|
||||
public override String ToString() => Value + Unit;
|
||||
|
||||
|
||||
// parallel
|
||||
public static Power operator |(Power left, Power right) => new Power(left.Value + right.Value);
|
||||
// series
|
||||
public static Power operator +(Power left, Power right) => new Power(left.Value + right.Value);
|
||||
|
||||
// scalar multiplication
|
||||
public static Power operator *(Decimal scalar, Power power ) => new Power(scalar * power.Value);
|
||||
public static Power operator *(Power power , Decimal scalar) => new Power(scalar * power.Value);
|
||||
public static Power operator *(Int32 scalar, Power power ) => new Power(scalar * power.Value);
|
||||
public static Power operator *(Power power , Int32 scalar) => new Power(scalar * power.Value);
|
||||
public static Power operator /(Power power , Decimal scalar) => new Power(power.Value / scalar);
|
||||
public static Power operator /(Power power , Int32 scalar) => new Power(power.Value / scalar);
|
||||
|
||||
// P=UI
|
||||
public static Voltage operator /(Power power, Current current) => new Voltage(power.Value / current.Value);
|
||||
public static Current operator /(Power power, Voltage voltage) => new Current(power.Value / voltage.Value);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
namespace InnovEnergy.Units;
|
||||
|
||||
public readonly struct Resistance
|
||||
{
|
||||
public static String Unit => "Ω";
|
||||
public static String Symbol => "R";
|
||||
|
||||
public Decimal Value { get; }
|
||||
|
||||
public Resistance(Decimal value) => Value = value;
|
||||
|
||||
public override String ToString() => Value + Unit;
|
||||
|
||||
// series
|
||||
public static Resistance operator +(Resistance left, Resistance right) => new Resistance(left.Value + right.Value);
|
||||
// parallel
|
||||
public static Resistance operator |(Resistance left, Resistance right) => new Resistance(1m / (1m / left.Value + 1m / right.Value));
|
||||
|
||||
// scalar multiplication
|
||||
public static Resistance operator *(Decimal scalar , Resistance resistance) => new Resistance(scalar * resistance.Value);
|
||||
public static Resistance operator *(Resistance resistance, Decimal scalar ) => new Resistance(scalar * resistance.Value);
|
||||
public static Resistance operator *(Int32 scalar , Resistance resistance) => new Resistance(scalar * resistance.Value);
|
||||
public static Resistance operator *(Resistance resistance, Int32 scalar ) => new Resistance(scalar * resistance.Value);
|
||||
public static Resistance operator /(Resistance resistance, Decimal scalar ) => new Resistance(resistance.Value / scalar);
|
||||
public static Resistance operator /(Resistance resistance, Int32 scalar ) => new Resistance(resistance.Value / scalar);
|
||||
|
||||
|
||||
// U=RI
|
||||
public static Voltage operator *(Resistance resistance, Current current) => new Voltage(resistance.Value* current.Value);
|
||||
|
||||
|
||||
|
||||
// public static Voltage operator /(Power power, Current current) => new Voltage(power.Value / current.Value);
|
||||
// public static Current operator /(Power power, Voltage voltage) => new Current(power.Value / voltage.Value);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="../InnovEnergy.lib.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>InnovEnergy.Units</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,32 @@
|
|||
namespace InnovEnergy.Units;
|
||||
|
||||
public readonly struct Voltage
|
||||
{
|
||||
public static String Unit => "V";
|
||||
public static String Symbol => "U";
|
||||
|
||||
public Decimal Value { get; }
|
||||
|
||||
public Voltage(Decimal value) => Value = value;
|
||||
|
||||
public override String ToString() => Value + Unit;
|
||||
|
||||
|
||||
// series
|
||||
public static Voltage operator +(Voltage left, Voltage right) => new Voltage(left.Value + right.Value);
|
||||
|
||||
public static Voltage operator *(Decimal scalar , Voltage voltage) => new Voltage(scalar * voltage.Value);
|
||||
public static Voltage operator *(Voltage voltage, Decimal scalar) => new Voltage(scalar * voltage.Value);
|
||||
public static Voltage operator *(Int32 scalar , Voltage voltage) => new Voltage(scalar * voltage.Value);
|
||||
public static Voltage operator *(Voltage voltage, Int32 scalar) => new Voltage(scalar * voltage.Value);
|
||||
|
||||
public static Voltage operator /(Voltage voltage, Decimal scalar) => new Voltage(voltage.Value / scalar);
|
||||
public static Voltage operator /(Voltage voltage, Int32 scalar) => new Voltage(voltage.Value / scalar);
|
||||
|
||||
|
||||
// U=RI
|
||||
public static Current operator /(Voltage voltage, Resistance resistance) => new Current(voltage.Value / resistance.Value);
|
||||
|
||||
// P=UI
|
||||
public static Power operator *(Voltage voltage, Current current) => new Power(current.Value * voltage.Value);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue