Skip to main content

PackedTileId

Struct PackedTileId 

Source
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

Source

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.

Source

pub fn from_value(value: i32) -> Result<Self, TileIdError>

Construct a PackedTileId from the signed NDS.Live public value.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn from_wgs84( longitude: f64, latitude: f64, level: u32, ) -> Result<Self, TileIdError>

Create the tile at level that contains the given WGS84 coordinate.

Source

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().

Source

pub fn level(&self) -> u32

Level of the tile (0..=15).

Source

pub fn size(&self) -> i64

Size of the tile in NDS coordinate units (1 << (31 - level)).

Source

pub fn dimensions_in_meters(&self) -> (f64, f64)

Tile dimensions in meters at the tile’s center latitude.

Returns (width_meters, height_meters).

Source

pub fn center(&self) -> (i64, i64)

Center of the tile in NDS coordinates (x, y).

Source

pub fn wgs84_from_nds_coordinates(x: i64, y: i64) -> (f64, f64)

Convert NDS integer coordinates to lon/lat degrees without edge normalization.

Source

pub fn center_wgs84(&self) -> (f64, f64)

Center of the tile in lon/lat degrees.

Source

pub fn south_west_wgs84(&self) -> (f64, f64)

South-west tile corner in lon/lat degrees.

Source

pub fn north_east_wgs84(&self) -> (f64, f64)

Exclusive north-east tile corner in lon/lat degrees.

Source

pub fn wgs84_size(&self) -> (f64, f64)

Tile width/height in lon/lat degrees.

Source

pub fn south_west_corner(&self) -> (i64, i64)

South-west corner of the tile in NDS coordinates (x, y).

Source

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.

Source

pub fn morton_number(&self) -> u32

Morton number of the tile (the packed value minus the level offset).

Source

pub fn x(&self) -> u32

Tile-grid X coordinate at this tile’s level.

Source

pub fn y(&self) -> u32

Tile-grid Y coordinate at this tile’s level.

Source

pub fn neighbour(&self, offset_x: i32, offset_y: i32) -> PackedTileId

Same-level tile at a relative grid offset, wrapping at the respective limits.

Source

pub fn west_neighbour(&self) -> PackedTileId

Tile to the west at the same level (wraps at the antimeridian).

Source

pub fn east_neighbour(&self) -> PackedTileId

Tile to the east at the same level (wraps at the antimeridian).

Source

pub fn south_neighbour(&self) -> PackedTileId

Tile to the south at the same level (wraps at the south pole).

Source

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

Source§

fn clone(&self) -> PackedTileId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PackedTileId

Source§

impl Debug for PackedTileId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PackedTileId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PackedTileId

Source§

impl Hash for PackedTileId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for PackedTileId

Source§

fn cmp(&self, other: &PackedTileId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for PackedTileId

Source§

fn eq(&self, other: &PackedTileId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PackedTileId

Source§

fn partial_cmp(&self, other: &PackedTileId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for PackedTileId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.