GetDistance() public method

public GetDistance ( Location other ) : double
other Location
return double
Esempio n. 1
0
        public static double GetTotalDistance(Location startLocation, Location[] locations)
        {
            if (startLocation == null)
                throw new ArgumentNullException("startLocation");

            if (locations == null)
                throw new ArgumentNullException("locations");

            if (locations.Length == 0)
                throw new ArgumentException("The locations array must have at least one element.", "locations");

            foreach(var location in locations)
                if (location == null)
                    throw new ArgumentException("The locations array can't contain null values.");

            double result = startLocation.GetDistance(locations[0]);
            int countLess1 = locations.Length-1;
            for(int i=0; i<countLess1; i++)
            {
                var actual = locations[i];
                var next = locations[i+1];

                var distance = actual.GetDistance(next);
                result += distance;
            }

            result += locations[locations.Length-1].GetDistance(startLocation);

            return result;
        }
Esempio n. 2
0
        public static double GetTotalDistance(Location startLocation, Location[] locations)
        {
            if (startLocation == null)
            {
                throw new ArgumentNullException("startLocation");
            }

            if (locations == null)
            {
                throw new ArgumentNullException("locations");
            }

            if (locations.Length == 0)
            {
                throw new ArgumentException("The locations array must have at least one element.", "locations");
            }

            foreach (var location in locations)
            {
                if (location == null)
                {
                    throw new ArgumentException("The locations array can't contain null values.");
                }
            }

            double result     = startLocation.GetDistance(locations[0]);
            int    countLess1 = locations.Length - 1;

            for (int i = 0; i < countLess1; i++)
            {
                var actual = locations[i];
                var next   = locations[i + 1];

                var distance = actual.GetDistance(next);
                result += distance;
            }

            result += locations[locations.Length - 1].GetDistance(startLocation);

            return(result);
        }