diff --git a/Itinero.Common.props b/Itinero.Common.props index 2351caf5d..298cc1f46 100644 --- a/Itinero.Common.props +++ b/Itinero.Common.props @@ -3,7 +3,7 @@ - 2.0.0-alpha-091 + 2.0.1-alpha-092 en Itinero - Routeplanning for .NET. Itinero BV diff --git a/src/Itinero/Network/Tiles/NetworkTile.Geo.cs b/src/Itinero/Network/Tiles/NetworkTile.Geo.cs index 6ed1e8059..a044cd6b3 100644 --- a/src/Itinero/Network/Tiles/NetworkTile.Geo.cs +++ b/src/Itinero/Network/Tiles/NetworkTile.Geo.cs @@ -163,6 +163,8 @@ private uint SetShape(IEnumerable<(double longitude, double latitude, float? e)> } } + count++; + if (count == 255) { // start a new block, assign 255. @@ -171,10 +173,6 @@ private uint SetShape(IEnumerable<(double longitude, double latitude, float? e)> pointer = blockPointer + 1; count = 0; } - else - { - count++; - } previous = (x, y, eOffset); } @@ -198,7 +196,7 @@ private uint SetShape(IEnumerable<(double longitude, double latitude, float? e)> const int resolution = (1 << TileResolutionInBits) - 1; var count = -1; (int x, int y, int? eOffset) previous = (int.MaxValue, int.MaxValue, null); - do + while (true) { count = _shapes[p]; p++; @@ -214,7 +212,7 @@ private uint SetShape(IEnumerable<(double longitude, double latitude, float? e)> eOffset = e; } - if (previous.x != int.MaxValue) + if (i > 0) { x = previous.x + x; y = previous.y + y; @@ -246,7 +244,9 @@ private uint SetShape(IEnumerable<(double longitude, double latitude, float? e)> previous = (x, y, eOffset); } - } while (count == 255); + + if (count < 255) break; + } } private void WriteGeoTo(Stream stream) diff --git a/test/Itinero.Tests/Network/Tiles/NetworkTile.GeoTests.cs b/test/Itinero.Tests/Network/Tiles/NetworkTile.GeoTests.cs index 693c8ff4d..fab2e37d3 100644 --- a/test/Itinero.Tests/Network/Tiles/NetworkTile.GeoTests.cs +++ b/test/Itinero.Tests/Network/Tiles/NetworkTile.GeoTests.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using Itinero.Network.Tiles; using Xunit; @@ -192,4 +193,41 @@ public void NetworkTile_AddEdge0_ThreeShapePoints_Elevation_ShouldStoreElevation Assert.NotNull(shapePoint.e); Assert.Equal(109f, shapePoint.e.Value); } + + [Fact] + public void NetworkTile_AddEdge0_256ShapePoint_ShouldStore256ShapePoints() + { + var graphTile = new NetworkTile(14, + TileStatic.ToLocalId(4.86638, 51.269728, 14)); + var vertex1 = graphTile.AddVertex(4.86638, 51.269728); + var vertex2 = graphTile.AddVertex(4.86737, 51.267849); + + var shapePoints = new List<(double longitude, double latitude, float? e)> + { + (4.86786, + 51.26909, (float?) null) + }; + while (shapePoints.Count < 265) + { + var last = shapePoints[^1]; + shapePoints.Add((last.longitude + 0.001, last.latitude + 0.001, null)); + } + + var edge = graphTile.AddEdge(vertex1, vertex2, shapePoints); + + var enumerator = new NetworkTileEnumerator(); + enumerator.MoveTo(graphTile); + Assert.True(enumerator.MoveTo(edge, true)); + var shapes = enumerator.Shape.ToList(); + Assert.NotNull(shapes); + Assert.Equal(shapePoints.Count, shapes.Count); + for (var i = 0; i < shapePoints.Count; i++) + { + var ex = shapePoints[i]; + var ac = shapes[i]; + Assert.Equal(ex.longitude, ac.longitude, 4); + Assert.Equal(ex.latitude, ac.latitude, 4); + Assert.Null(ac.e); + } + } }