public static CoordinateVi Average(CoordinateVi lhs, CoordinateVi rhs) { if (lhs.Direction != rhs.Direction) { return(null); } return(new CoordinateVi(lhs.Direction, (lhs.Degrees + rhs.Degrees) / 2, (lhs.Minutes + rhs.Minutes) / 2, (lhs.Seconds + rhs.Seconds) / 2)); }
public static void Part2() { Console.WriteLine("Частина 2"); var defaultInit = new CoordinateVi(); Console.WriteLine($"{nameof(defaultInit)} : {defaultInit} ; {defaultInit.ToDecimalString()}"); var latitude1 = new CoordinateVi(Direction.Latitude, 85, 23, 56); var latitude2 = new CoordinateVi(Direction.Latitude, -67, 11, 34); try { var invalidLatitude = new CoordinateVi(Direction.Latitude, 100, 84, 120); } catch (ArgumentOutOfRangeException e) { Console.WriteLine(e.Message); } Console.WriteLine($"{nameof(latitude1)} : {latitude1} ; {latitude1.ToDecimalString()}"); Console.WriteLine($"{nameof(latitude1)} : {latitude2} ; {latitude2.ToDecimalString()}"); var avgLatitude1 = latitude1.Average(latitude2); var avgLatitude2 = CoordinateVi.Average(latitude2, avgLatitude1); Console.WriteLine($"{nameof(avgLatitude1)} : {avgLatitude1} ; {avgLatitude1.ToDecimalString()}"); Console.WriteLine($"{nameof(avgLatitude2)} : {avgLatitude2} ; {avgLatitude2.ToDecimalString()}"); Console.WriteLine(); var longitude1 = new CoordinateVi(Direction.Longitude, -8, 28, 47); var longitude2 = new CoordinateVi(Direction.Longitude, 145, 32, 13); try { var invalidLongitude = new CoordinateVi(Direction.Longitude, 200, 84, 120); } catch (ArgumentOutOfRangeException e) { Console.WriteLine(e.Message); } Console.WriteLine($"{nameof(longitude1)} : {longitude1} ; {longitude1.ToDecimalString()}"); Console.WriteLine($"{nameof(longitude2)} : {longitude2} ; {longitude2.ToDecimalString()}"); var avgLongitude1 = longitude1.Average(longitude2); var avgLongitude2 = CoordinateVi.Average(longitude2, avgLongitude1); Console.WriteLine($"{nameof(avgLongitude1)} : {avgLongitude1} ; {avgLongitude1.ToDecimalString()}"); Console.WriteLine($"{nameof(avgLongitude2)} : {avgLongitude2} ; {avgLongitude2.ToDecimalString()}"); }
public CoordinateVi Average(CoordinateVi rhs) { return(Average(this, rhs)); }