namespace NucuCar.Sensors.Environment.Bmxx80.Units
{
public struct Temperature
{
private const double KelvinOffset = 273.15;
private const double FahrenheitOffset = 32.0;
private const double FahrenheitRatio = 1.8;
private double _celsius;
private Temperature(double celsius)
{
_celsius = celsius;
}
///
/// Temperature in Celsius
///
public double Celsius => _celsius;
///
/// Temperature in Fahrenheit
///
public double Fahrenheit => FahrenheitRatio * _celsius + FahrenheitOffset;
///
/// Temperature in Kelvin
///
public double Kelvin => _celsius + KelvinOffset;
///
/// Creates Temperature instance from temperature in Celsius
///
/// Temperature value in Celsius
/// Temperature instance
public static Temperature FromCelsius(double value)
{
return new Temperature(value);
}
///
/// Creates Temperature instance from temperature in Fahrenheit
///
/// Temperature value in Fahrenheit
/// Temperature instance
public static Temperature FromFahrenheit(double value)
{
return new Temperature((value - FahrenheitOffset) / FahrenheitRatio);
}
///
/// Creates Temperature instance from temperature in Kelvin
///
/// Temperature value in Kelvin
/// Temperature instance
public static Temperature FromKelvin(double value)
{
return new Temperature(value - KelvinOffset);
}
}
}