Created
August 16, 2018 07:18
-
-
Save se5a/c23df23b8dd4edd53fd549b75c3e2649 to your computer and use it in GitHub Desktop.
Distance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// An experimental distance value struct. | |
| /// idea here was to simply define what a distance value was and handle very small or very large numbers equaly well. | |
| /// </summary> | |
| public struct DistanceValue | |
| { | |
| public enum ValueTypeEnum : sbyte//number of zeros. | |
| { | |
| NanoMeters = -9, | |
| MicroMeters = -6, | |
| MilliMeters = -3, | |
| CentiMeters = -2, | |
| DeciMeters = -1, | |
| Meters = 0, | |
| DecaMeters = 1, | |
| HectoMeters = 2, | |
| KeloMeters = 3, | |
| MegaMeters = 6, | |
| GigaMeters = 9, | |
| } | |
| public ValueTypeEnum ValueType; | |
| public double Value; | |
| public static double Convert(DistanceValue value, ValueTypeEnum convertTo) | |
| { | |
| int fval = (int)value.ValueType; //from | |
| int tval = (int)convertTo; //to | |
| return value.Value * Math.Pow(10, tval - fval); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment