From f044457d296536a0db639d6148dff59e9bb66e1d Mon Sep 17 00:00:00 2001 From: Branden Gunn Date: Fri, 29 Dec 2023 23:45:48 -0500 Subject: [PATCH 1/7] cleanup --- Source/Meadow.Units/Illuminance.cs | 2 +- Source/Meadow.Units/Length.cs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Meadow.Units/Illuminance.cs b/Source/Meadow.Units/Illuminance.cs index adb894e..d8cc85e 100644 --- a/Source/Meadow.Units/Illuminance.cs +++ b/Source/Meadow.Units/Illuminance.cs @@ -21,7 +21,7 @@ public struct Illuminance : /// Creates a new `Illuminance` object. /// /// The Illuminance value. - /// kilometers meters per second by default. + /// Lux by default. public Illuminance(double value, UnitType type = UnitType.Lux) { Value = IlluminanceConversions.Convert(value, type, UnitType.Lux); diff --git a/Source/Meadow.Units/Length.cs b/Source/Meadow.Units/Length.cs index 21f424d..e76b3aa 100644 --- a/Source/Meadow.Units/Length.cs +++ b/Source/Meadow.Units/Length.cs @@ -157,8 +157,7 @@ public enum UnitType /// /// unit to covert to /// the converted value - [Pure] - public readonly double From(UnitType convertTo) + [Pure] public readonly double From(UnitType convertTo) { return LengthConversions.Convert(Value, UnitType.Meters, convertTo); } @@ -168,8 +167,7 @@ public readonly double From(UnitType convertTo) /// /// The object to compare /// true if equal - [Pure] - public override readonly bool Equals(object obj) + [Pure] public override readonly bool Equals(object obj) { if (obj is null) { return false; } if (Equals(this, obj)) { return true; } From c1ae64e93564d402f4e8e983f6041c917c2ff93f Mon Sep 17 00:00:00 2001 From: Branden Gunn Date: Mon, 29 Jan 2024 01:17:25 -0500 Subject: [PATCH 2/7] Add Nanovolts --- .../Conversions/VoltageConversions.cs | 1 + Source/Meadow.Units/Voltage.cs | 62 ++++++------------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/Source/Meadow.Units/Conversions/VoltageConversions.cs b/Source/Meadow.Units/Conversions/VoltageConversions.cs index b10e23b..6a0a16a 100644 --- a/Source/Meadow.Units/Conversions/VoltageConversions.cs +++ b/Source/Meadow.Units/Conversions/VoltageConversions.cs @@ -20,6 +20,7 @@ public static double Convert(double value, Voltage.UnitType from, Voltage.UnitTy 0.000001, //Megavolts 0.000000001, //Gigavolts 299.792458, //Statvolts + 1000000000, //Nanovolts }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Voltage.cs b/Source/Meadow.Units/Voltage.cs index 26cda77..91100c4 100644 --- a/Source/Meadow.Units/Voltage.cs +++ b/Source/Meadow.Units/Voltage.cs @@ -58,64 +58,40 @@ public Voltage(Voltage voltage) /// public enum UnitType { - /// - /// Volts - /// + /// Volts Volts, - /// - /// Millivolts - /// + /// Millivolts Millivolts, - /// - /// Microvolts - /// + /// Microvolts Microvolts, - /// - /// Kilovolts - /// + /// Kilovolts Kilovolts, - /// - /// Megavolts - /// + /// Megavolts Megavolts, - /// - /// Gigavolts - /// + /// Gigavolts Gigavolts, - /// - /// Statvolts - /// - Statvolts + /// Statvolts + Statvolts, + /// Nanovolts + Nanovolts, } - /// - /// Get voltage in volts - /// + /// Get voltage in volts public double Volts => From(UnitType.Volts); - /// - /// Get voltage in millivolts - /// + /// Get voltage in millivolts public double Millivolts => From(UnitType.Millivolts); - /// - /// Get voltage in microvolts - /// + /// Get voltage in microvolts public double Microvolts => From(UnitType.Microvolts); - /// - /// Get voltage in kilovolts - /// + /// Get voltage in kilovolts public double Kilovolts => From(UnitType.Kilovolts); - /// - /// Get voltage in megavolts - /// + /// Get voltage in megavolts public double Megavolts => From(UnitType.Megavolts); - /// - /// Get voltage in gigavolts - /// + /// Get voltage in gigavolts public double Gigavolts => From(UnitType.Gigavolts); - /// - /// Get voltage in statvolts - /// + /// Get voltage in statvolts public double Statvolts => From(UnitType.Statvolts); + /// Get voltage in nanovolts + public double Nanovolts => From(UnitType.Nanovolts); /// /// Get a double value for a specific unit From 122053bc1902296563aa4fba6ce5f0c7af205baf Mon Sep 17 00:00:00 2001 From: Branden Gunn Date: Mon, 29 Jan 2024 01:17:36 -0500 Subject: [PATCH 3/7] Add Charge --- Source/Meadow.Units/Charge.cs | 356 ++++++++++++++++++++++++++++++++++ 1 file changed, 356 insertions(+) create mode 100644 Source/Meadow.Units/Charge.cs diff --git a/Source/Meadow.Units/Charge.cs b/Source/Meadow.Units/Charge.cs new file mode 100644 index 0000000..ea729e7 --- /dev/null +++ b/Source/Meadow.Units/Charge.cs @@ -0,0 +1,356 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.Contracts; +using System.Runtime.InteropServices; + +namespace Meadow.Units +{ + /// + /// Represents a value of Electric Charge. + /// + [Serializable] + [ImmutableObject(true)] + [StructLayout(LayoutKind.Sequential)] + public struct Charge : + IComparable, IFormattable, IConvertible, + IEquatable, IComparable + { + /// + /// Creates a new `Charge` object. + /// + /// The Charge value. + /// Coulombs by default. + public Charge(double value, UnitType type = UnitType.Coulombs) + { + Coulombs = value; + } + + /// + /// Creates a new `Charge` object from an existing Charge object + /// + /// + public Charge(Charge Charge) + { + Coulombs = Charge.Coulombs; + } + + /// + /// The Charge in coulombs + /// + public double Coulombs { get; private set; } + + /// + /// The type of units available to describe the Charge. + /// + public enum UnitType + { + /// + /// coulombs + /// + Coulombs + } + + /// + /// Compare to another Charge object + /// + /// The object to compare + /// true if equal + [Pure] public override bool Equals(object obj) + { + if (obj is null) { return false; } + if (Equals(this, obj)) { return true; } + return obj.GetType() == GetType() && Equals((Charge)obj); + } + + /// + /// Get hash of object + /// + /// int32 hash value + [Pure] public override int GetHashCode() => Coulombs.GetHashCode(); + + // implicit conversions + //[Pure] public static implicit operator Charge(ushort value) => new Charge(value); + //[Pure] public static implicit operator Charge(short value) => new Charge(value); + //[Pure] public static implicit operator Charge(uint value) => new Charge(value); + //[Pure] public static implicit operator Charge(long value) => new Charge(value); + //[Pure] public static implicit operator Charge(int value) => new Charge(value); + //[Pure] public static implicit operator Charge(float value) => new Charge(value); + //[Pure] public static implicit operator Charge(double value) => new Charge(value); + //[Pure] public static implicit operator Charge(decimal value) => new Charge((double)value); + + // Comparison + /// + /// Compare to another Charge object + /// + /// The object to compare + /// true if equal + [Pure] public bool Equals(Charge other) => Coulombs == other.Coulombs; + + /// + /// Equals operator to compare two Charge objects + /// + /// left value + /// right value + /// true if equal + [Pure] public static bool operator ==(Charge left, Charge right) => Equals(left.Coulombs, right.Coulombs); + + /// + /// Not equals operator to compare two Charge objects + /// + /// left value + /// right value + /// true if not equal + [Pure] public static bool operator !=(Charge left, Charge right) => !Equals(left.Coulombs, right.Coulombs); + + /// + /// Compare to another Charge object + /// + /// + /// 0 if equal + [Pure] public int CompareTo(Charge other) => Equals(Coulombs, other.Coulombs) ? 0 : Coulombs.CompareTo(other.Coulombs); + + /// + /// Less than operator to compare two Charge objects + /// + /// left value + /// right value + /// true if left is less than right + [Pure] public static bool operator <(Charge left, Charge right) => Comparer.Default.Compare(left.Coulombs, right.Coulombs) < 0; + + /// + /// Greater than operator to compare two Charge objects + /// + /// left value + /// right value + /// true if left is greater than right + [Pure] public static bool operator >(Charge left, Charge right) => Comparer.Default.Compare(left.Coulombs, right.Coulombs) > 0; + + /// + /// Less than or equal operator to compare two Charge objects + /// + /// left value + /// right value + /// true if left is less than or equal to right + [Pure] public static bool operator <=(Charge left, Charge right) => Comparer.Default.Compare(left.Coulombs, right.Coulombs) <= 0; + + /// + /// Greater than or equal operator to compare two Charge objects + /// + /// left value + /// right value + /// true if left is greater than or equal to right + [Pure] public static bool operator >=(Charge left, Charge right) => Comparer.Default.Compare(left.Coulombs, right.Coulombs) >= 0; + + // Math + /// + /// Addition operator to add two Charge objects + /// + /// left value + /// right value + /// A new Charge object with a value of left + right + [Pure] public static Charge operator +(Charge left, Charge right) => new (left.Coulombs + right.Coulombs); + + /// + /// Subtraction operator to subtract two Charge objects + /// + /// left value + /// right value + /// A new Charge object with a value of left - right + [Pure] public static Charge operator -(Charge left, Charge right) => new (left.Coulombs - right.Coulombs); + + /// + /// Multiplication operator to multiply by a double + /// + /// object to multiply + /// operand to multiply object + /// A new Charge object with a value of value multiplied by the operand + [Pure] public static Charge operator *(Charge value, double operand) => new (value.Coulombs * operand); + + /// + /// Division operator to divide by a double + /// + /// object to be divided + /// operand to divide object + /// A new Charge object with a value of value divided by the operand + [Pure] public static Charge operator /(Charge value, double operand) => new (value.Coulombs / operand); + + /// + /// Returns the absolute value of the + /// + /// + [Pure] public Charge Abs() { return new Charge(Math.Abs(this.Coulombs)); } + + /// + /// Get a string representation of the object + /// + /// A string representing the object + [Pure] public override string ToString() => Coulombs.ToString(); + + /// + /// Get a string representation of the object + /// + /// format + /// format provider + /// A string representing the object + [Pure] public string ToString(string format, IFormatProvider formatProvider) => Coulombs.ToString(format, formatProvider); + + // IComparable + /// + /// Compare to another Charge object + /// + /// The other Charge cast to object + /// 0 if equal + [Pure] public int CompareTo(object obj) => Coulombs.CompareTo(obj); + + /// + /// Get type code of object + /// + /// The TypeCode + [Pure] public TypeCode GetTypeCode() => Coulombs.GetTypeCode(); + + /// + /// Convert to boolean + /// + /// format provider + /// bool representation of the object + [Pure] public bool ToBoolean(IFormatProvider provider) => ((IConvertible)Coulombs).ToBoolean(provider); + + /// + /// Convert to byte + /// + /// format provider + /// byte representation of the object + [Pure] public byte ToByte(IFormatProvider provider) => ((IConvertible)Coulombs).ToByte(provider); + + /// + /// Convert to char + /// + /// format provider + /// char representation of the object + [Pure] public char ToChar(IFormatProvider provider) => ((IConvertible)Coulombs).ToChar(provider); + + /// + /// Convert to DateTime + /// + /// format provider + /// DateTime representation of the object + [Pure] public DateTime ToDateTime(IFormatProvider provider) => ((IConvertible)Coulombs).ToDateTime(provider); + + /// + /// Convert to Decimal + /// + /// format provider + /// Decimal representation of the object + [Pure] public decimal ToDecimal(IFormatProvider provider) => ((IConvertible)Coulombs).ToDecimal(provider); + + /// + /// Convert to double + /// + /// format provider + /// double representation of the object + [Pure] public double ToDouble(IFormatProvider provider) => Coulombs; + + /// + /// Convert to in16 + /// + /// format provider + /// int16 representation of the object + [Pure] public short ToInt16(IFormatProvider provider) => ((IConvertible)Coulombs).ToInt16(provider); + + /// + /// Convert to int32 + /// + /// format provider + /// int32 representation of the object + [Pure] public int ToInt32(IFormatProvider provider) => ((IConvertible)Coulombs).ToInt32(provider); + + /// + /// Convert to int64 + /// + /// format provider + /// int64 representation of the object + [Pure] public long ToInt64(IFormatProvider provider) => ((IConvertible)Coulombs).ToInt64(provider); + + /// + /// Convert to sbyte + /// + /// format provider + /// sbyte representation of the object + [Pure] public sbyte ToSByte(IFormatProvider provider) => ((IConvertible)Coulombs).ToSByte(provider); + + /// + /// Convert to float + /// + /// format provider + /// float representation of the object + [Pure] public float ToSingle(IFormatProvider provider) => ((IConvertible)Coulombs).ToSingle(provider); + + /// + /// Convert to string + /// + /// format provider + /// string representation of the object + [Pure] public string ToString(IFormatProvider provider) => Coulombs.ToString(provider); + + /// + /// Convert to type + /// + /// conversion unit type + /// format provider + /// type representation of the object + [Pure] public object ToType(Type conversionType, IFormatProvider provider) => ((IConvertible)Coulombs).ToType(conversionType, provider); + + /// + /// Convert to uint16 + /// + /// format provider + /// uint16 representation of the object + [Pure] public ushort ToUInt16(IFormatProvider provider) => ((IConvertible)Coulombs).ToUInt16(provider); + + /// + /// Convert to uint32 + /// + /// format provider + /// uint32 representation of the object + [Pure] public uint ToUInt32(IFormatProvider provider) => ((IConvertible)Coulombs).ToUInt32(provider); + + /// + /// Convert to uint64 + /// + /// format provider + /// uint64 representation of the object + [Pure] public ulong ToUInt64(IFormatProvider provider) => ((IConvertible)Coulombs).ToUInt64(provider); + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public int CompareTo(double? other) + { + return (other is null) ? -1 : (Coulombs).CompareTo(other.Value); + } + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public bool Equals(double? other) => Coulombs.Equals(other); + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public bool Equals(double other) => Coulombs.Equals(other); + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public int CompareTo(double other) => Coulombs.CompareTo(other); + } +} \ No newline at end of file From 31e890a75ebccbd8e9d0378bdd2456e8f99e5ce2 Mon Sep 17 00:00:00 2001 From: Branden Gunn Date: Sun, 11 Feb 2024 21:13:17 -0500 Subject: [PATCH 4/7] typo --- Source/Meadow.Units/Turbidity.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Meadow.Units/Turbidity.cs b/Source/Meadow.Units/Turbidity.cs index a0e0836..6116296 100644 --- a/Source/Meadow.Units/Turbidity.cs +++ b/Source/Meadow.Units/Turbidity.cs @@ -37,9 +37,10 @@ public Turbidity(Turbidity Turbidity) } /// - /// The Turbidity expressed as NeNTUelometric Turbidity Units (NTU) + /// The Turbidity expressed as Nephelometric Turbidity Units (NTU) /// public double NTU { get; private set; } + /// /// The type of units available to describe the Turbidity. /// From f64074c06de9b8bb6a75cc625f763376ccd0725a Mon Sep 17 00:00:00 2001 From: Branden Gunn Date: Wed, 13 Mar 2024 21:18:49 -0400 Subject: [PATCH 5/7] cleanup, namespace syntax --- Source/Meadow.Units/AngularAcceleration3D.cs | 1 - Source/Meadow.Units/AngularVelocity3D.cs | 1 - .../Azimuth16PointCardinalNames.cs | 3 +- Source/Meadow.Units/Current.cs | 793 +++++++++--------- .../Extensions/FrequencyExtensions.cs | 2 +- .../Extensions/LengthExtensions.cs | 2 +- .../Extensions/ResistanceExtensions.cs | 2 +- .../Extensions/TemperatureExtensions.cs | 2 +- .../Extensions/VoltageExtensions.cs | 2 +- Source/Meadow.Units/MagneticField3D.cs | 1 - 10 files changed, 396 insertions(+), 413 deletions(-) diff --git a/Source/Meadow.Units/AngularAcceleration3D.cs b/Source/Meadow.Units/AngularAcceleration3D.cs index c6a8f3c..7a45ab9 100644 --- a/Source/Meadow.Units/AngularAcceleration3D.cs +++ b/Source/Meadow.Units/AngularAcceleration3D.cs @@ -3,7 +3,6 @@ using System.ComponentModel; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; -using Meadow.Units.Conversions; namespace Meadow.Units { diff --git a/Source/Meadow.Units/AngularVelocity3D.cs b/Source/Meadow.Units/AngularVelocity3D.cs index e1ff1fa..f3dfab8 100644 --- a/Source/Meadow.Units/AngularVelocity3D.cs +++ b/Source/Meadow.Units/AngularVelocity3D.cs @@ -3,7 +3,6 @@ using System.ComponentModel; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; -using Meadow.Units.Conversions; namespace Meadow.Units { diff --git a/Source/Meadow.Units/Azimuth16PointCardinalNames.cs b/Source/Meadow.Units/Azimuth16PointCardinalNames.cs index 9d9cef9..0d15ff6 100644 --- a/Source/Meadow.Units/Azimuth16PointCardinalNames.cs +++ b/Source/Meadow.Units/Azimuth16PointCardinalNames.cs @@ -1,5 +1,4 @@ -using System; -namespace Meadow.Units +namespace Meadow.Units { /// /// Cardinal compass directions diff --git a/Source/Meadow.Units/Current.cs b/Source/Meadow.Units/Current.cs index f6df7b2..22efc83 100644 --- a/Source/Meadow.Units/Current.cs +++ b/Source/Meadow.Units/Current.cs @@ -5,413 +5,400 @@ using System.Runtime.InteropServices; using Meadow.Units.Conversions; -namespace Meadow.Units +namespace Meadow.Units; + +/// +/// Represents a value of Electric Current. +/// +[Serializable] +[ImmutableObject(true)] +[StructLayout(LayoutKind.Sequential)] +public struct Current : + IComparable, IFormattable, IConvertible, + IEquatable, IComparable { + private static Current _zero; + + static Current() + { + _zero = new Current(0, UnitType.Amps); + } + + /// + /// Gets a current of 0 Amps + /// + public static Current Zero => _zero; + + /// + /// Creates a new `Current` object. + /// + /// The Current value. + /// Amps by default. + public Current(double value, UnitType type = UnitType.Amps) + { + Value = CurrentConversions.Convert(value, type, UnitType.Amps); + } + + /// + /// Creates a new `Current` object from an existing Current object + /// + /// + public Current(Current Current) + { + Value = Current.Value; + } + + /// + /// Internal canonical value. + /// + private readonly double Value; + /// - /// Represents a value of Electric Current. + /// The type of units available to describe the Current. /// - [Serializable] - [ImmutableObject(true)] - [StructLayout(LayoutKind.Sequential)] - public struct Current : - IComparable, IFormattable, IConvertible, - IEquatable, IComparable + public enum UnitType { - /// - /// Creates a new `Current` object. - /// - /// The Current value. - /// Amps by default. - public Current(double value, UnitType type = UnitType.Amps) - { - Value = CurrentConversions.Convert(value, type, UnitType.Amps); - } - - /// - /// Creates a new `Current` object from an existing Current object - /// - /// - public Current(Current Current) - { - Value = Current.Value; - } - - /// - /// Internal canonical value. - /// - private readonly double Value; - - /// - /// The type of units available to describe the Current. - /// - public enum UnitType - { - /// - /// Amperes - /// - Amps, - /// - /// Milli-amperes - /// - Milliamps, - /// - /// Micro-amperes - /// - Microamps, - /// - /// Kilo-amperes - /// - Kiloamps, - /// - /// Mega-amperes - /// - Megaamps, - /// - /// Giga-amperes - /// - Gigaamps, - } - - /// - /// Get current in amps - /// - public double Amps => From(UnitType.Amps); - - /// - /// Get current in milliamps - /// - public double Milliamps => From(UnitType.Milliamps); - - /// - /// Get current in microamps - /// - public double Microamps => From(UnitType.Microamps); - - /// - /// Get current in kiloamps - /// - public double Kiloamps => From(UnitType.Kiloamps); - - /// - /// Get current in megaamps - /// - public double Megaamps => From(UnitType.Megaamps); - - /// - /// Get current in gigaamps - /// - public double Gigaamps => From(UnitType.Gigaamps); + /// Amperes + Amps, + /// Milli-amperes + Milliamps, + /// Micro-amperes + Microamps, + /// Kilo-amperes + Kiloamps, + /// Mega-amperes + Megaamps, + /// Giga-amperes + Gigaamps, + } + + /// Get current in amps + public double Amps => From(UnitType.Amps); + + /// Get current in milliamps + public double Milliamps => From(UnitType.Milliamps); + + /// Get current in microamps + public double Microamps => From(UnitType.Microamps); + + /// Get current in kiloamps + public double Kiloamps => From(UnitType.Kiloamps); + + /// Get current in megaamps + public double Megaamps => From(UnitType.Megaamps); + + /// Get current in gigaamps + public double Gigaamps => From(UnitType.Gigaamps); - /// - /// Convert to a specific unit - /// - /// the unit to convert to - /// - [Pure] public double From(UnitType convertTo) - { - return CurrentConversions.Convert(Value, Current.UnitType.Amps, convertTo); - } - - /// - /// Compare to another Current object - /// - /// The object to compare - /// true if equal - [Pure] public override bool Equals(object obj) - { - if (obj is null) { return false; } - if (Equals(this, obj)) { return true; } - return obj.GetType() == GetType() && Equals((Current)obj); - } - - /// - /// Get hash of object - /// - /// int32 hash value - [Pure] public override int GetHashCode() => Value.GetHashCode(); - - // implicit conversions - //[Pure] public static implicit operator Current(ushort value) => new Current(value); - //[Pure] public static implicit operator Current(short value) => new Current(value); - //[Pure] public static implicit operator Current(uint value) => new Current(value); - //[Pure] public static implicit operator Current(long value) => new Current(value); - //[Pure] public static implicit operator Current(int value) => new Current(value); - //[Pure] public static implicit operator Current(float value) => new Current(value); - //[Pure] public static implicit operator Current(double value) => new Current(value); - //[Pure] public static implicit operator Current(decimal value) => new Current((double)value); - - // Comparison - /// - /// Compare to another Current object - /// - /// The object to compare - /// true if equal - [Pure] public bool Equals(Current other) => Value == other.Value; - - /// - /// Equals operator to compare two Current objects - /// - /// left value - /// right value - /// true if equal - [Pure] public static bool operator ==(Current left, Current right) => Equals(left.Value, right.Value); - - /// - /// Not equals operator to compare two Current objects - /// - /// left value - /// right value - /// true if not equal - [Pure] public static bool operator !=(Current left, Current right) => !Equals(left.Value, right.Value); - - /// - /// Compare to another Current object - /// - /// - /// 0 if equal - [Pure] public int CompareTo(Current other) => Equals(Value, other.Value) ? 0 : Value.CompareTo(other.Value); - - /// - /// Less than operator to compare two Current objects - /// - /// left value - /// right value - /// true if left is less than right - [Pure] public static bool operator <(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) < 0; - - /// - /// Greater than operator to compare two Current objects - /// - /// left value - /// right value - /// true if left is greater than right - [Pure] public static bool operator >(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) > 0; - - /// - /// Less than or equal operator to compare two Current objects - /// - /// left value - /// right value - /// true if left is less than or equal to right - [Pure] public static bool operator <=(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) <= 0; - - /// - /// Greater than or equal operator to compare two Current objects - /// - /// left value - /// right value - /// true if left is greater than or equal to right - [Pure] public static bool operator >=(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) >= 0; - - // Math - /// - /// Addition operator to add two Current objects - /// - /// left value - /// right value - /// A new Current object with a value of left + right - [Pure] public static Current operator +(Current left, Current right) => new (left.Value + right.Value); - - /// - /// Subtraction operator to subtract two Current objects - /// - /// left value - /// right value - /// A new Current object with a value of left - right - [Pure] public static Current operator -(Current left, Current right) => new (left.Value - right.Value); - - /// - /// Multiplication operator to multiply by a double - /// - /// object to multiply - /// operand to multiply object - /// A new Current object with a value of value multiplied by the operand - [Pure] public static Current operator *(Current value, double operand) => new (value.Value * operand); - - /// - /// Division operator to divide by a double - /// - /// object to be divided - /// operand to divide object - /// A new Current object with a value of value divided by the operand - [Pure] public static Current operator /(Current value, double operand) => new (value.Value / operand); - - /// - /// Returns the absolute value of the - /// - /// - [Pure] public Current Abs() { return new Current(Math.Abs(this.Value)); } - - /// - /// Get a string representation of the object - /// - /// A string representing the object - [Pure] public override string ToString() => Value.ToString(); - - /// - /// Get a string representation of the object - /// - /// format - /// format provider - /// A string representing the object - [Pure] public string ToString(string format, IFormatProvider formatProvider) => Value.ToString(format, formatProvider); - - // IComparable - /// - /// Compare to another Current object - /// - /// The other Current cast to object - /// 0 if equal - [Pure] public int CompareTo(object obj) => Value.CompareTo(obj); - - /// - /// Get type code of object - /// - /// The TypeCode - [Pure] public TypeCode GetTypeCode() => Value.GetTypeCode(); - - /// - /// Convert to boolean - /// - /// format provider - /// bool representation of the object - [Pure] public bool ToBoolean(IFormatProvider provider) => ((IConvertible)Value).ToBoolean(provider); - - /// - /// Convert to byte - /// - /// format provider - /// byte representation of the object - [Pure] public byte ToByte(IFormatProvider provider) => ((IConvertible)Value).ToByte(provider); - - /// - /// Convert to char - /// - /// format provider - /// char representation of the object - [Pure] public char ToChar(IFormatProvider provider) => ((IConvertible)Value).ToChar(provider); - - /// - /// Convert to DateTime - /// - /// format provider - /// DateTime representation of the object - [Pure] public DateTime ToDateTime(IFormatProvider provider) => ((IConvertible)Value).ToDateTime(provider); - - /// - /// Convert to Decimal - /// - /// format provider - /// Decimal representation of the object - [Pure] public decimal ToDecimal(IFormatProvider provider) => ((IConvertible)Value).ToDecimal(provider); - - /// - /// Convert to double - /// - /// format provider - /// double representation of the object - [Pure] public double ToDouble(IFormatProvider provider) => Value; - - /// - /// Convert to in16 - /// - /// format provider - /// int16 representation of the object - [Pure] public short ToInt16(IFormatProvider provider) => ((IConvertible)Value).ToInt16(provider); - - /// - /// Convert to int32 - /// - /// format provider - /// int32 representation of the object - [Pure] public int ToInt32(IFormatProvider provider) => ((IConvertible)Value).ToInt32(provider); - - /// - /// Convert to int64 - /// - /// format provider - /// int64 representation of the object - [Pure] public long ToInt64(IFormatProvider provider) => ((IConvertible)Value).ToInt64(provider); - - /// - /// Convert to sbyte - /// - /// format provider - /// sbyte representation of the object - [Pure] public sbyte ToSByte(IFormatProvider provider) => ((IConvertible)Value).ToSByte(provider); - - /// - /// Convert to float - /// - /// format provider - /// float representation of the object - [Pure] public float ToSingle(IFormatProvider provider) => ((IConvertible)Value).ToSingle(provider); - - /// - /// Convert to string - /// - /// format provider - /// string representation of the object - [Pure] public string ToString(IFormatProvider provider) => Value.ToString(provider); - - /// - /// Convert to type - /// - /// conversion unit type - /// format provider - /// type representation of the object - [Pure] public object ToType(Type conversionType, IFormatProvider provider) => ((IConvertible)Value).ToType(conversionType, provider); - - /// - /// Convert to uint16 - /// - /// format provider - /// uint16 representation of the object - [Pure] public ushort ToUInt16(IFormatProvider provider) => ((IConvertible)Value).ToUInt16(provider); - - /// - /// Convert to uint32 - /// - /// format provider - /// uint32 representation of the object - [Pure] public uint ToUInt32(IFormatProvider provider) => ((IConvertible)Value).ToUInt32(provider); - - /// - /// Convert to uint64 - /// - /// format provider - /// uint64 representation of the object - [Pure] public ulong ToUInt64(IFormatProvider provider) => ((IConvertible)Value).ToUInt64(provider); - - /// - /// Compare the default value to a double - /// - /// value to compare - /// 0 if equal - [Pure] public int CompareTo(double? other) - { - return (other is null) ? -1 : (Value).CompareTo(other.Value); - } - - /// - /// Compare the default value to a double - /// - /// value to compare - /// 0 if equal - [Pure] public bool Equals(double? other) => Value.Equals(other); - - /// - /// Compare the default value to a double - /// - /// value to compare - /// 0 if equal - [Pure] public bool Equals(double other) => Value.Equals(other); - - /// - /// Compare the default value to a double - /// - /// value to compare - /// 0 if equal - [Pure] public int CompareTo(double other) => Value.CompareTo(other); + /// + /// Convert to a specific unit + /// + /// the unit to convert to + /// + [Pure] public double From(UnitType convertTo) + { + return CurrentConversions.Convert(Value, Current.UnitType.Amps, convertTo); + } + + /// + /// Compare to another Current object + /// + /// The object to compare + /// true if equal + [Pure] public override bool Equals(object obj) + { + if (obj is null) { return false; } + if (Equals(this, obj)) { return true; } + return obj.GetType() == GetType() && Equals((Current)obj); + } + + /// + /// Get hash of object + /// + /// int32 hash value + [Pure] public override int GetHashCode() => Value.GetHashCode(); + + // implicit conversions + //[Pure] public static implicit operator Current(ushort value) => new Current(value); + //[Pure] public static implicit operator Current(short value) => new Current(value); + //[Pure] public static implicit operator Current(uint value) => new Current(value); + //[Pure] public static implicit operator Current(long value) => new Current(value); + //[Pure] public static implicit operator Current(int value) => new Current(value); + //[Pure] public static implicit operator Current(float value) => new Current(value); + //[Pure] public static implicit operator Current(double value) => new Current(value); + //[Pure] public static implicit operator Current(decimal value) => new Current((double)value); + + // Comparison + /// + /// Compare to another Current object + /// + /// The object to compare + /// true if equal + [Pure] public bool Equals(Current other) => Value == other.Value; + + /// + /// Equals operator to compare two Current objects + /// + /// left value + /// right value + /// true if equal + [Pure] public static bool operator ==(Current left, Current right) => Equals(left.Value, right.Value); + + /// + /// Not equals operator to compare two Current objects + /// + /// left value + /// right value + /// true if not equal + [Pure] public static bool operator !=(Current left, Current right) => !Equals(left.Value, right.Value); + + /// + /// Compare to another Current object + /// + /// + /// 0 if equal + [Pure] public int CompareTo(Current other) => Equals(Value, other.Value) ? 0 : Value.CompareTo(other.Value); + + /// + /// Less than operator to compare two Current objects + /// + /// left value + /// right value + /// true if left is less than right + [Pure] public static bool operator <(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) < 0; + + /// + /// Greater than operator to compare two Current objects + /// + /// left value + /// right value + /// true if left is greater than right + [Pure] public static bool operator >(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) > 0; + + /// + /// Less than or equal operator to compare two Current objects + /// + /// left value + /// right value + /// true if left is less than or equal to right + [Pure] public static bool operator <=(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) <= 0; + + /// + /// Greater than or equal operator to compare two Current objects + /// + /// left value + /// right value + /// true if left is greater than or equal to right + [Pure] public static bool operator >=(Current left, Current right) => Comparer.Default.Compare(left.Value, right.Value) >= 0; + + // Math + /// + /// Addition operator to add two Current objects + /// + /// left value + /// right value + /// A new Current object with a value of left + right + [Pure] public static Current operator +(Current left, Current right) => new (left.Value + right.Value); + + /// + /// Subtraction operator to subtract two Current objects + /// + /// left value + /// right value + /// A new Current object with a value of left - right + [Pure] public static Current operator -(Current left, Current right) => new (left.Value - right.Value); + + /// + /// Multiplication operator to multiply by a double + /// + /// object to multiply + /// operand to multiply object + /// A new Current object with a value of value multiplied by the operand + [Pure] public static Current operator *(Current value, double operand) => new (value.Value * operand); + + /// + /// Division operator to divide by a double + /// + /// object to be divided + /// operand to divide object + /// A new Current object with a value of value divided by the operand + [Pure] public static Current operator /(Current value, double operand) => new (value.Value / operand); + + /// + /// Returns the absolute value of the + /// + /// + [Pure] public Current Abs() { return new Current(Math.Abs(this.Value)); } + + /// + /// Get a string representation of the object + /// + /// A string representing the object + [Pure] public override string ToString() => Value.ToString(); + + /// + /// Get a string representation of the object + /// + /// format + /// format provider + /// A string representing the object + [Pure] public string ToString(string format, IFormatProvider formatProvider) => Value.ToString(format, formatProvider); + + // IComparable + /// + /// Compare to another Current object + /// + /// The other Current cast to object + /// 0 if equal + [Pure] public int CompareTo(object obj) => Value.CompareTo(obj); + + /// + /// Get type code of object + /// + /// The TypeCode + [Pure] public TypeCode GetTypeCode() => Value.GetTypeCode(); + + /// + /// Convert to boolean + /// + /// format provider + /// bool representation of the object + [Pure] public bool ToBoolean(IFormatProvider provider) => ((IConvertible)Value).ToBoolean(provider); + + /// + /// Convert to byte + /// + /// format provider + /// byte representation of the object + [Pure] public byte ToByte(IFormatProvider provider) => ((IConvertible)Value).ToByte(provider); + + /// + /// Convert to char + /// + /// format provider + /// char representation of the object + [Pure] public char ToChar(IFormatProvider provider) => ((IConvertible)Value).ToChar(provider); + + /// + /// Convert to DateTime + /// + /// format provider + /// DateTime representation of the object + [Pure] public DateTime ToDateTime(IFormatProvider provider) => ((IConvertible)Value).ToDateTime(provider); + + /// + /// Convert to Decimal + /// + /// format provider + /// Decimal representation of the object + [Pure] public decimal ToDecimal(IFormatProvider provider) => ((IConvertible)Value).ToDecimal(provider); + + /// + /// Convert to double + /// + /// format provider + /// double representation of the object + [Pure] public double ToDouble(IFormatProvider provider) => Value; + + /// + /// Convert to in16 + /// + /// format provider + /// int16 representation of the object + [Pure] public short ToInt16(IFormatProvider provider) => ((IConvertible)Value).ToInt16(provider); + + /// + /// Convert to int32 + /// + /// format provider + /// int32 representation of the object + [Pure] public int ToInt32(IFormatProvider provider) => ((IConvertible)Value).ToInt32(provider); + + /// + /// Convert to int64 + /// + /// format provider + /// int64 representation of the object + [Pure] public long ToInt64(IFormatProvider provider) => ((IConvertible)Value).ToInt64(provider); + + /// + /// Convert to sbyte + /// + /// format provider + /// sbyte representation of the object + [Pure] public sbyte ToSByte(IFormatProvider provider) => ((IConvertible)Value).ToSByte(provider); + + /// + /// Convert to float + /// + /// format provider + /// float representation of the object + [Pure] public float ToSingle(IFormatProvider provider) => ((IConvertible)Value).ToSingle(provider); + + /// + /// Convert to string + /// + /// format provider + /// string representation of the object + [Pure] public string ToString(IFormatProvider provider) => Value.ToString(provider); + + /// + /// Convert to type + /// + /// conversion unit type + /// format provider + /// type representation of the object + [Pure] public object ToType(Type conversionType, IFormatProvider provider) => ((IConvertible)Value).ToType(conversionType, provider); + + /// + /// Convert to uint16 + /// + /// format provider + /// uint16 representation of the object + [Pure] public ushort ToUInt16(IFormatProvider provider) => ((IConvertible)Value).ToUInt16(provider); + + /// + /// Convert to uint32 + /// + /// format provider + /// uint32 representation of the object + [Pure] public uint ToUInt32(IFormatProvider provider) => ((IConvertible)Value).ToUInt32(provider); + + /// + /// Convert to uint64 + /// + /// format provider + /// uint64 representation of the object + [Pure] public ulong ToUInt64(IFormatProvider provider) => ((IConvertible)Value).ToUInt64(provider); + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public int CompareTo(double? other) + { + return (other is null) ? -1 : (Value).CompareTo(other.Value); } + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public bool Equals(double? other) => Value.Equals(other); + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public bool Equals(double other) => Value.Equals(other); + + /// + /// Compare the default value to a double + /// + /// value to compare + /// 0 if equal + [Pure] public int CompareTo(double other) => Value.CompareTo(other); } \ No newline at end of file diff --git a/Source/Meadow.Units/Extensions/FrequencyExtensions.cs b/Source/Meadow.Units/Extensions/FrequencyExtensions.cs index f4fbc01..55d2d72 100644 --- a/Source/Meadow.Units/Extensions/FrequencyExtensions.cs +++ b/Source/Meadow.Units/Extensions/FrequencyExtensions.cs @@ -1,7 +1,7 @@ namespace Meadow.Units; /// -/// Provides extension methods for creating Frequency instances. +/// Provides extension methods for creating instances. /// public static class FrequencyExtensions { diff --git a/Source/Meadow.Units/Extensions/LengthExtensions.cs b/Source/Meadow.Units/Extensions/LengthExtensions.cs index 24d930d..4c698f8 100644 --- a/Source/Meadow.Units/Extensions/LengthExtensions.cs +++ b/Source/Meadow.Units/Extensions/LengthExtensions.cs @@ -1,7 +1,7 @@ namespace Meadow.Units; /// -/// Provides extension methods for creating Length instances. +/// Provides extension methods for creating instances. /// public static class LengthExtensions { diff --git a/Source/Meadow.Units/Extensions/ResistanceExtensions.cs b/Source/Meadow.Units/Extensions/ResistanceExtensions.cs index 978885a..9273ea5 100644 --- a/Source/Meadow.Units/Extensions/ResistanceExtensions.cs +++ b/Source/Meadow.Units/Extensions/ResistanceExtensions.cs @@ -1,7 +1,7 @@ namespace Meadow.Units; /// -/// Provides extension methods for creating Resistance instances. +/// Provides extension methods for creating instances. /// public static class ResistanceExtensions { diff --git a/Source/Meadow.Units/Extensions/TemperatureExtensions.cs b/Source/Meadow.Units/Extensions/TemperatureExtensions.cs index d95e352..123c52c 100644 --- a/Source/Meadow.Units/Extensions/TemperatureExtensions.cs +++ b/Source/Meadow.Units/Extensions/TemperatureExtensions.cs @@ -1,7 +1,7 @@ namespace Meadow.Units; /// -/// Provides extension methods for creating Temperature instances. +/// Provides extension methods for creating instances. /// public static class TemperatureExtensions { diff --git a/Source/Meadow.Units/Extensions/VoltageExtensions.cs b/Source/Meadow.Units/Extensions/VoltageExtensions.cs index 609bbfa..42394fb 100644 --- a/Source/Meadow.Units/Extensions/VoltageExtensions.cs +++ b/Source/Meadow.Units/Extensions/VoltageExtensions.cs @@ -1,7 +1,7 @@ namespace Meadow.Units; /// -/// Provides extension methods for creating Resistance instances. +/// Provides extension methods for creating instances. /// public static class VoltageExtensions { diff --git a/Source/Meadow.Units/MagneticField3D.cs b/Source/Meadow.Units/MagneticField3D.cs index 920c17c..0f92958 100644 --- a/Source/Meadow.Units/MagneticField3D.cs +++ b/Source/Meadow.Units/MagneticField3D.cs @@ -3,7 +3,6 @@ using System.ComponentModel; using System.Diagnostics.Contracts; using System.Runtime.InteropServices; -using Meadow.Units.Conversions; using MU = Meadow.Units.MagneticField.UnitType; namespace Meadow.Units From 04efbfd3e8f7ca95332191091894ab117a00630c Mon Sep 17 00:00:00 2001 From: Branden Gunn Date: Wed, 13 Mar 2024 21:18:55 -0400 Subject: [PATCH 6/7] Create CurrentExtensions.cs --- .../Extensions/CurrentExtensions.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Source/Meadow.Units/Extensions/CurrentExtensions.cs diff --git a/Source/Meadow.Units/Extensions/CurrentExtensions.cs b/Source/Meadow.Units/Extensions/CurrentExtensions.cs new file mode 100644 index 0000000..3887166 --- /dev/null +++ b/Source/Meadow.Units/Extensions/CurrentExtensions.cs @@ -0,0 +1,37 @@ +namespace Meadow.Units; + +/// +/// Provides extension methods for creating instances. +/// +public static class CurrentExtensions +{ + /// + /// Creates a Current instance with the specified value in amps. + /// + /// The value of Current as an integer. + /// A new Current instance with the specified value. + public static Current Amps(this int v) + { + return new Current(v, Current.UnitType.Amps); + } + + /// + /// Creates a Current instance with the specified value in amps. + /// + /// The value of Current as a double. + /// A new Current instance with the specified value. + public static Current Amps(this double v) + { + return new Current(v, Current.UnitType.Amps); + } + + /// + /// Creates a Current instance with the specified value in amps. + /// + /// The value of Current as a float. + /// A new Current instance with the specified value. + public static Current Amps(this float v) + { + return new Current(v, Current.UnitType.Amps); + } +} From 1812171460a5e4e4186ec4bd3a02149712efdf57 Mon Sep 17 00:00:00 2001 From: Branden Gunn Date: Fri, 15 Mar 2024 21:40:19 -0400 Subject: [PATCH 7/7] tabs to spaces --- .../AbsoluteHumidityConversions.cs | 34 +++++----- .../Conversions/AccelerationConversions.cs | 40 ++++++------ .../Conversions/AngleConversions.cs | 42 ++++++------ .../AngularAccelerationConversion.cs | 42 ++++++------ .../Conversions/AngularVelocityConversion.cs | 42 ++++++------ .../Conversions/ApparentPowerConversions.cs | 12 ++-- .../Conversions/ConcentrationConversions.cs | 2 +- .../ConcentrationInWaterConversions.cs | 2 +- .../Conversions/ConductivityConversions.cs | 4 +- .../Conversions/CurrentConversions.cs | 42 ++++++------ .../Conversions/DensityConversions.cs | 2 +- .../Conversions/EnergyConversions.cs | 48 +++++++------- .../Conversions/FrequencyConversions.cs | 38 +++++------ .../Conversions/IlluminanceConversions.cs | 36 +++++------ .../Conversions/LengthConversions.cs | 54 ++++++++-------- .../Conversions/MagneticFieldConversions.cs | 46 ++++++------- .../Conversions/MassConversions.cs | 36 +++++------ .../Conversions/ParticleDensityConversions.cs | 2 +- .../Conversions/PowerConversions.cs | 64 +++++++++---------- .../Conversions/PressureConversions.cs | 38 +++++------ .../Conversions/ReactiveEnergyConversions.cs | 12 ++-- .../Conversions/ReactivePowerConversions.cs | 12 ++-- .../Conversions/ResistanceConversions.cs | 36 +++++------ .../Conversions/SpeedConversions.cs | 54 ++++++++-------- .../Conversions/TempConversions.cs | 36 +++++------ .../Conversions/TorqueConversions.cs | 32 +++++----- .../Conversions/VoltageConversions.cs | 42 ++++++------ .../Conversions/VolumeConversions.cs | 46 ++++++------- .../Extensions/FrequencyExtensions.cs | 1 - .../Extensions/LengthExtensions.cs | 1 - .../Extensions/TemperatureExtensions.cs | 1 - 31 files changed, 448 insertions(+), 451 deletions(-) diff --git a/Source/Meadow.Units/Conversions/AbsoluteHumidityConversions.cs b/Source/Meadow.Units/Conversions/AbsoluteHumidityConversions.cs index ea27709..08c1093 100644 --- a/Source/Meadow.Units/Conversions/AbsoluteHumidityConversions.cs +++ b/Source/Meadow.Units/Conversions/AbsoluteHumidityConversions.cs @@ -1,21 +1,21 @@ namespace Meadow.Units.Conversions { - internal static class AbsoluteHumidityConversions - { - public static double Convert(double value, AbsoluteHumidity.UnitType from, AbsoluteHumidity.UnitType to) - { - if (from == to) - { - return value; - } - return value * humidityConversions[(int)to] / humidityConversions[(int)from]; - } + internal static class AbsoluteHumidityConversions + { + public static double Convert(double value, AbsoluteHumidity.UnitType from, AbsoluteHumidity.UnitType to) + { + if (from == to) + { + return value; + } + return value * humidityConversions[(int)to] / humidityConversions[(int)from]; + } - //must align to enum - private static readonly double[] humidityConversions = - { - 1000.0,//grams per cubic meter - 1.0,//kilograms per cubic meter - }; - } + //must align to enum + private static readonly double[] humidityConversions = + { + 1000.0,//grams per cubic meter + 1.0,//kilograms per cubic meter + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/AccelerationConversions.cs b/Source/Meadow.Units/Conversions/AccelerationConversions.cs index 4987bf1..c8e9267 100644 --- a/Source/Meadow.Units/Conversions/AccelerationConversions.cs +++ b/Source/Meadow.Units/Conversions/AccelerationConversions.cs @@ -2,25 +2,25 @@ { internal static class AccelerationConversions { - public static double Convert(double value, Acceleration.UnitType from, Acceleration.UnitType to) - { - if (from == to) - { - return value; - } - return value * accelConversions[(int)to] / accelConversions[(int)from]; - } + public static double Convert(double value, Acceleration.UnitType from, Acceleration.UnitType to) + { + if (from == to) + { + return value; + } + return value * accelConversions[(int)to] / accelConversions[(int)from]; + } - private static readonly double[] accelConversions = - { - 1.0, //meters per second squared - 100.0, //cm per s squared - 100.0, // gal (galileo) - 100000.0, // milligal - 0.0001019716213, //milli gravity - 0.1019716213,//gravity - 3.280839895,//feet per second squared - 39.37007874,//inches per s squared - }; - } + private static readonly double[] accelConversions = + { + 1.0, //meters per second squared + 100.0, //cm per s squared + 100.0, // gal (galileo) + 100000.0, // milligal + 0.0001019716213, //milli gravity + 0.1019716213,//gravity + 3.280839895,//feet per second squared + 39.37007874,//inches per s squared + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/AngleConversions.cs b/Source/Meadow.Units/Conversions/AngleConversions.cs index 643b569..ac77bc1 100644 --- a/Source/Meadow.Units/Conversions/AngleConversions.cs +++ b/Source/Meadow.Units/Conversions/AngleConversions.cs @@ -2,26 +2,26 @@ namespace Meadow.Units.Conversions { - internal static class AngleConversions - { - public static double Convert(double value, Angle.UnitType from, Angle.UnitType to) - { - if (from == to) - { - return value; - } - return value * angleConversions[(int)to] / angleConversions[(int)from]; - } + internal static class AngleConversions + { + public static double Convert(double value, Angle.UnitType from, Angle.UnitType to) + { + if (from == to) + { + return value; + } + return value * angleConversions[(int)to] / angleConversions[(int)from]; + } - //must align to enum - private static readonly double[] angleConversions = - { - 1, //revolution - 360, //degrees - 2*Math.PI, //radians - 400, //gradians - 21600, //minutes - 1296000, //seconds - }; - } + //must align to enum + private static readonly double[] angleConversions = + { + 1, //revolution + 360, //degrees + 2*Math.PI, //radians + 400, //gradians + 21600, //minutes + 1296000, //seconds + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/AngularAccelerationConversion.cs b/Source/Meadow.Units/Conversions/AngularAccelerationConversion.cs index 4ee9881..7c4e799 100644 --- a/Source/Meadow.Units/Conversions/AngularAccelerationConversion.cs +++ b/Source/Meadow.Units/Conversions/AngularAccelerationConversion.cs @@ -1,25 +1,25 @@ namespace Meadow.Units.Conversions { - internal static class AngularAccelerationConversions - { - public static double Convert(double value, AngularAcceleration.UnitType from, AngularAcceleration.UnitType to) - { - if (from == to) - { - return value; - } - return value * angularAccelerationConversions[(int)to] / angularAccelerationConversions[(int)from]; - } + internal static class AngularAccelerationConversions + { + public static double Convert(double value, AngularAcceleration.UnitType from, AngularAcceleration.UnitType to) + { + if (from == to) + { + return value; + } + return value * angularAccelerationConversions[(int)to] / angularAccelerationConversions[(int)from]; + } - //must align to enum - private static readonly double[] angularAccelerationConversions = - { - 1, //revolutions per second^2 - 3600, //revolutions per minute^2 - 6.28318530717959, //radians per second^2 - 22619.4671058465, //radians per minute^2 - 360, //degrees per second^2 - 1296000, //degrees per minute^2 - }; - } + //must align to enum + private static readonly double[] angularAccelerationConversions = + { + 1, //revolutions per second^2 + 3600, //revolutions per minute^2 + 6.28318530717959, //radians per second^2 + 22619.4671058465, //radians per minute^2 + 360, //degrees per second^2 + 1296000, //degrees per minute^2 + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/AngularVelocityConversion.cs b/Source/Meadow.Units/Conversions/AngularVelocityConversion.cs index dfc7dcc..166b163 100644 --- a/Source/Meadow.Units/Conversions/AngularVelocityConversion.cs +++ b/Source/Meadow.Units/Conversions/AngularVelocityConversion.cs @@ -1,25 +1,25 @@ namespace Meadow.Units.Conversions { - internal static class AngularVelocityConversions - { - public static double Convert(double value, AngularVelocity.UnitType from, AngularVelocity.UnitType to) - { - if (from == to) - { - return value; - } - return value * angularVelocityConversions[(int)to] / angularVelocityConversions[(int)from]; - } + internal static class AngularVelocityConversions + { + public static double Convert(double value, AngularVelocity.UnitType from, AngularVelocity.UnitType to) + { + if (from == to) + { + return value; + } + return value * angularVelocityConversions[(int)to] / angularVelocityConversions[(int)from]; + } - //must align to enum - private static readonly double[] angularVelocityConversions = - { - 1, //revolutions per second - 60, //revolutions per minute - 6.28318530717959, //radians per second - 376.991118430775, //radians per minute - 360, //degrees per second - 21600, //degrees per minute - }; - } + //must align to enum + private static readonly double[] angularVelocityConversions = + { + 1, //revolutions per second + 60, //revolutions per minute + 6.28318530717959, //radians per second + 376.991118430775, //radians per minute + 360, //degrees per second + 21600, //degrees per minute + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/ApparentPowerConversions.cs b/Source/Meadow.Units/Conversions/ApparentPowerConversions.cs index ea89fb3..776597b 100644 --- a/Source/Meadow.Units/Conversions/ApparentPowerConversions.cs +++ b/Source/Meadow.Units/Conversions/ApparentPowerConversions.cs @@ -14,11 +14,11 @@ public static double Convert(double value, ApparentPower.UnitType from, Apparent //must align to enum private static readonly double[] apparentPowerConversions = { - 0.000000001, //Gigavolt ampere - 0.000001, //Megavolt ampere - 0.001, //Kilovolt ampere - 1.0, //Volt ampere - 1000.0, //Millivolt ampere - }; + 0.000000001, //Gigavolt ampere + 0.000001, //Megavolt ampere + 0.001, //Kilovolt ampere + 1.0, //Volt ampere + 1000.0, //Millivolt ampere + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/ConcentrationConversions.cs b/Source/Meadow.Units/Conversions/ConcentrationConversions.cs index db8d55f..fd1d7f3 100644 --- a/Source/Meadow.Units/Conversions/ConcentrationConversions.cs +++ b/Source/Meadow.Units/Conversions/ConcentrationConversions.cs @@ -18,6 +18,6 @@ public static double Convert(double value, Concentration.UnitType from, Concentr 10.0,//ppt 10000.0, // ppm 10000000.0, // ppb - }; + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/ConcentrationInWaterConversions.cs b/Source/Meadow.Units/Conversions/ConcentrationInWaterConversions.cs index 86dc69d..0fb5cea 100644 --- a/Source/Meadow.Units/Conversions/ConcentrationInWaterConversions.cs +++ b/Source/Meadow.Units/Conversions/ConcentrationInWaterConversions.cs @@ -22,6 +22,6 @@ public static double Convert(double value, ConcentrationInWater.UnitType from, C 10000000.0, // ppb 10000000.0, // ug/L 10000000000.0, // ppt - }; + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/ConductivityConversions.cs b/Source/Meadow.Units/Conversions/ConductivityConversions.cs index 3d7eb66..b7473bf 100644 --- a/Source/Meadow.Units/Conversions/ConductivityConversions.cs +++ b/Source/Meadow.Units/Conversions/ConductivityConversions.cs @@ -16,10 +16,10 @@ public static double Convert(double value, Conductivity.UnitType from, Conductiv { 1, //siemen per cm 100, //siemen per m - 1000, //milli siemen per cm + 1000, //milli siemen per cm 100000, //milli siemen per m 1000000, //micro siemen per cm 100000000, //micro siemen per m - }; + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/CurrentConversions.cs b/Source/Meadow.Units/Conversions/CurrentConversions.cs index ba9f0a6..332221e 100644 --- a/Source/Meadow.Units/Conversions/CurrentConversions.cs +++ b/Source/Meadow.Units/Conversions/CurrentConversions.cs @@ -1,25 +1,25 @@ namespace Meadow.Units.Conversions { - internal static class CurrentConversions - { - public static double Convert(double value, Current.UnitType from, Current.UnitType to) - { - if (from == to) - { - return value; - } - return value * currentConversions[(int)to] / currentConversions[(int)from]; - } + internal static class CurrentConversions + { + public static double Convert(double value, Current.UnitType from, Current.UnitType to) + { + if (from == to) + { + return value; + } + return value * currentConversions[(int)to] / currentConversions[(int)from]; + } - //must align to enum - private static readonly double[] currentConversions = - { - 1, //Amps - 1000, //Milliamps - 1000000, //Microamps - 0.001, //Kiloamps - 0.000001, //Megaamps - 0.000000001, //Gigaamps - }; - } + //must align to enum + private static readonly double[] currentConversions = + { + 1, //Amps + 1000, //Milliamps + 1000000, //Microamps + 0.001, //Kiloamps + 0.000001, //Megaamps + 0.000000001, //Gigaamps + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/DensityConversions.cs b/Source/Meadow.Units/Conversions/DensityConversions.cs index 9905477..a8651c9 100644 --- a/Source/Meadow.Units/Conversions/DensityConversions.cs +++ b/Source/Meadow.Units/Conversions/DensityConversions.cs @@ -25,6 +25,6 @@ public static double Convert(double value, Density.UnitType from, Density.UnitTy 0.000036127292,//pound /inch 0.062427960576,//pound /ft^3 0.0010018032458,//water (20) - }; + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/EnergyConversions.cs b/Source/Meadow.Units/Conversions/EnergyConversions.cs index 0734c62..eb8b460 100644 --- a/Source/Meadow.Units/Conversions/EnergyConversions.cs +++ b/Source/Meadow.Units/Conversions/EnergyConversions.cs @@ -2,29 +2,29 @@ namespace Meadow.Units.Conversions { - internal static class EnergyConversions - { - public static double Convert(double value, Energy.UnitType from, Energy.UnitType to) - { - if (from == to) - { - return value; - } - return value * energyConversions[(int)to] / energyConversions[(int)from]; - } + internal static class EnergyConversions + { + public static double Convert(double value, Energy.UnitType from, Energy.UnitType to) + { + if (from == to) + { + return value; + } + return value * energyConversions[(int)to] / energyConversions[(int)from]; + } - //must align to enum - private static readonly double[] energyConversions = - { - 0.00094845138281, //BTU - 0.23900573614, //calories (thermo) - 1.0,//joules - 0.00023900573614, //kilocals - 0.001,//kilojoules - 0.000000277777777778, //kilowatt hours - 9.4804342797*Math.Pow(10.0,-9.0), //therms - 0.000277777777778, //watt hours, - 1.0, //watt seconds - }; - } + //must align to enum + private static readonly double[] energyConversions = + { + 0.00094845138281, //BTU + 0.23900573614, //calories (thermo) + 1.0,//joules + 0.00023900573614, //kilocals + 0.001,//kilojoules + 0.000000277777777778, //kilowatt hours + 9.4804342797*Math.Pow(10.0,-9.0), //therms + 0.000277777777778, //watt hours, + 1.0, //watt seconds + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/FrequencyConversions.cs b/Source/Meadow.Units/Conversions/FrequencyConversions.cs index ceb8ccc..6fbae7c 100644 --- a/Source/Meadow.Units/Conversions/FrequencyConversions.cs +++ b/Source/Meadow.Units/Conversions/FrequencyConversions.cs @@ -1,23 +1,23 @@ namespace Meadow.Units.Conversions { - internal static class FrequencyConversions - { - public static double Convert(double value, Frequency.UnitType from, Frequency.UnitType to) - { - if (from == to) - { - return value; - } - return value * frequencyConversions[(int)to] / frequencyConversions[(int)from]; - } + internal static class FrequencyConversions + { + public static double Convert(double value, Frequency.UnitType from, Frequency.UnitType to) + { + if (from == to) + { + return value; + } + return value * frequencyConversions[(int)to] / frequencyConversions[(int)from]; + } - //must align to enum - private static readonly double[] frequencyConversions = - { - 1, //GHz - 1000, //MHz - 1000000, //kHz - 1000000000, //Hz - }; - } + //must align to enum + private static readonly double[] frequencyConversions = + { + 1, //GHz + 1000, //MHz + 1000000, //kHz + 1000000000, //Hz + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/IlluminanceConversions.cs b/Source/Meadow.Units/Conversions/IlluminanceConversions.cs index b89b7e2..82df93f 100644 --- a/Source/Meadow.Units/Conversions/IlluminanceConversions.cs +++ b/Source/Meadow.Units/Conversions/IlluminanceConversions.cs @@ -1,22 +1,22 @@ namespace Meadow.Units.Conversions { - internal static class IlluminanceConversions - { - public static double Convert(double value, Illuminance.UnitType from, Illuminance.UnitType to) - { - if (from == to) - { - return value; - } - return value * illuminanceConversions[(int)to] / illuminanceConversions[(int)from]; - } + internal static class IlluminanceConversions + { + public static double Convert(double value, Illuminance.UnitType from, Illuminance.UnitType to) + { + if (from == to) + { + return value; + } + return value * illuminanceConversions[(int)to] / illuminanceConversions[(int)from]; + } - //must align to enum - private static readonly double[] illuminanceConversions = - { - 0.001, //kilo lux - 1.0, //lux - 0.0930578820026056//foot-candle - }; - } + //must align to enum + private static readonly double[] illuminanceConversions = + { + 0.001, //kilo lux + 1.0, //lux + 0.0930578820026056//foot-candle + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/LengthConversions.cs b/Source/Meadow.Units/Conversions/LengthConversions.cs index b04ac97..1569421 100644 --- a/Source/Meadow.Units/Conversions/LengthConversions.cs +++ b/Source/Meadow.Units/Conversions/LengthConversions.cs @@ -1,31 +1,31 @@ namespace Meadow.Units.Conversions { - internal static class LengthConversions - { - public static double Convert(double value, Length.UnitType from, Length.UnitType to) - { - if (from == to) - { - return value; - } - return value * lengthConversions[(int)to] / lengthConversions[(int)from]; - } + internal static class LengthConversions + { + public static double Convert(double value, Length.UnitType from, Length.UnitType to) + { + if (from == to) + { + return value; + } + return value * lengthConversions[(int)to] / lengthConversions[(int)from]; + } - //must align to enum - private static readonly double[] lengthConversions = - { - 0.001,//km - 1,//meter - 100,//cm - 10,//dm - 1000,//millimeter - 1000000,//micron / micrometer - 1000000000,//nm - 0.00062137119224,//mile - 0.000539956803,//nautical miles - 1.0936132983,//yard - 3.280839895,//ft - 39.37007874,//inch - }; - } + //must align to enum + private static readonly double[] lengthConversions = + { + 0.001,//km + 1,//meter + 100,//cm + 10,//dm + 1000,//millimeter + 1000000,//micron / micrometer + 1000000000,//nm + 0.00062137119224,//mile + 0.000539956803,//nautical miles + 1.0936132983,//yard + 3.280839895,//ft + 39.37007874,//inch + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/MagneticFieldConversions.cs b/Source/Meadow.Units/Conversions/MagneticFieldConversions.cs index 1454562..7fd9d35 100644 --- a/Source/Meadow.Units/Conversions/MagneticFieldConversions.cs +++ b/Source/Meadow.Units/Conversions/MagneticFieldConversions.cs @@ -1,27 +1,27 @@ namespace Meadow.Units.Conversions { - internal static class MagneticFieldConversions - { - public static double Convert(double value, MagneticField.UnitType from, MagneticField.UnitType to) - { - if (from == to) - { - return value; - } - return value * magneticFieldConversions[(int)to] / magneticFieldConversions[(int)from]; - } + internal static class MagneticFieldConversions + { + public static double Convert(double value, MagneticField.UnitType from, MagneticField.UnitType to) + { + if (from == to) + { + return value; + } + return value * magneticFieldConversions[(int)to] / magneticFieldConversions[(int)from]; + } - //must align to enum - private static readonly double[] magneticFieldConversions = - { - 0.000001, //MegaTesla - 0.001, //KiloTesla - 1.0, //Tesla - 1000.0,//MilliTesla - 1000000.0, //MicroTesla - 1000000000.0, //NanoTesla - 1000000000000.0, //PicoTesla - 10000.0, //Gauss - }; - } + //must align to enum + private static readonly double[] magneticFieldConversions = + { + 0.000001, //MegaTesla + 0.001, //KiloTesla + 1.0, //Tesla + 1000.0,//MilliTesla + 1000000.0, //MicroTesla + 1000000000.0, //NanoTesla + 1000000000000.0, //PicoTesla + 10000.0, //Gauss + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/MassConversions.cs b/Source/Meadow.Units/Conversions/MassConversions.cs index d88d910..9643a2f 100644 --- a/Source/Meadow.Units/Conversions/MassConversions.cs +++ b/Source/Meadow.Units/Conversions/MassConversions.cs @@ -4,25 +4,25 @@ internal static class MassConversions { public static double Convert(double value, Mass.UnitType from, Mass.UnitType to) { - if(from == to) + if(from == to) { - return value; + return value; } - return value * massConversions[(int)to] / massConversions[(int)from]; - } + return value * massConversions[(int)to] / massConversions[(int)from]; + } - //must align to enum - private static readonly double[] massConversions = - { - 1, //grams (identity unit) - 0.001, //kg - 0.0352739619495804129156758082152,//ounces - 0.0022046226218487758072297380134, //pounds - 0.000001, //tonnes metric - 0.0000011023113109243879036148690, //Tons US Short ... 5000 pounds - 0.0000009842065276110606282275616,//Tons UK Long - 15.4323584, // grains - 5, // Carats - }; - } + //must align to enum + private static readonly double[] massConversions = + { + 1, //grams (identity unit) + 0.001, //kg + 0.0352739619495804129156758082152,//ounces + 0.0022046226218487758072297380134, //pounds + 0.000001, //tonnes metric + 0.0000011023113109243879036148690, //Tons US Short ... 5000 pounds + 0.0000009842065276110606282275616,//Tons UK Long + 15.4323584, // grains + 5, // Carats + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/ParticleDensityConversions.cs b/Source/Meadow.Units/Conversions/ParticleDensityConversions.cs index f7f2b96..63e37a5 100644 --- a/Source/Meadow.Units/Conversions/ParticleDensityConversions.cs +++ b/Source/Meadow.Units/Conversions/ParticleDensityConversions.cs @@ -17,6 +17,6 @@ public static double Convert(double value, ParticleDensity.UnitType from, Partic 1.0,//particles/l 100.0,//particles/cl 1000.0,//particles/ml - }; + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/PowerConversions.cs b/Source/Meadow.Units/Conversions/PowerConversions.cs index 44b51f0..750a6be 100644 --- a/Source/Meadow.Units/Conversions/PowerConversions.cs +++ b/Source/Meadow.Units/Conversions/PowerConversions.cs @@ -1,39 +1,39 @@ namespace Meadow.Units.Conversions { - internal static class PowerConversions - { - public static double Convert(double value, Power.UnitType from, Power.UnitType to) - { - if (from == to) - { - return value; - } - return value * powerConversions[(int)to] / powerConversions[(int)from]; - } + internal static class PowerConversions + { + public static double Convert(double value, Power.UnitType from, Power.UnitType to) + { + if (from == to) + { + return value; + } + return value * powerConversions[(int)to] / powerConversions[(int)from]; + } - //must align to enum - private static readonly double[] powerConversions = - { - 0.000000001, //gigawatts - 0.000001, //milliwatts - 0.001, //kwatts - 1.0, //watts - 1000.0, //milliwatt + //must align to enum + private static readonly double[] powerConversions = + { + 0.000000001, //gigawatts + 0.000001, //milliwatts + 0.001, //kwatts + 1.0, //watts + 1000.0, //milliwatt - 0.0013596216173, //HP metric - 0.0013410220924, //HP IT + 0.0013596216173, //HP metric + 0.0013410220924, //HP IT - 0.23884589663, //cals/s - 14.330753798, //cals/min - 859.84522786, //cals/hour - 0.00094781712087, //BTU/sec - 0.056869027252, //BTU/min - 3.4121416351, //BTU/hour - - 0.73756217557, //ft-pounds/sec - 44.253730534, //ft-pound/min - 2655.2238321, //ft-pounds/hour + 0.23884589663, //cals/s + 14.330753798, //cals/min + 859.84522786, //cals/hour + 0.00094781712087, //BTU/sec + 0.056869027252, //BTU/min + 3.4121416351, //BTU/hour + + 0.73756217557, //ft-pounds/sec + 44.253730534, //ft-pound/min + 2655.2238321, //ft-pounds/hour 0.00028434513609399,//Tons refrigeration - }; - } + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/PressureConversions.cs b/Source/Meadow.Units/Conversions/PressureConversions.cs index bdddf97..5225f56 100644 --- a/Source/Meadow.Units/Conversions/PressureConversions.cs +++ b/Source/Meadow.Units/Conversions/PressureConversions.cs @@ -14,25 +14,25 @@ internal static class PressureConversions public static Func PaToBar = (value) => (value / 100000); - public static double Convert(double value, Pressure.UnitType from, Pressure.UnitType to) - { - if (from == to) { - return value; - } - return value * pressureConversions[(int)to] / pressureConversions[(int)from]; - } + public static double Convert(double value, Pressure.UnitType from, Pressure.UnitType to) + { + if (from == to) { + return value; + } + return value * pressureConversions[(int)to] / pressureConversions[(int)from]; + } - //must align to enum - private static readonly double[] pressureConversions = - { - 1,//Bar - 100000, //Pascal, - 14.503773773, //Psi, - 0.9869232667, //StandardAtmosphere, - 1000, // mBar - 1000, // hPa (yes, same as millibar, but both are common) - 100, //kPa - }; + //must align to enum + private static readonly double[] pressureConversions = + { + 1,//Bar + 100000, //Pascal, + 14.503773773, //Psi, + 0.9869232667, //StandardAtmosphere, + 1000, // mBar + 1000, // hPa (yes, same as millibar, but both are common) + 100, //kPa + }; - } + } } diff --git a/Source/Meadow.Units/Conversions/ReactiveEnergyConversions.cs b/Source/Meadow.Units/Conversions/ReactiveEnergyConversions.cs index 1c83601..fdc576d 100644 --- a/Source/Meadow.Units/Conversions/ReactiveEnergyConversions.cs +++ b/Source/Meadow.Units/Conversions/ReactiveEnergyConversions.cs @@ -14,11 +14,11 @@ public static double Convert(double value, ReactiveEnergy.UnitType from, Reactiv //must align to enum private static readonly double[] reactiveEnergyConversions = { - 0.000000001, //Gigavolt ampere - 0.000001, //Megavolt ampere - 0.001, //Kilovolt ampere - 1.0, //Volt ampere - 1000.0, //Millivolt ampere - }; + 0.000000001, //Gigavolt ampere + 0.000001, //Megavolt ampere + 0.001, //Kilovolt ampere + 1.0, //Volt ampere + 1000.0, //Millivolt ampere + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/ReactivePowerConversions.cs b/Source/Meadow.Units/Conversions/ReactivePowerConversions.cs index f071165..56801f8 100644 --- a/Source/Meadow.Units/Conversions/ReactivePowerConversions.cs +++ b/Source/Meadow.Units/Conversions/ReactivePowerConversions.cs @@ -14,11 +14,11 @@ public static double Convert(double value, ReactivePower.UnitType from, Reactive //must align to enum private static readonly double[] reactivePowerConversions = { - 0.000000001, //Gigavolt ampere - 0.000001, //Megavolt ampere - 0.001, //Kilovolt ampere - 1.0, //Volt ampere - 1000.0, //Millivolt ampere - }; + 0.000000001, //Gigavolt ampere + 0.000001, //Megavolt ampere + 0.001, //Kilovolt ampere + 1.0, //Volt ampere + 1000.0, //Millivolt ampere + }; } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/ResistanceConversions.cs b/Source/Meadow.Units/Conversions/ResistanceConversions.cs index ea80eca..bd7c9e3 100644 --- a/Source/Meadow.Units/Conversions/ResistanceConversions.cs +++ b/Source/Meadow.Units/Conversions/ResistanceConversions.cs @@ -1,23 +1,23 @@ namespace Meadow.Units.Conversions { internal static class ResistanceConversions - { - public static double Convert(double value, Resistance.UnitType from, Resistance.UnitType to) - { - if (from == to) - { - return value; - } - return value * resistanceConversions[(int)to] / resistanceConversions[(int)from]; - } + { + public static double Convert(double value, Resistance.UnitType from, Resistance.UnitType to) + { + if (from == to) + { + return value; + } + return value * resistanceConversions[(int)to] / resistanceConversions[(int)from]; + } - //must align to enum - private static readonly double[] resistanceConversions = - { - 1000, //MilliOhms - 1, //Ohms - 0.001, //KiloOhms - 0.000001, //MegaOhms - }; - } + //must align to enum + private static readonly double[] resistanceConversions = + { + 1000, //MilliOhms + 1, //Ohms + 0.001, //KiloOhms + 0.000001, //MegaOhms + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/SpeedConversions.cs b/Source/Meadow.Units/Conversions/SpeedConversions.cs index 8bd6a94..40985b6 100644 --- a/Source/Meadow.Units/Conversions/SpeedConversions.cs +++ b/Source/Meadow.Units/Conversions/SpeedConversions.cs @@ -1,32 +1,32 @@ namespace Meadow.Units.Conversions { - internal static class SpeedConversions - { - public static double Convert(double value, Speed.UnitType from, Speed.UnitType to) - { - if (from == to) - { - return value; - } - return value * speedConversions[(int)to] / speedConversions[(int)from]; - } + internal static class SpeedConversions + { + public static double Convert(double value, Speed.UnitType from, Speed.UnitType to) + { + if (from == to) + { + return value; + } + return value * speedConversions[(int)to] / speedConversions[(int)from]; + } - //must align to enum - private static readonly double[] speedConversions = - { - 196850.3937,// ft/min - 3280.839895,// ft/s - 3600.0,// km/h + //must align to enum + private static readonly double[] speedConversions = + { + 196850.3937,// ft/min + 3280.839895,// ft/s + 3600.0,// km/h 60.0,//km/min - 1.0,// km/s - 1943.8444925,// knots - 60000.0,// m/min - 1000.0,// m/s - 2236.9362922064,// mph - 37.2822715344,//mpm - 0.62137119224,//mps - 0.000003335640952,// c - 2.938669958// mach - }; - } + 1.0,// km/s + 1943.8444925,// knots + 60000.0,// m/min + 1000.0,// m/s + 2236.9362922064,// mph + 37.2822715344,//mpm + 0.62137119224,//mps + 0.000003335640952,// c + 2.938669958// mach + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/TempConversions.cs b/Source/Meadow.Units/Conversions/TempConversions.cs index fdd9d25..8ba4283 100644 --- a/Source/Meadow.Units/Conversions/TempConversions.cs +++ b/Source/Meadow.Units/Conversions/TempConversions.cs @@ -12,27 +12,27 @@ internal static class TempConversions public static Func CToK = (value) => value + 273.15D; - public static double Convert(double value, Temperature.UnitType from, Temperature.UnitType to) - { - if (from == to) { return value; } + public static double Convert(double value, Temperature.UnitType from, Temperature.UnitType to) + { + if (from == to) { return value; } - if (from == Temperature.UnitType.Celsius && to == Temperature.UnitType.Fahrenheit) { - return CToK(value); - } - if (from == Temperature.UnitType.Fahrenheit && to == Temperature.UnitType.Celsius) { + if (from == Temperature.UnitType.Celsius && to == Temperature.UnitType.Fahrenheit) { + return CToK(value); + } + if (from == Temperature.UnitType.Fahrenheit && to == Temperature.UnitType.Celsius) { } - return value * temperatureConversions[(int)to] / temperatureConversions[(int)from]; - } + return value * temperatureConversions[(int)to] / temperatureConversions[(int)from]; + } - //must align to enum - private static readonly double[] temperatureConversions = - { - 1,//Celsius, - -32*(5D/9D),//Fahrenheit, // NO WAY TO GET THIS TO WORK? - //(9D / 5D) + 32D, - 273.15D//Kelvin, - }; - } + //must align to enum + private static readonly double[] temperatureConversions = + { + 1,//Celsius, + -32*(5D/9D),//Fahrenheit, // NO WAY TO GET THIS TO WORK? + //(9D / 5D) + 32D, + 273.15D//Kelvin, + }; + } } diff --git a/Source/Meadow.Units/Conversions/TorqueConversions.cs b/Source/Meadow.Units/Conversions/TorqueConversions.cs index bdbaae5..d6b7505 100644 --- a/Source/Meadow.Units/Conversions/TorqueConversions.cs +++ b/Source/Meadow.Units/Conversions/TorqueConversions.cs @@ -1,20 +1,20 @@ namespace Meadow.Units.Conversions { - internal static class TorqueConversions - { - public static double Convert(double value, Torque.UnitType from, Torque.UnitType to) - { - if (from == to) - { - return value; - } - return value * speedConversions[(int)to] / speedConversions[(int)from]; - } + internal static class TorqueConversions + { + public static double Convert(double value, Torque.UnitType from, Torque.UnitType to) + { + if (from == to) + { + return value; + } + return value * speedConversions[(int)to] / speedConversions[(int)from]; + } - //must align to enum - private static readonly double[] speedConversions = - { - 1.355817952,//newton-meter + //must align to enum + private static readonly double[] speedConversions = + { + 1.355817952,//newton-meter 1.0,//foot pound 0.13825495475,//kilogram-meter 13.825495475,//kg-cm @@ -22,6 +22,6 @@ public static double Convert(double value, Torque.UnitType from, Torque.UnitType 12.0,//inch pound 192.0,//inch oz 13558179.52,//dyne centimeter - }; - } + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Conversions/VoltageConversions.cs b/Source/Meadow.Units/Conversions/VoltageConversions.cs index 6a0a16a..ec60004 100644 --- a/Source/Meadow.Units/Conversions/VoltageConversions.cs +++ b/Source/Meadow.Units/Conversions/VoltageConversions.cs @@ -1,26 +1,26 @@ namespace Meadow.Units.Conversions { internal static class VoltageConversions - { - public static double Convert(double value, Voltage.UnitType from, Voltage.UnitType to) - { - if (from == to) { - return value; - } - return value * voltageConversions[(int)to] / voltageConversions[(int)from]; - } + { + public static double Convert(double value, Voltage.UnitType from, Voltage.UnitType to) + { + if (from == to) { + return value; + } + return value * voltageConversions[(int)to] / voltageConversions[(int)from]; + } - //must align to enum - private static readonly double[] voltageConversions = - { - 1, //Volts - 1000, //Millivolts - 1000000, //Microvolts - 0.001, //Kilovolts - 0.000001, //Megavolts - 0.000000001, //Gigavolts - 299.792458, //Statvolts + //must align to enum + private static readonly double[] voltageConversions = + { + 1, //Volts + 1000, //Millivolts + 1000000, //Microvolts + 0.001, //Kilovolts + 0.000001, //Megavolts + 0.000000001, //Gigavolts + 299.792458, //Statvolts 1000000000, //Nanovolts - }; - } -} \ No newline at end of file + }; + } +} diff --git a/Source/Meadow.Units/Conversions/VolumeConversions.cs b/Source/Meadow.Units/Conversions/VolumeConversions.cs index e60e616..9d925db 100644 --- a/Source/Meadow.Units/Conversions/VolumeConversions.cs +++ b/Source/Meadow.Units/Conversions/VolumeConversions.cs @@ -1,27 +1,27 @@ namespace Meadow.Units.Conversions { - internal static class VolumeConversions - { - public static double Convert(double value, Volume.UnitType from, Volume.UnitType to) - { - if (from == to) - { - return value; - } - return value * volumeConversions[(int)to] / volumeConversions[(int)from]; - } + internal static class VolumeConversions + { + public static double Convert(double value, Volume.UnitType from, Volume.UnitType to) + { + if (from == to) + { + return value; + } + return value * volumeConversions[(int)to] / volumeConversions[(int)from]; + } - //must align to enum - private static readonly double[] volumeConversions = - { - 1.0, //gal US - 133.2278701, //ounces - 0.13368055556 , //cubic feet - 231.0, //cubic inches - 3.785411784, //liters - 378.5411784, //cl - 3785.411784, //ml - 0.003785411784, //m3 - }; - } + //must align to enum + private static readonly double[] volumeConversions = + { + 1.0, //gal US + 133.2278701, //ounces + 0.13368055556 , //cubic feet + 231.0, //cubic inches + 3.785411784, //liters + 378.5411784, //cl + 3785.411784, //ml + 0.003785411784, //m3 + }; + } } \ No newline at end of file diff --git a/Source/Meadow.Units/Extensions/FrequencyExtensions.cs b/Source/Meadow.Units/Extensions/FrequencyExtensions.cs index 55d2d72..1d2a2c1 100644 --- a/Source/Meadow.Units/Extensions/FrequencyExtensions.cs +++ b/Source/Meadow.Units/Extensions/FrequencyExtensions.cs @@ -25,4 +25,3 @@ public static Frequency Hertz(this int v) return new Frequency(v, Frequency.UnitType.Hertz); } } - diff --git a/Source/Meadow.Units/Extensions/LengthExtensions.cs b/Source/Meadow.Units/Extensions/LengthExtensions.cs index 4c698f8..9b95526 100644 --- a/Source/Meadow.Units/Extensions/LengthExtensions.cs +++ b/Source/Meadow.Units/Extensions/LengthExtensions.cs @@ -25,4 +25,3 @@ public static Length Meters(this int v) return new Length(v, Length.UnitType.Meters); } } - diff --git a/Source/Meadow.Units/Extensions/TemperatureExtensions.cs b/Source/Meadow.Units/Extensions/TemperatureExtensions.cs index 123c52c..26a4dcd 100644 --- a/Source/Meadow.Units/Extensions/TemperatureExtensions.cs +++ b/Source/Meadow.Units/Extensions/TemperatureExtensions.cs @@ -45,4 +45,3 @@ public static Temperature Celsius(this int v) return new Temperature(v, Temperature.UnitType.Celsius); } } -