-
Notifications
You must be signed in to change notification settings - Fork 407
Expand file tree
/
Copy pathFlatness.g.cs
More file actions
169 lines (141 loc) · 6.63 KB
/
Flatness.g.cs
File metadata and controls
169 lines (141 loc) · 6.63 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
//------------------------------------------------------------------------------
// <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>
/// Flatness is a measurement for the deviation of a surface from a perfectly flat surface.
/// </summary>
public struct Flatness
{
/// <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 FlatnessUnit _unit;
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
public double Value => _value;
/// <inheritdoc />
public FlatnessUnit 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 Flatness(double value, FlatnessUnit unit)
{
_value = value;
_unit = unit;
}
/// <summary>
/// The base unit of Flatness, which is Second. All conversions go via this value.
/// </summary>
public static FlatnessUnit BaseUnit { get; } = FlatnessUnit.IUnit;
/// <summary>
/// Represents the largest possible value of Flatness.
/// </summary>
public static Flatness MaxValue { get; } = new Flatness(double.MaxValue, BaseUnit);
/// <summary>
/// Represents the smallest possible value of Flatness.
/// </summary>
public static Flatness MinValue { get; } = new Flatness(double.MinValue, BaseUnit);
/// <summary>
/// Gets an instance of this quantity with a value of 0 in the base unit Second.
/// </summary>
public static Flatness Zero { get; } = new Flatness(0, BaseUnit);
#region Conversion Properties
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="FlatnessUnit.IUnit"/>
/// </summary>
public double IUnits => As(FlatnessUnit.IUnit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="FlatnessUnit.MicrometerPerMeter"/>
/// </summary>
public double MicrometersPerMeter => As(FlatnessUnit.MicrometerPerMeter);
#endregion
#region Static Factory Methods
/// <summary>
/// Creates a <see cref="Flatness"/> from <see cref="FlatnessUnit.IUnit"/>.
/// </summary>
public static Flatness FromIUnits(double iunits) => new Flatness(iunits, FlatnessUnit.IUnit);
/// <summary>
/// Creates a <see cref="Flatness"/> from <see cref="FlatnessUnit.MicrometerPerMeter"/>.
/// </summary>
public static Flatness FromMicrometersPerMeter(double micrometerspermeter) => new Flatness(micrometerspermeter, FlatnessUnit.MicrometerPerMeter);
/// <summary>
/// Dynamically convert from value and unit enum <see cref="FlatnessUnit" /> to <see cref="Flatness" />.
/// </summary>
/// <param name="value">Value to convert from.</param>
/// <param name="fromUnit">Unit to convert from.</param>
/// <returns>Flatness unit value.</returns>
public static Flatness From(double value, FlatnessUnit fromUnit)
{
return new Flatness(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(FlatnessUnit unit) => GetValueAs(unit);
/// <summary>
/// Converts this Flatness to another Flatness with the unit representation <paramref name="unit" />.
/// </summary>
/// <returns>A Flatness with the specified unit.</returns>
public Flatness ToUnit(FlatnessUnit unit)
{
var convertedValue = GetValueAs(unit);
return new Flatness(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
{
FlatnessUnit.IUnit => _value,
FlatnessUnit.MicrometerPerMeter => _value / 1e1,
_ => throw new NotImplementedException($"Can't convert {Unit} to base units.")
};
}
private double GetValueAs(FlatnessUnit unit)
{
if (Unit == unit)
return _value;
var baseUnitValue = GetValueInBaseUnit();
return unit switch
{
FlatnessUnit.IUnit => baseUnitValue,
FlatnessUnit.MicrometerPerMeter => baseUnitValue * 1e1,
_ => throw new NotImplementedException($"Can't convert {Unit} to {unit}.")
};
}
#endregion
}
}