namespace Plane.Geography { public static class LocationExtensions { /// /// 计算在二维平面上从 的方向,单位为弧度。 /// /// 出发点。 /// 目标点。 /// 点 1 到点 2 的方向。 public static double CalcDirection2D(this ILocation2D l1, ILocation2D l2) => GeographyUtils.CalcDirection2D(l1.Latitude, l1.Longitude, l2.Latitude, l2.Longitude); /// /// 计算在二维平面上从 到 (, ) 的方向,单位为弧度。 /// /// 出发点。 /// 目标点的纬度。 /// 目标点的经度。 /// 点 1 到点 2 的方向。 public static double CalcDirection2D(this ILocation2D l1, double lat2, double lng2) => GeographyUtils.CalcDirection2D(l1.Latitude, l1.Longitude, lat2, lng2); /// /// 计算空间中两点间的距离,单位为米。 /// /// 点 1。 /// 点 2。 /// 空间中两点间的距离。 public static double CalcDistance(this ILocation l1, ILocation l2) => GeographyUtils.CalcDistance(l1, l2); /// /// 计算空间中两点间的距离,单位为米。 /// /// 点 1。 /// 点 2 的纬度。 /// 点 2 的经度。 /// 点 2 的高度。 /// 空间中两点间的距离。 public static double CalcDistance(this ILocation l1, double lat2, double lng2, double alt2) => GeographyUtils.CalcDistance(l1.Latitude, l1.Longitude, l1.Altitude, lat2, lng2, alt2); /// /// 计算二维平面上两个位置之间的距离,单位为米。 /// /// 位置 1。 /// 位置 2。 /// 平面上两点间的距离。 public static double CalcDistance2D(this ILocation2D l1, ILocation2D l2) => GeographyUtils.CalcDistance2D(l1, l2); /// /// 计算二维平面上两个位置之间的距离,单位为米。 /// /// 点 2 的纬度。 /// 点 2 的经度。 /// 平面上两点间的距离。 public static double CalcDistance2D(this ILocation2D l1, double lat2, double lng2) => GeographyUtils.CalcDistance2D(l1.Latitude, l1.Longitude, lat2, lng2); /// /// 计算在水平面上从指定点往指定方向移动指定距离后所在的点。 /// /// 出发点。 /// 移动方向,单位为角度。 /// 移动距离。 /// 从指定点往指定方向移动指定距离后所在的点。 public static ILocation2D CalcLatLngSomeMetersAway2D(this ILocation2D loc1, float directionDegrees, float distance) => GeographyUtils.CalcLatLngSomeMetersAway2D(loc1, directionDegrees, distance); /// /// 判断一个 实例是否被认为是空值。 /// /// 实例。 /// 若给定的位置被认为是空值,返回 true;否则返回 false。 public static bool IsNullOrEmpty(this ILocation loc) => loc == null || (loc.Latitude == 0 && loc.Longitude == 0 && loc.Altitude == 0); } }