Skip to content

Commit

Permalink
Make bound checking in quad key conversion explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Apr 23, 2023
1 parent bdf743a commit b22edec
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions maplibre/src/coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,19 @@ impl WorldTileCoords {
}

pub fn build_quad_key(&self) -> Option<Quadkey> {
// check for out of bound access
let TileCoords {
x, y, z
} = self.into_tile(TileAddressingScheme::XYZ)?;
let max_coords = self.z.max_tile_coord();

if self.x < 0 || self.y < 0 {
// TODO: This is probably not the correct if x and y are allowed to be negative
return None;
}

let x = self.x as u32;
let y = self.y as u32;

if x > max_coords || y > max_coords {
return None;
}

Some(Quadkey::new(z, x, y))
}
Expand Down

0 comments on commit b22edec

Please sign in to comment.