Class to assist in autoranging chart axes or value displays. More...
Static Public Member Functions | |
| static double | GetSnapValue (double valueToSnap, bool snapIsGreater) |
| Calculates the closest member in the sequence (... 0.5, 1, 2, 5, 10, 20 ...) to any given value. | |
Class to assist in autoranging chart axes or value displays.
Definition at line 13 of file Autorange.cs.
| static double NewGamePhysics.Utilities.Autorange.GetSnapValue | ( | double | valueToSnap, | |
| bool | snapIsGreater | |||
| ) | [static] |
Calculates the closest member in the sequence (... 0.5, 1, 2, 5, 10, 20 ...) to any given value.
| valueToSnap | The value to check. | |
| snapIsGreater | If true, the snap value is numerically greater than value; or less if false. |
Definition at line 23 of file Autorange.cs.
00024 { 00025 // Value range factors for positive numbers in sequence. 00026 double[] factorsP = { 1.0, 2.0, 5.0, 10.0 }; 00027 00028 // Value range factors for negative numbers in sequence. 00029 double[] factorsN = { 10.0, 5.0, 2.0, 1.0 }; 00030 00031 // Determine factor for input 00032 double[] factors; 00033 if (valueToSnap != 0.0) 00034 { 00035 bool isPositive = (valueToSnap > 0.0); 00036 double exponent = Math.Floor(Math.Log10(Math.Abs(valueToSnap))); 00037 double valueBase = Math.Pow(10, exponent); 00038 00039 if (isPositive) 00040 { 00041 factors = factorsP; 00042 } 00043 else 00044 { 00045 factors = factorsN; 00046 valueBase = -valueBase; 00047 } 00048 00049 factors[0] *= valueBase; 00050 for (int i = 1; i < 4; i++) 00051 { 00052 factors[i] *= valueBase; 00053 if (factors[i] >= valueToSnap) 00054 { 00055 if (snapIsGreater) 00056 { 00057 return factors[i]; 00058 } 00059 else 00060 { 00061 return factors[i - 1]; 00062 } 00063 } 00064 } 00065 } 00066 00067 // Default 00068 return 0.0; 00069 }
1.6.2