-
Notifications
You must be signed in to change notification settings - Fork 407
Expand file tree
/
Copy pathAreaDensity.g.cs
More file actions
205 lines (171 loc) · 9.31 KB
/
AreaDensity.g.cs
File metadata and controls
205 lines (171 loc) · 9.31 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
196
197
198
199
200
201
202
203
204
//------------------------------------------------------------------------------
// <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>
/// The area density of a two-dimensional object is calculated as the mass per unit area. For paper this is also called grammage.
/// </summary>
public struct AreaDensity
{
/// <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 AreaDensityUnit _unit;
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
public double Value => _value;
/// <inheritdoc />
public AreaDensityUnit 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 AreaDensity(double value, AreaDensityUnit unit)
{
_value = value;
_unit = unit;
}
/// <summary>
/// The base unit of AreaDensity, which is Second. All conversions go via this value.
/// </summary>
public static AreaDensityUnit BaseUnit { get; } = AreaDensityUnit.KilogramPerSquareMeter;
/// <summary>
/// Represents the largest possible value of AreaDensity.
/// </summary>
public static AreaDensity MaxValue { get; } = new AreaDensity(double.MaxValue, BaseUnit);
/// <summary>
/// Represents the smallest possible value of AreaDensity.
/// </summary>
public static AreaDensity MinValue { get; } = new AreaDensity(double.MinValue, BaseUnit);
/// <summary>
/// Gets an instance of this quantity with a value of 0 in the base unit Second.
/// </summary>
public static AreaDensity Zero { get; } = new AreaDensity(0, BaseUnit);
#region Conversion Properties
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaDensityUnit.GramPerSquareMeter"/>
/// </summary>
public double GramsPerSquareMeter => As(AreaDensityUnit.GramPerSquareMeter);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaDensityUnit.KilogramPerSquareMeter"/>
/// </summary>
public double KilogramsPerSquareMeter => As(AreaDensityUnit.KilogramPerSquareMeter);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaDensityUnit.MilligramPerSquareMeter"/>
/// </summary>
public double MilligramsPerSquareMeter => As(AreaDensityUnit.MilligramPerSquareMeter);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaDensityUnit.PoundPerSquareFoot"/>
/// </summary>
public double PoundPerSquareFoot => As(AreaDensityUnit.PoundPerSquareFoot);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaDensityUnit.PoundPerThousandSquareFeet"/>
/// </summary>
public double PoundPerThousandSquareFeet => As(AreaDensityUnit.PoundPerThousandSquareFeet);
#endregion
#region Static Factory Methods
/// <summary>
/// Creates a <see cref="AreaDensity"/> from <see cref="AreaDensityUnit.GramPerSquareMeter"/>.
/// </summary>
public static AreaDensity FromGramsPerSquareMeter(double gramspersquaremeter) => new AreaDensity(gramspersquaremeter, AreaDensityUnit.GramPerSquareMeter);
/// <summary>
/// Creates a <see cref="AreaDensity"/> from <see cref="AreaDensityUnit.KilogramPerSquareMeter"/>.
/// </summary>
public static AreaDensity FromKilogramsPerSquareMeter(double kilogramspersquaremeter) => new AreaDensity(kilogramspersquaremeter, AreaDensityUnit.KilogramPerSquareMeter);
/// <summary>
/// Creates a <see cref="AreaDensity"/> from <see cref="AreaDensityUnit.MilligramPerSquareMeter"/>.
/// </summary>
public static AreaDensity FromMilligramsPerSquareMeter(double milligramspersquaremeter) => new AreaDensity(milligramspersquaremeter, AreaDensityUnit.MilligramPerSquareMeter);
/// <summary>
/// Creates a <see cref="AreaDensity"/> from <see cref="AreaDensityUnit.PoundPerSquareFoot"/>.
/// </summary>
public static AreaDensity FromPoundPerSquareFoot(double poundpersquarefoot) => new AreaDensity(poundpersquarefoot, AreaDensityUnit.PoundPerSquareFoot);
/// <summary>
/// Creates a <see cref="AreaDensity"/> from <see cref="AreaDensityUnit.PoundPerThousandSquareFeet"/>.
/// </summary>
public static AreaDensity FromPoundPerThousandSquareFeet(double poundperthousandsquarefeet) => new AreaDensity(poundperthousandsquarefeet, AreaDensityUnit.PoundPerThousandSquareFeet);
/// <summary>
/// Dynamically convert from value and unit enum <see cref="AreaDensityUnit" /> to <see cref="AreaDensity" />.
/// </summary>
/// <param name="value">Value to convert from.</param>
/// <param name="fromUnit">Unit to convert from.</param>
/// <returns>AreaDensity unit value.</returns>
public static AreaDensity From(double value, AreaDensityUnit fromUnit)
{
return new AreaDensity(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(AreaDensityUnit unit) => GetValueAs(unit);
/// <summary>
/// Converts this AreaDensity to another AreaDensity with the unit representation <paramref name="unit" />.
/// </summary>
/// <returns>A AreaDensity with the specified unit.</returns>
public AreaDensity ToUnit(AreaDensityUnit unit)
{
var convertedValue = GetValueAs(unit);
return new AreaDensity(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
{
AreaDensityUnit.GramPerSquareMeter => _value / 1000,
AreaDensityUnit.KilogramPerSquareMeter => _value,
AreaDensityUnit.MilligramPerSquareMeter => _value / 1000000,
AreaDensityUnit.PoundPerSquareFoot => _value * 4.8824,
AreaDensityUnit.PoundPerThousandSquareFeet => _value * 4.8824 / 1000,
_ => throw new NotImplementedException($"Can't convert {Unit} to base units.")
};
}
private double GetValueAs(AreaDensityUnit unit)
{
if (Unit == unit)
return _value;
var baseUnitValue = GetValueInBaseUnit();
return unit switch
{
AreaDensityUnit.GramPerSquareMeter => baseUnitValue * 1000,
AreaDensityUnit.KilogramPerSquareMeter => baseUnitValue,
AreaDensityUnit.MilligramPerSquareMeter => baseUnitValue * 1000000,
AreaDensityUnit.PoundPerSquareFoot => baseUnitValue / 4.8824,
AreaDensityUnit.PoundPerThousandSquareFeet => baseUnitValue / 4.8824 * 1000,
_ => throw new NotImplementedException($"Can't convert {Unit} to {unit}.")
};
}
#endregion
}
}