Ejemplo n.º 1
0
        public Distance(string distance)
        {
            if (distance == null ||
                (distance != "-" && !distance.EndsWith("km") && !distance.EndsWith("AU") && !distance.EndsWith("AE") && !distance.EndsWith("m")))
            {
                throw new ArgumentException();
            }
            _hasDistance = distance != "-";
            if (!_hasDistance)
            {
                return;
            }

            string distanceValue;

            if (distance.TryStripFromEnd(" km", out distanceValue))
            {
                _distanceInKm = int.Parse(NormalizeNumber(distanceValue), CultureInfo.InvariantCulture);
                return;
            }
            if (distance.TryStripFromEnd(" m", out distanceValue))
            {
                _distanceInKm = int.Parse(NormalizeNumber(distanceValue), CultureInfo.InvariantCulture) / 1000;
                return;
            }
            if (distance.TryStripFromEnd(" AU", out distanceValue) || distance.TryStripFromEnd(" AE", out distanceValue))
            {
                var distanceInAU = distanceValue.ToDoubleNormalized();
                _distanceInKm = (long)UnitConverter.AUToKm(distanceInAU);
                return;
            }

            throw new ArgumentException();
        }
Ejemplo n.º 2
0
        public static long GetLowerBoundInKm(Distance distance)
        {
            if (distance.AUValue < 0.1)
            {
                return(Math.Max(distance.KmValue - 6000, 1000));
            }

            if (distance.KmValue < UnitConverter.AUToKm(0.15))
            {
                //the cut to 0.1 AU instead of km seems to be 10,000,000 km -> thank you Blue Katelo for finding out
                return(10000000);
            }

            return(distance.KmValue - POINT_FIVE_AU_IN_KM);
        }