Skip to content

Commit

Permalink
Add extent test for lineal geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
FObermaier committed Mar 19, 2024
1 parent 60cab58 commit 580ea72
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/NetTopologySuite.IO.VectorTiles.Mapbox/MapboxTileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@ private static IEnumerable<uint> Encode(ILineal lineal, TileGeometryTransform tg
for (int i = 0; i < geometry.NumGeometries; i++)
{
var lineString = (LineString)geometry.GetGeometryN(i);
foreach (uint encoded in Encode(lineString.CoordinateSequence, tgt, ref currentX, ref currentY, false))
yield return encoded;
if (tgt.IsGreaterThanOnePixelOfTile(lineString))
{
foreach (uint encoded in Encode(lineString.CoordinateSequence, tgt, ref currentX, ref currentY, false))
yield return encoded;
}
}
}

Expand Down Expand Up @@ -284,24 +287,25 @@ private static IEnumerable<uint> Encode(CoordinateSequence sequence, TileGeometr
// skipping the last point for rings since ClosePath is used instead
int count = ring ? sequence.Count - 1 : sequence.Count;

// In case we decide to ditch encoded data, we must reset currentX and currentY
int initialCurrentX = currentX;
int initialCurrentY = currentY;

// If the sequence is empty there is nothing we can do with it.
if (count == 0)
return Array.Empty<uint>();

// In case we decide to ditch encoded data, we must reset currentX and currentY
// or subsequent geometry items will not be positioned correctly.
int initialCurrentX = currentX;
int initialCurrentY = currentY;

// if we have a ring we need to check orientation
if (ring)
{
if (ccw != Algorithm.Orientation.IsCCW(sequence))
{
sequence = sequence.Copy();
CoordinateSequences.Reverse(sequence);
}
sequence = sequence.Reversed();
}
var encoded = new List<uint>

// provide encoded data buffer:
// 1 command + 2 parameter = 3 elements per coordinate
var encoded = new List<uint>(3 * count + (ring ? 1 : 0))
{
// Start point
GenerateCommandInteger(MapboxCommandType.MoveTo, 1)
Expand Down

0 comments on commit 580ea72

Please sign in to comment.