Skip to content

Commit

Permalink
Merge pull request #20 from podusowski/fix-crashing-at-the-edges
Browse files Browse the repository at this point in the history
Fix crashing at the edges
  • Loading branch information
podusowski authored Jul 18, 2023
2 parents fe2c530 + ee8bea9 commit 3127b24
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ All notable changes to this project will be documented in this file.

* Zooming using CTRL + mouse wheel or pinch gesture.

### Fixed

* Fixed panic when dragging out of the map's boundaries.

## 0.5.0

### Breaking
Expand Down
7 changes: 5 additions & 2 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ fn draw_tiles(
tile_id.east(),
tile_id.south(),
tile_id.west(),
] {
]
.iter()
.flatten()
{
draw_tiles(
painter,
coordinates,
*coordinates,
map_center_projected_position,
tiles,
ui,
Expand Down
28 changes: 14 additions & 14 deletions src/mercator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,36 +84,36 @@ impl TileId {
Pixels::new((self.x * TILE_SIZE) as f32, (self.y * TILE_SIZE) as f32)
}

pub fn east(&self) -> TileId {
TileId {
pub fn east(&self) -> Option<TileId> {
Some(TileId {
x: self.x + 1,
y: self.y,
zoom: self.zoom,
}
})
}

pub fn west(&self) -> TileId {
TileId {
x: self.x - 1,
pub fn west(&self) -> Option<TileId> {
Some(TileId {
x: self.x.checked_sub(1)?,
y: self.y,
zoom: self.zoom,
}
})
}

pub fn north(&self) -> TileId {
TileId {
pub fn north(&self) -> Option<TileId> {
Some(TileId {
x: self.x,
y: self.y - 1,
y: self.y.checked_sub(1)?,
zoom: self.zoom,
}
})
}

pub fn south(&self) -> TileId {
TileId {
pub fn south(&self) -> Option<TileId> {
Some(TileId {
x: self.x,
y: self.y + 1,
zoom: self.zoom,
}
})
}
}

Expand Down

0 comments on commit 3127b24

Please sign in to comment.