Skip to content

Commit

Permalink
Fixed obscure issue when lon/lat diff are exactly the same.
Browse files Browse the repository at this point in the history
  • Loading branch information
xivk committed Nov 14, 2023
1 parent 3068c12 commit 1fbb921
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion NetTopologySuite.IO.VectorTiles.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>latest</LangVersion>
<Authors>NetTopologySuite - Team</Authors>
<Owners>NetTopologySuite - Team</Owners>
<PackageVersion>1.0.2</PackageVersion>
<PackageVersion>1.0.3</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/NetTopologySuite/NetTopologySuite.IO.VectorTiles</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
Expand Down
16 changes: 8 additions & 8 deletions src/NetTopologySuite.IO.VectorTiles/Tilers/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ internal static class Shared
{
double xDiff = x2 - x1;
double yDiff = y2 - y1;
if (Math.Abs(xDiff) <= double.Epsilon &&

if (Math.Abs(xDiff) <= double.Epsilon &&
Math.Abs(yDiff) <= double.Epsilon) yield break;
if (Math.Abs(xDiff) > Math.Abs(yDiff))

if (Math.Abs(xDiff) >= Math.Abs(yDiff))
{ // we take x as denominator.
int yPrevious = (int)Math.Floor(y1);
int xPrevious = (int)Math.Floor(x1);
int xLast = (int) Math.Floor(x2);
int yLast = (int) Math.Floor(y2);

double slope = (yDiff / xDiff);
double y0 = y1 - (slope * x1);

// with an increment of 1 we calculate y.
bool right = xDiff > 0;
// var up = (yDiff > 0);
Expand All @@ -42,12 +42,12 @@ internal static class Shared
yield return (xPrevious, yPrevious);
for (int x = start; x != end + xStep; x += xStep)
{
// REMARK: this can be more efficient but this way numerically more stable.
// REMARK: this can be more efficient but this way numerically more stable.
// we prefer correctness over performance here.
// calculate next y.
double y = x * slope + y0;
int yRounded = (int)Math.Floor(y);

if (yPrevious != yRounded)
{
// we have moved to a new y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void LineStringTiler_Cut_LineString_CutAt21_ShouldBeCutIn0OrMore()
}
}
}

[Fact]
public void LineStringTiler_Cut_LineString_CutAt22_ShouldBeCutIn0OrMore()
{
Expand Down Expand Up @@ -200,13 +200,28 @@ public void LineStringTiler_Tiles_LineStringInMultipleTiles_Zoom13_ShouldBeInEac
});

var tiles = lineString.Tiles(13).ToList();

Assert.Equal(5, tiles.Count);
Assert.Equal(44869043UL, tiles[0]);
Assert.Equal(44860851UL, tiles[1]);
Assert.Equal(44860852UL, tiles[2]);
Assert.Equal(44852660UL, tiles[3]);
Assert.Equal(44852661UL, tiles[4]);
}

[Fact]
public void LineStringTile_Tiles_Regression_ExactLonLatDiff_Zoom14_ShouldReturnTiles()
{
var reader = new WKTReader();
var lineString =
reader.Read(
"LINESTRING (-61.122810782967036 -34.2440222744931, -61.144767342032964 -34.225843342865723)")
as
LineString;


var tiles = lineString.Tiles(14).ToList();

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.

Check warning on line 223 in test/NetTopologySuite.IO.VectorTiles.Tests/Tilers/LineStringTilerTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference argument for parameter 'lineString' in 'IEnumerable<ulong> LineStringTiler.Tiles(LineString lineString, int zoom)'.
Assert.NotEmpty(tiles);
}
}
}

0 comments on commit 1fbb921

Please sign in to comment.