pub struct PackedTileId { /* private fields */ }Expand description
An NDS.Live Packed Tile ID.
Per the NDS.Live standard, tile IDs are signed 32-bit integers: levels 0-14
are positive, while level 15 values are negative (bit 31 is the sign bit).
Internally the value is stored as a u32 so that bit operations need not
deal with the sign bit; conversion to/from signed happens only at the API
boundary (see PackedTileId::value and PackedTileId::new).
Implementations§
Source§impl PackedTileId
impl PackedTileId
Sourcepub fn new(value: i32) -> Result<Self, TileIdError>
pub fn new(value: i32) -> Result<Self, TileIdError>
Construct a PackedTileId from a signed i32 tile ID value.
Accepts the signed representation (negative for level 15). For a
constructor that also accepts the unsigned representation or
out-of-range values, see PackedTileId::from_i64.
Sourcepub fn from_value(value: i32) -> Result<Self, TileIdError>
pub fn from_value(value: i32) -> Result<Self, TileIdError>
Construct a PackedTileId from the signed NDS.Live public value.
Sourcepub fn from_i64(value: i64) -> Result<Self, TileIdError>
pub fn from_i64(value: i64) -> Result<Self, TileIdError>
Construct a PackedTileId from an i64, accepting both signed and
unsigned 32-bit representations (matching the Python constructor).
Negative values are interpreted as signed i32 and converted to the
unsigned internal representation; values >= 2^32 are masked to 32 bits.
Sourcepub fn value(&self) -> i32
pub fn value(&self) -> i32
Get the tile ID value as a signed i32, per the NDS.Live standard.
Level 15 tiles return negative values; levels 0-14 return positive values.
Sourcepub fn from_tile_index(
morton_number: u32,
level: u32,
) -> Result<Self, TileIdError>
pub fn from_tile_index( morton_number: u32, level: u32, ) -> Result<Self, TileIdError>
Create a PackedTileId directly from a tile morton number and level,
without any coordinate conversion.
morton_number must be in 0..=2^(2*level+1) - 1.
Sourcepub fn from_tile_xy(x: u32, y: u32, level: u32) -> Result<Self, TileIdError>
pub fn from_tile_xy(x: u32, y: u32, level: u32) -> Result<Self, TileIdError>
Create a PackedTileId from tile-grid coordinates at the given level.
X is in 0..=2^(level+1)-1, Y is in 0..=2^level-1. Coordinates use
the NDS Morton tile-grid order and are inverse to PackedTileId::x
and PackedTileId::y.
Sourcepub fn from_nds_coordinates(
x: i32,
y: i32,
level: u32,
) -> Result<Self, TileIdError>
pub fn from_nds_coordinates( x: i32, y: i32, level: u32, ) -> Result<Self, TileIdError>
Create the tile at level that contains the given NDS coordinate.
Sourcepub fn from_wgs84(
longitude: f64,
latitude: f64,
level: u32,
) -> Result<Self, TileIdError>
pub fn from_wgs84( longitude: f64, latitude: f64, level: u32, ) -> Result<Self, TileIdError>
Create the tile at level that contains the given WGS84 coordinate.
Sourcepub fn from_morton_and_level(
morton_code: MortonCode,
level: u32,
) -> Result<Self, TileIdError>
pub fn from_morton_and_level( morton_code: MortonCode, level: u32, ) -> Result<Self, TileIdError>
Create a PackedTileId for the tile at level that contains the
full-precision NDS coordinates encoded in morton_code.
Note: the resulting tile’s PackedTileId::morton_number generally
differs from morton_code.value().
Sourcepub fn dimensions_in_meters(&self) -> (f64, f64)
pub fn dimensions_in_meters(&self) -> (f64, f64)
Tile dimensions in meters at the tile’s center latitude.
Returns (width_meters, height_meters).
Sourcepub fn wgs84_from_nds_coordinates(x: i64, y: i64) -> (f64, f64)
pub fn wgs84_from_nds_coordinates(x: i64, y: i64) -> (f64, f64)
Convert NDS integer coordinates to lon/lat degrees without edge normalization.
Sourcepub fn center_wgs84(&self) -> (f64, f64)
pub fn center_wgs84(&self) -> (f64, f64)
Center of the tile in lon/lat degrees.
Sourcepub fn south_west_wgs84(&self) -> (f64, f64)
pub fn south_west_wgs84(&self) -> (f64, f64)
South-west tile corner in lon/lat degrees.
Sourcepub fn north_east_wgs84(&self) -> (f64, f64)
pub fn north_east_wgs84(&self) -> (f64, f64)
Exclusive north-east tile corner in lon/lat degrees.
Sourcepub fn wgs84_size(&self) -> (f64, f64)
pub fn wgs84_size(&self) -> (f64, f64)
Tile width/height in lon/lat degrees.
Sourcepub fn south_west_corner(&self) -> (i64, i64)
pub fn south_west_corner(&self) -> (i64, i64)
South-west corner of the tile in NDS coordinates (x, y).
Sourcepub fn north_east_corner(&self) -> (i64, i64)
pub fn north_east_corner(&self) -> (i64, i64)
North-east corner of the tile in NDS coordinates (x, y).
This boundary is exclusive — it is the first point outside the tile.
Sourcepub fn morton_number(&self) -> u32
pub fn morton_number(&self) -> u32
Morton number of the tile (the packed value minus the level offset).
Sourcepub fn neighbour(&self, offset_x: i32, offset_y: i32) -> PackedTileId
pub fn neighbour(&self, offset_x: i32, offset_y: i32) -> PackedTileId
Same-level tile at a relative grid offset, wrapping at the respective limits.
Sourcepub fn west_neighbour(&self) -> PackedTileId
pub fn west_neighbour(&self) -> PackedTileId
Tile to the west at the same level (wraps at the antimeridian).
Sourcepub fn east_neighbour(&self) -> PackedTileId
pub fn east_neighbour(&self) -> PackedTileId
Tile to the east at the same level (wraps at the antimeridian).
Sourcepub fn south_neighbour(&self) -> PackedTileId
pub fn south_neighbour(&self) -> PackedTileId
Tile to the south at the same level (wraps at the south pole).
Sourcepub fn north_neighbour(&self) -> PackedTileId
pub fn north_neighbour(&self) -> PackedTileId
Tile to the north at the same level (wraps at the north pole).
Trait Implementations§
Source§impl Clone for PackedTileId
impl Clone for PackedTileId
Source§fn clone(&self) -> PackedTileId
fn clone(&self) -> PackedTileId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for PackedTileId
Source§impl Debug for PackedTileId
impl Debug for PackedTileId
Source§impl Display for PackedTileId
impl Display for PackedTileId
impl Eq for PackedTileId
Source§impl Hash for PackedTileId
impl Hash for PackedTileId
Source§impl Ord for PackedTileId
impl Ord for PackedTileId
Source§fn cmp(&self, other: &PackedTileId) -> Ordering
fn cmp(&self, other: &PackedTileId) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for PackedTileId
impl PartialEq for PackedTileId
Source§fn eq(&self, other: &PackedTileId) -> bool
fn eq(&self, other: &PackedTileId) -> bool
self and other values to be equal, and is used by ==.