170 lines
11 KiB
C#
170 lines
11 KiB
C#
namespace QWERTYkez.Mensura.Units;
|
|
|
|
internal static class Coefficients
|
|
{
|
|
internal static double MultiplyCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
|
|
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
|
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
|
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
|
=> r.ToDouble() / (a.ToDouble() * b.ToDouble());
|
|
|
|
internal static double DivideCoefficient<T1, T2, TResult>(T1 a, T2 b, TResult r)
|
|
where T1 : struct, IMensuraUnit<T1>, IEquatable<T1>, IMensuraUnit
|
|
where T2 : struct, IMensuraUnit<T2>, IEquatable<T2>, IMensuraUnit
|
|
where TResult : struct, IMensuraUnit<TResult>, IEquatable<TResult>, IMensuraUnit
|
|
=> r.ToDouble() * b.ToDouble() / a.ToDouble();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public readonly partial record struct Length
|
|
{
|
|
[OperatorsGenerator] public static Area operator *(Length left, Length right) => new(left._Value * right._Value);
|
|
|
|
|
|
public static Volume operator *(Area left, Length right) => right * left;
|
|
[OperatorsGenerator] public static Volume operator *(Length left, Area right) => new(left._Value * right._Value);
|
|
|
|
|
|
public static Pressure operator *(Length left, ForceVolumetric right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Pressure operator *(ForceVolumetric left, Length right) => new(left._Value * right._Value * Coeff1);
|
|
public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(ForceVolumetric.NewtonPerMeterCubic, Length.Meter, Pressure.NewtonPerMeterSquared);
|
|
|
|
|
|
public static Torque operator *(Force left, Length right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff2))] public static Torque operator *(Length left, Force right) => new(left._Value * right._Value * Coeff2);
|
|
public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Length.Meter, Force._Newton, Torque._Newton_Meter);
|
|
}
|
|
|
|
public readonly partial record struct Mass // Grams
|
|
{
|
|
|
|
}
|
|
|
|
public readonly partial record struct Pressure // Pascals
|
|
{
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Length operator /(Pressure left, ForceVolumetric right) => new(left._Value * Coeff1 / right._Value);
|
|
public static readonly double Coeff1 = Coefficients.DivideCoefficient(Pressure._Pascal, ForceVolumetric.NewtonPerMeterCubic, Length.Meter);
|
|
|
|
public static Force operator *(Pressure left, Area right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff2))] public static Force operator *(Area left, Pressure right) => new (left._Value * right._Value * Coeff2);
|
|
public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Area.MeterSquared, Pressure._Pascal, Force._Newton);
|
|
|
|
|
|
|
|
[OperatorsGenerator(nameof(Coeff3))] public static Length operator /(ForceLinear left, Pressure right) => new(left._Value * Coeff3 / right._Value);
|
|
public static readonly double Coeff3 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, Pressure.NewtonPerMilliMeterSquared, Length._MilliMeter);
|
|
|
|
public static ForceLinear operator *(Pressure left, Length right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff4))] public static ForceLinear operator *(Length left, Pressure right) => new(left._Value * right._Value * Coeff4);
|
|
public static readonly double Coeff4 = Coefficients.MultiplyCoefficient(Length._MilliMeter, Pressure.NewtonPerMilliMeterSquared, ForceLinear._NewtonPerMilliMeter);
|
|
}
|
|
|
|
public readonly partial record struct Area // MilliMetersSquared
|
|
{
|
|
public static Torque operator *(ForceLinear left, Area right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Torque operator *(Area left, ForceLinear right) => new(left._Value * right._Value * Coeff1);
|
|
public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Area.MeterSquared, ForceLinear.NewtonPerMeter, Torque._Newton_Meter);
|
|
|
|
[OperatorsGenerator] public static Length operator /(Area left, Length right) => new(left._Value / right._Value);
|
|
}
|
|
|
|
public readonly partial record struct Volume // MillimetersCubic
|
|
{
|
|
public static Torque operator *(Pressure left, Volume right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff2))] public static Torque operator *(Volume left, Pressure right) => new(left._Value * right._Value * Coeff2);
|
|
public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Volume.MeterCubic, Pressure._Pascal, Torque._Newton_Meter);
|
|
|
|
[OperatorsGenerator] public static Area operator /(Volume left, Length right) => new(left._Value / right._Value);
|
|
[OperatorsGenerator] public static Length operator /(Volume left, Area right) => new(left._Value / right._Value);
|
|
}
|
|
|
|
public readonly partial record struct Force // Newtons
|
|
{
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Area operator /(Force left, Pressure right) => new(left._Value * Coeff1 / right._Value);
|
|
public static readonly double Coeff1 = Coefficients.DivideCoefficient(Force._Newton, Pressure._Pascal, Area.MeterSquared);
|
|
[OperatorsGenerator(nameof(Coeff2))] public static Pressure operator /(Force left, Area right) => new(left._Value * Coeff2 / right._Value);
|
|
public static readonly double Coeff2 = Coefficients.DivideCoefficient(Force._Newton, Area.MeterSquared, Pressure._Pascal);
|
|
|
|
}
|
|
|
|
public readonly partial record struct Torque // NewtonMeters
|
|
{
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Length operator /(Torque left, Force right) => new(left._Value * Coeff1 / right._Value);
|
|
public static readonly double Coeff1 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Force._Newton, Length.Meter);
|
|
[OperatorsGenerator(nameof(Coeff2))] public static Force operator /(Torque left, Length right) => new(left._Value * Coeff2 / right._Value);
|
|
public static readonly double Coeff2 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Length.Meter, Force._Newton);
|
|
[OperatorsGenerator(nameof(Coeff3))] public static ForceLinear operator /(Torque left, Area right) => new(left._Value * Coeff3 / right._Value);
|
|
public static readonly double Coeff3 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Area._MilliMeterSquared, ForceLinear.KiloNewtonPerMilliMeter );
|
|
[OperatorsGenerator(nameof(Coeff4))] public static Pressure operator /(Torque left, Volume right) => new(left._Value * Coeff4 / right._Value);
|
|
public static readonly double Coeff4 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Volume.MeterCubic, Pressure._Pascal);
|
|
[OperatorsGenerator(nameof(Coeff5))] public static Volume operator /(Torque left, Pressure right) => new(left._Value * Coeff5 / right._Value);
|
|
public static readonly double Coeff5 = Coefficients.DivideCoefficient(Torque._Newton_Meter, Pressure._Pascal, Volume.MeterCubic);
|
|
}
|
|
|
|
public readonly partial record struct Frequency // Hertz
|
|
{
|
|
|
|
}
|
|
|
|
public readonly partial record struct Time
|
|
{
|
|
public static Speed operator *(Boost left, Time right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Speed operator *(Time left, Boost right) => new(left._Value * right._Value * Coeff1);
|
|
public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Boost._MeterPerSecondSquared, Speed.MeterPerSecond);
|
|
|
|
[OperatorsGenerator(nameof(Coeff2))] public static Speed operator /(Length left, Time right) => new(left._Value * Coeff2 / right._Value);
|
|
public static readonly double Coeff2 = Coefficients.DivideCoefficient(Length.Meter, Time.Second, Speed.MeterPerSecond);
|
|
}
|
|
|
|
public readonly partial record struct Speed
|
|
{
|
|
public static Length operator *(Speed left, Time right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Length operator *(Time left, Speed right) => new(left._Value * right._Value * Coeff1);
|
|
public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Time.Second, Speed.MeterPerSecond, Length.Meter);
|
|
|
|
[OperatorsGenerator(nameof(Coeff2))] public static Boost operator /(Speed left, Time right) => new(left._Value * Coeff2 / right._Value);
|
|
public static readonly double Coeff2 = Coefficients.DivideCoefficient(Speed.MeterPerSecond, Time.Second, Boost._MeterPerSecondSquared);
|
|
}
|
|
|
|
public readonly partial record struct Boost
|
|
{
|
|
public static Force operator *(Mass left, Boost right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Force operator *(Boost left, Mass right) => new(left._Value * right._Value * Coeff1);
|
|
public static readonly double Coeff1 = Coefficients.MultiplyCoefficient(Boost._MeterPerSecondSquared, Mass.KiloGram, Force._Newton);
|
|
|
|
public static ForceLinear operator *(MassLinear left, Boost right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff2))] public static ForceLinear operator *(Boost left, MassLinear right) => new(left._Value * right._Value * Coeff2);
|
|
public static readonly double Coeff2 = Coefficients.MultiplyCoefficient(Boost._MeterPerSecondSquared, MassLinear.KiloGramPerMilliMeter, ForceLinear._NewtonPerMilliMeter);
|
|
|
|
public static ForceVolumetric operator *(Density left, Boost right) => right * left;
|
|
[OperatorsGenerator(nameof(Coeff3))] public static ForceVolumetric operator *(Boost left, Density right) => new(left._Value * right._Value * Coeff3);
|
|
public static readonly double Coeff3 = Coefficients.MultiplyCoefficient(Boost._MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic, ForceVolumetric._NewtonPerMilliMeterCubic);
|
|
|
|
|
|
[OperatorsGenerator(nameof(Coeff4))] public static MassLinear operator /(ForceLinear left, Boost right) => new(left._Value * Coeff4 / right._Value);
|
|
public static readonly double Coeff4 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, Boost._MeterPerSecondSquared, MassLinear.KiloGramPerMilliMeter);
|
|
|
|
[OperatorsGenerator(nameof(Coeff5))] public static Density operator /(ForceVolumetric left, Boost right) => new(left._Value * Coeff5 / right._Value);
|
|
public static readonly double Coeff5 = Coefficients.DivideCoefficient(ForceVolumetric._NewtonPerMilliMeterCubic, Boost._MeterPerSecondSquared, Density.KiloGramPerMilliMeterCubic);
|
|
|
|
|
|
[OperatorsGenerator] public static MassPerSquare operator /(Pressure left, Boost right) => new(left._Value / right._Value);
|
|
}
|
|
|
|
public readonly partial record struct MassPerSquare
|
|
{
|
|
public static Pressure operator *(Boost left, MassPerSquare right) => right * left;
|
|
[OperatorsGenerator] public static Pressure operator *(MassPerSquare left, Boost right) => new(left._Value * right._Value);
|
|
}
|
|
|
|
|
|
public readonly partial record struct MassLinear
|
|
{
|
|
[OperatorsGenerator(nameof(Coeff1))] public static Boost operator /(ForceLinear left, MassLinear right) => new(left._Value * Coeff1 / right._Value);
|
|
|
|
public static readonly double Coeff1 = Coefficients.DivideCoefficient(ForceLinear._NewtonPerMilliMeter, MassLinear.KiloGramPerMilliMeter, Boost._MeterPerSecondSquared);
|
|
} |