Skip to content

Commit

Permalink
Fixed issue with long shapes.
Browse files Browse the repository at this point in the history
  • Loading branch information
xivk committed Nov 16, 2023
1 parent 9b52155 commit e39e907
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Itinero.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!--- Package information, Version -->
<PropertyGroup>
<PackageVersion>2.0.0-alpha-091</PackageVersion>
<PackageVersion>2.0.1-alpha-092</PackageVersion>
<NeutralLanguage>en</NeutralLanguage>
<Description>Itinero - Routeplanning for .NET.</Description>
<Copyright>Itinero BV</Copyright>
Expand Down
14 changes: 7 additions & 7 deletions src/Itinero/Network/Tiles/NetworkTile.Geo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ private uint SetShape(IEnumerable<(double longitude, double latitude, float? e)>
}
}

count++;

if (count == 255)
{
// start a new block, assign 255.
Expand All @@ -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);
}
Expand All @@ -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++;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 39 additions & 1 deletion test/Itinero.Tests/Network/Tiles/NetworkTile.GeoTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using Itinero.Network.Tiles;
using Xunit;

Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit e39e907

Please sign in to comment.