forked from angularsen/UnitsNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecificFuelConsumption.g.cs
More file actions
196 lines (164 loc) · 9.56 KB
/
Copy pathSpecificFuelConsumption.g.cs
File metadata and controls
196 lines (164 loc) · 9.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by \generate-code.bat.
//
// Changes to this file will be lost when the code is regenerated.
// The build server regenerates the code before each build and a pre-build
// step will regenerate the code on each local build.
//
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
//
// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities.
//
// </auto-generated>
//------------------------------------------------------------------------------
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.
using System;
using UnitsNet.Units;
namespace UnitsNet
{
/// <inheritdoc />
/// <summary>
/// SFC is the fuel efficiency of an engine design with respect to thrust output
/// </summary>
/// <remarks>
/// https://en.wikipedia.org/wiki/Thrust-specific_fuel_consumption
/// </remarks>
public struct SpecificFuelConsumption
{
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
private readonly double _value;
/// <summary>
/// The unit this quantity was constructed with.
/// </summary>
private readonly SpecificFuelConsumptionUnit _unit;
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
public double Value => _value;
/// <inheritdoc />
public SpecificFuelConsumptionUnit Unit => _unit;
/// <summary>
/// Creates the quantity with the given numeric value and unit.
/// </summary>
/// <param name="value">The numeric value to construct this quantity with.</param>
/// <param name="unit">The unit representation to construct this quantity with.</param>
public SpecificFuelConsumption(double value, SpecificFuelConsumptionUnit unit)
{
_value = value;
_unit = unit;
}
/// <summary>
/// The base unit of SpecificFuelConsumption, which is Second. All conversions go via this value.
/// </summary>
public static SpecificFuelConsumptionUnit BaseUnit { get; } = SpecificFuelConsumptionUnit.GramPerKilonewtonSecond;
/// <summary>
/// Represents the largest possible value of SpecificFuelConsumption.
/// </summary>
public static SpecificFuelConsumption MaxValue { get; } = new SpecificFuelConsumption(double.MaxValue, BaseUnit);
/// <summary>
/// Represents the smallest possible value of SpecificFuelConsumption.
/// </summary>
public static SpecificFuelConsumption MinValue { get; } = new SpecificFuelConsumption(double.MinValue, BaseUnit);
/// <summary>
/// Gets an instance of this quantity with a value of 0 in the base unit Second.
/// </summary>
public static SpecificFuelConsumption Zero { get; } = new SpecificFuelConsumption(0, BaseUnit);
#region Conversion Properties
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="SpecificFuelConsumptionUnit.GramPerKilonewtonSecond"/>
/// </summary>
public double GramsPerKilonewtonSecond => As(SpecificFuelConsumptionUnit.GramPerKilonewtonSecond);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour"/>
/// </summary>
public double KilogramsPerKilogramForceHour => As(SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond"/>
/// </summary>
public double KilogramsPerKilonewtonSecond => As(SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour"/>
/// </summary>
public double PoundsMassPerPoundForceHour => As(SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour);
#endregion
#region Static Factory Methods
/// <summary>
/// Creates a <see cref="SpecificFuelConsumption"/> from <see cref="SpecificFuelConsumptionUnit.GramPerKilonewtonSecond"/>.
/// </summary>
public static SpecificFuelConsumption FromGramsPerKilonewtonSecond(double gramsperkilonewtonsecond) => new SpecificFuelConsumption(gramsperkilonewtonsecond, SpecificFuelConsumptionUnit.GramPerKilonewtonSecond);
/// <summary>
/// Creates a <see cref="SpecificFuelConsumption"/> from <see cref="SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour"/>.
/// </summary>
public static SpecificFuelConsumption FromKilogramsPerKilogramForceHour(double kilogramsperkilogramforcehour) => new SpecificFuelConsumption(kilogramsperkilogramforcehour, SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour);
/// <summary>
/// Creates a <see cref="SpecificFuelConsumption"/> from <see cref="SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond"/>.
/// </summary>
public static SpecificFuelConsumption FromKilogramsPerKilonewtonSecond(double kilogramsperkilonewtonsecond) => new SpecificFuelConsumption(kilogramsperkilonewtonsecond, SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond);
/// <summary>
/// Creates a <see cref="SpecificFuelConsumption"/> from <see cref="SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour"/>.
/// </summary>
public static SpecificFuelConsumption FromPoundsMassPerPoundForceHour(double poundsmassperpoundforcehour) => new SpecificFuelConsumption(poundsmassperpoundforcehour, SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour);
/// <summary>
/// Dynamically convert from value and unit enum <see cref="SpecificFuelConsumptionUnit" /> to <see cref="SpecificFuelConsumption" />.
/// </summary>
/// <param name="value">Value to convert from.</param>
/// <param name="fromUnit">Unit to convert from.</param>
/// <returns>SpecificFuelConsumption unit value.</returns>
public static SpecificFuelConsumption From(double value, SpecificFuelConsumptionUnit fromUnit)
{
return new SpecificFuelConsumption(value, fromUnit);
}
#endregion
#region Conversion Methods
/// <summary>
/// Convert to the unit representation <paramref name="unit" />.
/// </summary>
/// <returns>Value converted to the specified unit.</returns>
public double As(SpecificFuelConsumptionUnit unit) => GetValueAs(unit);
/// <summary>
/// Converts this SpecificFuelConsumption to another SpecificFuelConsumption with the unit representation <paramref name="unit" />.
/// </summary>
/// <returns>A SpecificFuelConsumption with the specified unit.</returns>
public SpecificFuelConsumption ToUnit(SpecificFuelConsumptionUnit unit)
{
var convertedValue = GetValueAs(unit);
return new SpecificFuelConsumption(convertedValue, unit);
}
/// <summary>
/// Converts the current value + unit to the base unit.
/// This is typically the first step in converting from one unit to another.
/// </summary>
/// <returns>The value in the base unit representation.</returns>
private double GetValueInBaseUnit()
{
return Unit switch
{
SpecificFuelConsumptionUnit.GramPerKilonewtonSecond => _value,
SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour => _value * 28.33,
SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond => (_value) * 1e3d,
SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour => _value * 28.33,
_ => throw new NotImplementedException($"Can not convert {Unit} to base units.")
};
}
private double GetValueAs(SpecificFuelConsumptionUnit unit)
{
if (Unit == unit)
return _value;
var baseUnitValue = GetValueInBaseUnit();
return unit switch
{
SpecificFuelConsumptionUnit.GramPerKilonewtonSecond => baseUnitValue,
SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour => baseUnitValue / 28.33,
SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond => (baseUnitValue) / 1e3d,
SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour => baseUnitValue / 28.33,
_ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.")
};
}
#endregion
}
}