public void TestGeoDistanceInRadians() { var d2r = Math.PI / 180.0; var pointA = new AVGeoPoint(); var pointB = new AVGeoPoint(); // Zero Assert.AreEqual(0.0, pointA.DistanceTo(pointB).Radians, 0.00001); Assert.AreEqual(0.0, pointB.DistanceTo(pointA).Radians, 0.00001); // Wrap Long pointA.Longitude = 179.0; pointB.Longitude = -179.0; Assert.AreEqual(2 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001); Assert.AreEqual(2 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001); // North South Lat pointA.Latitude = 89.0; pointA.Longitude = 0; pointB.Latitude = -89.0; pointB.Longitude = 0; Assert.AreEqual(178 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001); Assert.AreEqual(178 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001); // Long wrap Lat pointA.Latitude = 89.0; pointA.Longitude = 0; pointB.Latitude = -89.0; pointB.Longitude = 179.999; Assert.AreEqual(180 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001); Assert.AreEqual(180 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001); pointA.Latitude = 79.0; pointA.Longitude = 90.0; pointB.Latitude = -79.0; pointB.Longitude = -90.0; Assert.AreEqual(180 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001); Assert.AreEqual(180 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001); // Wrap near pole - somewhat ill conditioned case due to pole proximity pointA.Latitude = 85.0; pointA.Longitude = 90.0; pointB.Latitude = 85.0; pointB.Longitude = -90.0; Assert.AreEqual(10 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001); Assert.AreEqual(10 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001); // Reference cities // Sydney, Australia pointA.Latitude = -34.0; pointA.Longitude = 151.0; // Buenos Aires, Argentina pointB.Latitude = -34.5; pointB.Longitude = -58.35; Assert.AreEqual(1.85, pointA.DistanceTo(pointB).Radians, 0.01); Assert.AreEqual(1.85, pointB.DistanceTo(pointA).Radians, 0.01); }
public void TestEncodeParseGeoPoint() { AVGeoPoint point = new AVGeoPoint(3.22, 32.2); IDictionary <string, object> value = ParseEncoderTestClass.Instance.Encode(point) as IDictionary <string, object>; Assert.AreEqual("GeoPoint", value["__type"]); Assert.AreEqual(3.22, value["latitude"]); Assert.AreEqual(32.2, value["longitude"]); }
/// <summary> /// Deserialize the specified msgStr. /// </summary> /// <returns>The deserialize.</returns> /// <param name="msgStr">Message string.</param> public override IAVIMMessage Deserialize(string msgStr) { var msg = Json.Parse(msgStr) as IDictionary <string, object>; var locationData = msg[AVIMProtocol.LCLOC] as IDictionary <string, object>; if (locationData != null) { Location = new AVGeoPoint(double.Parse(locationData["latitude"].ToString()), double.Parse(locationData["longitude"].ToString())); } return(base.Deserialize(msgStr)); }
public void TestGeoPointConstructor() { var point = new AVGeoPoint(); Assert.AreEqual(0.0, point.Latitude); Assert.AreEqual(0.0, point.Longitude); point = new AVGeoPoint(42, 36); Assert.AreEqual(42.0, point.Latitude); Assert.AreEqual(36.0, point.Longitude); point.Latitude = 12; point.Longitude = 24; Assert.AreEqual(12.0, point.Latitude); Assert.AreEqual(24.0, point.Longitude); }
public void TestGeoPointCultureInvariantParsing() { var originalCulture = Thread.CurrentThread.CurrentCulture; foreach (var c in CultureInfo.GetCultures(CultureTypes.AllCultures)) { Thread.CurrentThread.CurrentCulture = c; var point = new AVGeoPoint(1.234, 1.234); var serialized = Json.Encode( new Dictionary <string, object> { { "point", NoObjectsEncoder.Instance.Encode(point) } }); var deserialized = AVDecoder.Instance.Decode(Json.Parse(serialized)) as IDictionary <string, object>; var pointAgain = (AVGeoPoint)deserialized["point"]; Assert.AreEqual(1.234, pointAgain.Latitude); Assert.AreEqual(1.234, pointAgain.Longitude); } }
public void TestDecodeGeoPoint() { IDictionary <string, object> value1 = new Dictionary <string, object>() { { "__type", "GeoPoint" }, { "latitude", 0.9 }, { "longitude", 0.3 } }; AVGeoPoint point1 = (AVGeoPoint)AVDecoder.Instance.Decode(value1); Assert.IsNotNull(point1); Assert.AreEqual(0.9, point1.Latitude); Assert.AreEqual(0.3, point1.Longitude); IDictionary <string, object> value2 = new Dictionary <string, object>() { { "__type", "GeoPoint" }, { "latitude", 0.9 } }; Assert.Throws <KeyNotFoundException>(() => AVDecoder.Instance.Decode(value2)); }
public AVIMLocationMessage(AVGeoPoint location) : this() { Location = location; }