/// <summary> /// Tests routing from a serialized routing file. /// </summary> /// <param name="name"></param> /// <param name="stream"></param> /// <param name="box"></param> /// <param name="testCount"></param> public static void TestSerializedRouting(string name, Stream stream, GeoCoordinateBox box, int testCount) { var router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream), new OsmRoutingInterpreter()); var performanceInfo = new PerformanceInfoConsumer("LiveRouting"); performanceInfo.Start(); performanceInfo.Report("Routing {0} routes...", testCount); int successCount = 0; int totalCount = testCount; float latestProgress = -1; while (testCount > 0) { var from = box.GenerateRandomIn(); var to = box.GenerateRandomIn(); var fromPoint = router.Resolve(Vehicle.Car, from); var toPoint = router.Resolve(Vehicle.Car, to); if (fromPoint != null && toPoint != null) { var route = router.Calculate(Vehicle.Car, fromPoint, toPoint); if (route != null) { successCount++; } } testCount--; // report progress. float progress = (float)System.Math.Round(((double)(totalCount - testCount) / (double)totalCount) * 100); if (progress != latestProgress) { OsmSharp.Logging.Log.TraceEvent("LiveEdgePreprocessor", TraceEventType.Information, "Routing... {0}%", progress); latestProgress = progress; } } performanceInfo.Stop(); OsmSharp.Logging.Log.TraceEvent("LiveRouting", OsmSharp.Logging.TraceEventType.Information, string.Format("{0}/{1} routes successfull!", successCount, totalCount)); }
void AddMarkers() { var from = new GeoCoordinate(51.261203, 4.780760); var to = new GeoCoordinate(51.267797, 4.801362); var box = new GeoCoordinateBox(from, to); _mapView.ClearMarkers(); MapMarker marker; for (int idx = 0; idx < 20; idx++) { var pos = box.GenerateRandomIn(); marker = new MapMarker(this, pos, MapControlAlignmentType.CenterBottom, this.Resources, Resource.Drawable.marker); var popupView = marker.AddNewPopup(300, 300); var textView = new TextView(this.ApplicationContext); textView.Text = "Some popup text here."; textView.TextSize = 10; textView.SetTextColor(global::Android.Graphics.Color.Black); popupView.AddView(textView); _mapView.AddMarker(marker); } }
/// <summary> /// Tests routing within a bounding box. /// </summary> /// <param name="router"></param> /// <param name="box"></param> /// <param name="testCount"></param> public static void TestRouting(Router router, GeoCoordinateBox box, int testCount) { var performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting"); performanceInfo.Start(); performanceInfo.Report("Routing {0} routes: Resolving...", testCount); int successCount = 0; int totalCount = testCount; var resolvedPoints = new List <RouterPoint>(); while (testCount > 0) { var from = box.GenerateRandomIn(); var to = box.GenerateRandomIn(); var fromPoint = router.Resolve(Vehicle.Car, from); var toPoint = router.Resolve(Vehicle.Car, to); resolvedPoints.Add(fromPoint); resolvedPoints.Add(toPoint); testCount--; } performanceInfo.Stop(); performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting"); performanceInfo.Start(); performanceInfo.Report("Routing {0} routes: Routing...", testCount); for (int idx = 0; idx < resolvedPoints.Count; idx = idx + 2) { var fromPoint = resolvedPoints[idx]; var toPoint = resolvedPoints[idx + 1]; if (fromPoint != null && toPoint != null) { var route = router.Calculate(Vehicle.Car, fromPoint, toPoint, float.MaxValue, true); if (route != null) { successCount++; } } } performanceInfo.Stop(); OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information, string.Format("{0}/{1} routes successfull!", successCount, totalCount)); }
/// <summary> /// Tests routing from a serialized routing file. /// </summary> /// <param name="name"></param> /// <param name="stream"></param> /// <param name="box"></param> /// <param name="testCount"></param> public static void TestSerializedRouting(string name, Stream stream, GeoCoordinateBox box, int testCount) { PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting"); performanceInfo.Start(); performanceInfo.Report("Routing {0} routes...", testCount); TagsCollectionBase metaData = null; var routingSerializer = new CHEdgeDataDataSourceSerializer(); var graphDeserialized = routingSerializer.Deserialize( stream, out metaData, true); var router = Router.CreateCHFrom( graphDeserialized, new CHRouter(), new OsmRoutingInterpreter()); int successCount = 0; int totalCount = testCount; while (testCount > 0) { GeoCoordinate from = box.GenerateRandomIn(); GeoCoordinate to = box.GenerateRandomIn(); RouterPoint fromPoint = router.Resolve(Vehicle.Car, from); RouterPoint toPoint = router.Resolve(Vehicle.Car, to); if (fromPoint != null && toPoint != null) { Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint, float.MaxValue, true); if (route != null) { successCount++; } } testCount--; } performanceInfo.Stop(); OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information, string.Format("{0}/{1} routes successfull!", successCount, totalCount)); }
public static void TestResolved(RouterDataSource <CHEdgeData> data, int testCount, GeoCoordinateBox box) { var router = Router.CreateCHFrom(data, new CHRouter(), new OsmRoutingInterpreter()); var performanceInfo = new PerformanceInfoConsumer("CHRouting"); performanceInfo.Start(); performanceInfo.Report("Routing {0} routes...", testCount); var successCount = 0; var totalCount = testCount; var latestProgress = -1.0f; while (testCount > 0) { var from = box.GenerateRandomIn(); var to = box.GenerateRandomIn(); var fromPoint = router.Resolve(Vehicle.Car, from); var toPoint = router.Resolve(Vehicle.Car, to); if (fromPoint != null && toPoint != null) { var route = router.Calculate(Vehicle.Car, fromPoint, toPoint); if (route != null) { successCount++; } } testCount--; // report progress. var progress = (float)System.Math.Round(((double)(totalCount - testCount) / (double)totalCount) * 100); if (progress != latestProgress) { OsmSharp.Logging.Log.TraceEvent("CHRouting", TraceEventType.Information, "Routing... {0}%", progress); latestProgress = progress; } } performanceInfo.Stop(); OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information, string.Format("{0}/{1} routes successfull!", successCount, totalCount)); }
/// <summary> /// Tests routing from a serialized routing file. /// </summary> /// <param name="data"></param> /// <param name="box"></param> /// <param name="testCount"></param> public static void TestSerializedResolved(RouterDataSource <CHEdgeData> data, GeoCoordinateBox box, int testCount = 100) { var successCount = 0; var totalCount = testCount; var router = Router.CreateCHFrom(data, new CHRouter(), new OsmRoutingInterpreter()); var performanceInfo = new PerformanceInfoConsumer("CHRouting"); performanceInfo.Start(); performanceInfo.Report("Routing {0} routes...", testCount); while (testCount > 0) { var point1 = router.Resolve(Vehicle.Car, box.GenerateRandomIn()); var point2 = router.Resolve(Vehicle.Car, box.GenerateRandomIn()); Route route = null; if (point1 != null && point2 != null) { route = router.Calculate(Vehicle.Car, point1, point2); } if (route != null) { successCount++; } testCount--; } performanceInfo.Stop(); OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information, string.Format("{0}/{1} routes successfull!", successCount, totalCount)); }
/// <summary> /// Tests rendering the given serialized scene. /// </summary> /// <param name="stream"></param> /// <param name="box"></param> /// <param name="testCount"></param> /// <param name="createTarget"></param> /// <param name="createRenderer"></param> /// <param name="range"></param> /// <param name="minZoom"></param> public static void TestRenderScene(CreateTarget createTarget, CreateRenderer createRenderer, Stream stream, GeoCoordinateBox box, int testCount, int range, int minZoom) { WebMercator projection = new WebMercator(); // build a map. Map map = new Map(); TagsCollectionBase metaTags; map.AddLayer(new LayerScene( Scene2D.Deserialize(stream, true, out metaTags))); // build the target and renderer. TTarget target = createTarget.Invoke(TargetWidth, TargetHeight); MapRenderer <TTarget> mapRenderer = new MapRenderer <TTarget>( createRenderer.Invoke()); // render the map. PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("Scene2DLayeredRendering"); performanceInfo.Start(); //performanceInfo.Report("Rendering {0} random images...", testCount); while (testCount > 0) { // randomize view. int zoom = minZoom; if (range > 1) { // only randomize when range is > 1 zoom = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(range) + minZoom; } GeoCoordinate center = box.GenerateRandomIn(); View2D view = mapRenderer.Create(TargetWidth, TargetHeight, map, (float)projection.ToZoomFactor(zoom), center, false, true); OsmSharp.Logging.Log.TraceEvent("Scene2DLayeredRendering", OsmSharp.Logging.TraceEventType.Information, string.Format("Rendering at z{0} l{1}.", zoom, center)); map.ViewChanged((float)projection.ToZoomFactor(zoom), center, view, view); mapRenderer.Render(target, map, view, (float)projection.ToZoomFactor(zoom)); testCount--; } performanceInfo.Stop(); stream.Seek(0, SeekOrigin.Begin); }
public void TestTrim() { OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346); var box = new GeoCoordinateBox( new GeoCoordinate(90, 180), new GeoCoordinate(-90, -180)); var size = 100; var maxCollectionSize = 4; var referenceDictionary = new Dictionary <long, ICoordinateCollection>(); var coordinates = new HugeCoordinateCollectionIndex(400); for (int idx = 0; idx < size; idx++) { var currentSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1; var coordinatesArray = new GeoCoordinate[currentSize]; while (currentSize > 0) { coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get()); currentSize--; } var coordinatesCollection = new CoordinateArrayCollection <GeoCoordinate>(coordinatesArray); referenceDictionary[idx] = coordinatesCollection; coordinates[idx] = coordinatesCollection; } // execute the trim. coordinates.Trim(); // check result. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } }
void AddMarkers() { var from = new GeoCoordinate(51.261203, 4.780760); var to = new GeoCoordinate(51.267797, 4.801362); var box = new GeoCoordinateBox(from, to); _mapView.ClearMarkers(); MapMarker marker; for (int idx = 0; idx < 20; idx++) { var pos = box.GenerateRandomIn(); marker = _mapView.AddMarker(pos); var popupTextView = new UITextView(); popupTextView.Text = "Hey, this is popup text!"; popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f); marker.AddPopup(popupTextView, 100, 100); } }
public void Scene2DSimpleSerializeDeserializeTest() { // create the MapCSS image source. var imageSource = new MapCSSDictionaryImageSource(); // load mapcss style interpreter. var mapCSSInterpreter = new MapCSSInterpreter( Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.UI.Test.Unittests.Data.MapCSS.test.mapcss"), imageSource); // initialize the data source. var xmlSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.UI.Test.Unittests.Data.test.osm")); IEnumerable <OsmGeo> dataSource = xmlSource; MemoryDataSource source = MemoryDataSource.CreateFrom(xmlSource); // get data. var scene = new Scene2DSimple(); var projection = new WebMercator(); GeoCoordinateBox box = null; foreach (var osmGeo in dataSource) { CompleteOsmGeo completeOsmGeo = null; switch (osmGeo.Type) { case OsmGeoType.Node: completeOsmGeo = CompleteNode.CreateFrom(osmGeo as Node); break; case OsmGeoType.Way: completeOsmGeo = CompleteWay.CreateFrom(osmGeo as Way, source); break; case OsmGeoType.Relation: completeOsmGeo = CompleteRelation.CreateFrom(osmGeo as Relation, source); break; } // update box. if (completeOsmGeo != null) { if (box == null) { box = completeOsmGeo.BoundingBox; } else if (completeOsmGeo.BoundingBox != null) { box = box + completeOsmGeo.BoundingBox; } } // translate each object into scene object. mapCSSInterpreter.Translate(scene, projection, source, osmGeo as OsmGeo); } // create the stream. var stream = new MemoryStream(); scene.Serialize(stream, false); // deserialize the stream. IScene2DPrimitivesSource sceneSource = Scene2DSimple.Deserialize(stream, false); if (box != null) { // query both and get the same results. int counter = 100; var rand = new Random(); while (counter > 0) { var queryBox = new GeoCoordinateBox( box.GenerateRandomIn(rand), box.GenerateRandomIn(rand)); var zoomFactor = (float)projection.ToZoomFactor(15); View2D testView = View2D.CreateFromBounds( projection.LatitudeToY(queryBox.MaxLat), projection.LongitudeToX(queryBox.MinLon), projection.LatitudeToY(queryBox.MinLat), projection.LongitudeToX(queryBox.MaxLon)); var testScene = new Scene2DSimple(); sceneSource.Get(testScene, testView, zoomFactor); // var resultIndex = new HashSet<Scene2DPrimitive>(testScene.Get(testView, zoomFactor)); // var resultReference = new HashSet<Scene2DPrimitive>(scene.Get(testView, zoomFactor)); //Assert.AreEqual(resultReference.Count, resultIndex.Count); //foreach (var data in resultIndex) //{ // Assert.IsTrue(resultReference.Contains(data)); //} //foreach (var data in resultReference) //{ // Assert.IsTrue(resultIndex.Contains(data)); //} counter--; } } }
/// <summary> /// Tests adding a lot of random data. /// </summary> /// <param name="count"></param> public void DoTestAddingRandom(int count) { ILocatedObjectIndex<GeoCoordinate, LocatedObjectData> index = this.CreateIndex(); GeoCoordinateBox box = new GeoCoordinateBox(new GeoCoordinate(50, 3), new GeoCoordinate(40, 2)); HashSet<GeoCoordinate> locations = new HashSet<GeoCoordinate>(); Random random = new Random(); while (count > 0) { GeoCoordinate location = box.GenerateRandomIn(random); LocatedObjectData data = new LocatedObjectData() { SomeData = location.ToString() }; locations.Add(location); index.Add(location, data); // try immidiately after. GeoCoordinateBox location_box = new GeoCoordinateBox( new GeoCoordinate(location.Latitude - 0.0001, location.Longitude - 0.0001), new GeoCoordinate(location.Latitude + 0.0001, location.Longitude + 0.0001)); IEnumerable<LocatedObjectData> location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); bool found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == location.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", location, location_box)); count--; } foreach (GeoCoordinate location in locations) { GeoCoordinateBox location_box = new GeoCoordinateBox( new GeoCoordinate(location.Latitude - 0.0001, location.Longitude - 0.0001), new GeoCoordinate(location.Latitude + 0.0001, location.Longitude + 0.0001)); IEnumerable<LocatedObjectData> location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); bool found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == location.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", location, location_box)); } }
public void TestSwitch() { OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346); var box = new GeoCoordinateBox( new GeoCoordinate(90, 180), new GeoCoordinate(-90, -180)); var size = 100; var maxCollectionSize = 4; var referenceDictionary = new Dictionary <long, ICoordinateCollection>(); var coordinates = new HugeCoordinateCollectionIndex(400); for (int idx = 0; idx < size; idx++) { var currentSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1; var coordinatesArray = new GeoCoordinate[currentSize]; while (currentSize > 0) { coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get()); currentSize--; } var coordinatesCollection = new CoordinateArrayCollection <GeoCoordinate>(coordinatesArray); referenceDictionary[idx] = coordinatesCollection; coordinates[idx] = coordinatesCollection; } // generate a sequence of two id's and switch. for (var i = 0; i < 20; i++) { var id1 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(size); var id2 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(size - 1); if (id1 <= id2) { id2++; } var temp = referenceDictionary[id1]; referenceDictionary[id1] = referenceDictionary[id2]; referenceDictionary[id2] = temp; coordinates.Switch(id1, id2); } // check result. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } }
public void TestSerialize() { OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346); var box = new GeoCoordinateBox( new GeoCoordinate(90, 180), new GeoCoordinate(-90, -180)); var size = 5; var maxCollectionSize = 4; var referenceDictionary = new Dictionary <long, ICoordinateCollection>(); var coordinates = new HugeCoordinateCollectionIndex(100); for (int idx = 0; idx < size; idx++) { var currentSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1; var coordinatesArray = new GeoCoordinate[currentSize]; while (currentSize > 0) { coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get()); currentSize--; } var coordinatesCollection = new CoordinateArrayCollection <GeoCoordinate>(coordinatesArray); referenceDictionary[idx] = coordinatesCollection; coordinates[idx] = coordinatesCollection; } coordinates.Trim(); coordinates.Compress(); byte[] data = null; using (var stream = new MemoryStream()) { long length = coordinates.Serialize(stream); data = stream.ToArray(); Assert.AreEqual(168, length); Assert.AreEqual(data.Length, length); } var result = HugeCoordinateCollectionIndex.Deserialize(new MemoryStream(data)); // check result. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = result[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } result = HugeCoordinateCollectionIndex.Deserialize(new MemoryStream(data), true); // check result. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = result[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } }
/// <summary> /// Tests adding a lot of random data. /// </summary> /// <param name="count"></param> public void DoTestAddingRandom(int count) { ILocatedObjectIndex <GeoCoordinate, LocatedObjectData> index = this.CreateIndex(); GeoCoordinateBox box = new GeoCoordinateBox(new GeoCoordinate(50, 3), new GeoCoordinate(40, 2)); HashSet <GeoCoordinate> locations = new HashSet <GeoCoordinate>(); Random random = new Random(); while (count > 0) { GeoCoordinate location = box.GenerateRandomIn(random); LocatedObjectData data = new LocatedObjectData() { SomeData = location.ToString() }; locations.Add(location); index.Add(location, data); // try immidiately after. GeoCoordinateBox location_box = new GeoCoordinateBox( new GeoCoordinate(location.Latitude - 0.0001, location.Longitude - 0.0001), new GeoCoordinate(location.Latitude + 0.0001, location.Longitude + 0.0001)); IEnumerable <LocatedObjectData> location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); bool found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == location.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", location, location_box)); count--; } foreach (GeoCoordinate location in locations) { GeoCoordinateBox location_box = new GeoCoordinateBox( new GeoCoordinate(location.Latitude - 0.0001, location.Longitude - 0.0001), new GeoCoordinate(location.Latitude + 0.0001, location.Longitude + 0.0001)); IEnumerable <LocatedObjectData> location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); bool found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == location.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", location, location_box)); } }
public void TestHugeCoordinateCollectionIndexSmall() { OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346); var box = new GeoCoordinateBox( new GeoCoordinate(90, 180), new GeoCoordinate(-90, -180)); var size = 100; var maxCollectionSize = 4; var referenceDictionary = new Dictionary <long, ICoordinateCollection>(); var coordinates = new HugeCoordinateCollectionIndex(400); for (int idx = 0; idx < size; idx++) { var currentSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1; var coordinatesArray = new GeoCoordinate[currentSize]; while (currentSize > 0) { coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get()); currentSize--; } var coordinatesCollection = new CoordinateArrayCollection <GeoCoordinate>(coordinatesArray); referenceDictionary[idx] = coordinatesCollection; coordinates[idx] = coordinatesCollection; } // check result. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } // generate new randoms. for (int idx = 0; idx < size; idx++) { var currentSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1; var coordinatesArray = new GeoCoordinate[currentSize]; while (currentSize > 0) { coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get()); currentSize--; } var coordinatesCollection = new CoordinateArrayCollection <GeoCoordinate>(coordinatesArray); referenceDictionary[idx] = coordinatesCollection; coordinates[idx] = coordinatesCollection; var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } // check again. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } // randomly remove stuff. for (int idx = 0; idx < size; idx++) { if (OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) > 1) { referenceDictionary[idx] = null; coordinates[idx] = null; } } // check again. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; if (referenceCollection == null) { Assert.IsNull(collection); } else { referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } } // generate new randoms. for (int idx = 0; idx < size; idx++) { var currentSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1; var coordinatesArray = new GeoCoordinate[currentSize]; while (currentSize > 0) { coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get()); currentSize--; } var coordinatesCollection = new CoordinateArrayCollection <GeoCoordinate>(coordinatesArray); referenceDictionary[idx] = coordinatesCollection; coordinates[idx] = coordinatesCollection; var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } // check again. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = coordinates[idx]; referenceCollection.Reset(); collection.Reset(); while (referenceCollection.MoveNext()) { Assert.IsTrue(collection.MoveNext()); Assert.AreEqual(referenceCollection.Latitude, collection.Latitude); Assert.AreEqual(referenceCollection.Longitude, collection.Longitude); } Assert.IsFalse(collection.MoveNext()); } }