public static double ConvertSpeedToMPS(SpeedMeasurementType _fromType, double _fromValue) { double multiplier = 1.0; switch (_fromType) { case SpeedMeasurementType.FeetPerSecond: { multiplier = .3048; break; } case SpeedMeasurementType.KilometersPerHour: { multiplier = .277777778; break; } case SpeedMeasurementType.MilesPerHour: { multiplier = .44704; break; } case SpeedMeasurementType.MetersPerSecond: default: { multiplier = 1.0; break; } } return multiplier*_fromValue; }
public static double ConvertSpeedFromMPS(SpeedMeasurementType _toType, double _fromValue) { double multiplier = 1.0; switch (_toType) { case SpeedMeasurementType.FeetPerSecond: { multiplier = 3.2808399; break; } case SpeedMeasurementType.KilometersPerHour: { multiplier = 3.6; break; } case SpeedMeasurementType.MilesPerHour: { multiplier = 2.23693629; break; } case SpeedMeasurementType.MetersPerSecond: default: { multiplier = 1.0; break; } } return multiplier*_fromValue; }
public static double ConvertSpeed(SpeedMeasurementType _fromType, SpeedMeasurementType _toType, double _fromValue) { if (_fromType == _toType) { return _fromValue; } double mpsValue = ConvertSpeedToMPS(_fromType, _fromValue); return ConvertSpeedFromMPS(_toType, mpsValue); }