Skip to content

Commit

Permalink
Fixed tiles under line for when vertical up.
Browse files Browse the repository at this point in the history
  • Loading branch information
xivk committed Sep 26, 2023
1 parent 85439bf commit d1d796b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/TilesMath/TileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static IEnumerable<Tile> EnumerateTilesForLineSegment((double longitude,
var a = (point2.latitude - point1.latitude) / (point2.longitude - point1.longitude);
var b = 0.0;

var isMoreVertical = a > 0.5;
var isMoreVertical = a > 0.5 || a < -0.5;
if (isMoreVertical)
{
a = (point2.longitude - point1.longitude) / (point2.latitude - point1.latitude);
Expand Down
2 changes: 1 addition & 1 deletion src/TilesMath/TilesMath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageVersion>0.0.5</PackageVersion>
<PackageVersion>0.0.6</PackageVersion>
<Title>TilesMath</Title>
<Authors>ANYWAYS BV</Authors>
<Description>A tiny library for tiles math.</Description>
Expand Down
22 changes: 21 additions & 1 deletion test/TilesMath.Tests/TileStaticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Tile_BetweenLine_WhenLineHorizontal_TwoTileHop_ShouldEnumerateThreeT
}

[Fact]
public void Tile_BetweenLine_WhenLineVertical_OneTileHop_ShouldEnumerateTwoTiles()
public void Tile_BetweenLine_WhenLineVertical_OneTileHopDown_ShouldEnumerateTwoTiles()
{
var tiles = Tile.BelowLine(new (double longitude, double latitude)[]
{
Expand All @@ -82,6 +82,26 @@ public void Tile_BetweenLine_WhenLineVertical_OneTileHop_ShouldEnumerateTwoTiles
Assert.Equal(5465, tiles[1].Y);
}

[Fact]
public void Tile_BetweenLine_WhenLineVertical_OneTileHopUp_ShouldEnumerateTwoTiles()
{
var tiles = Tile.BelowLine(new (double longitude, double latitude)[]
{
(4.802056351009384,
51.267307188009435),
(4.802056351009384,
51.257307188009435)
}, 14).ToList();

Assert.Equal(2, tiles.Count);
Assert.Equal(14, tiles[0].Zoom);
Assert.Equal(8410, tiles[0].X);
Assert.Equal(5465, tiles[0].Y);
Assert.Equal(14, tiles[1].Zoom);
Assert.Equal(8410, tiles[1].X);
Assert.Equal(5466, tiles[1].Y);
}

[Fact]
public void Tile_BetweenLine_WhenLineVertical_TwoTileHop_ShouldEnumerateThreeTiles()
{
Expand Down

0 comments on commit d1d796b

Please sign in to comment.