Skip to main content

MercatorDem

Struct MercatorDem 

Source
pub struct MercatorDem { /* private fields */ }
Expand description

A contiguous rectangular block of decoded web-mercator (XYZ) DEM tiles, stitched into a single elevation grid and sampleable by longitude / latitude.

The stitched grid is row-major north → south, tiles_x * tile_size columns by tiles_y * tile_size rows. Sampling outside the block clamps to the nearest edge sample, so a halo that slightly overshoots the fetched coverage degrades gracefully rather than panicking — but for correct results the block should cover the target bounds (plus any halo).

Implementations§

Source§

impl MercatorDem

Source

pub fn new( zoom: u8, x0: u32, y0: u32, tiles_x: u32, tiles_y: u32, tile_size: u32, elev: Vec<f32>, ) -> Self

Wrap an already-stitched elevation block.

elev must be row-major north → south with (tiles_x*tile_size) * (tiles_y*tile_size) entries.

§Panics

Panics on a length mismatch, or if any tile dimension is zero.

Source

pub fn from_tiles<F>( zoom: u8, x0: u32, y0: u32, tiles_x: u32, tiles_y: u32, tile_size: u32, get_tile: F, ) -> Self
where F: FnMut(u8, u32, u32) -> Vec<f32>,

Build a block by pulling each XYZ tile through get_tile, which returns that tile’s decoded elevations (tile_size², row-major north → south). The closure is where you do your fetch + heightmap decode; for async callers, pre-fetch into a map and look it up here.

Tiles are requested in row-major order (x0, y0) … (x0+tiles_x-1, y0+tiles_y-1).

§Panics

Panics if any returned tile does not have exactly tile_size² samples.

Source

pub fn tiles_covering( zoom: u8, west: f64, south: f64, east: f64, north: f64, ) -> (u32, u32, u32, u32)

Range of XYZ tiles at zoom covering a longitude/latitude box, returning (x0, y0, tiles_x, tiles_y).

Widen the box by your halo before calling if you intend to sample a buffer beyond the tile (e.g. for buffered_geodetic).

Source

pub fn width_px(&self) -> u32

Stitched-grid width in pixels (tiles_x * tile_size).

Source

pub fn height_px(&self) -> u32

Stitched-grid height in pixels (tiles_y * tile_size).

Source

pub fn sample(&self, lon: f64, lat: f64) -> f32

Bilinearly sample the elevation at (lon, lat) in degrees.

Latitude is clamped to the web-mercator limit. Positions outside the fetched block clamp to the nearest edge sample. NaN samples (e.g. missing data filled by the caller) are tolerated: the interpolation falls back to any defined neighbour, returning NaN only if all four corners are NaN.

Source

pub fn geodetic_grid(&self, bounds: &TileBounds, grid_size: u32) -> Vec<f32>

Resample onto a geodetic grid_size × grid_size grid covering bounds, row-major north → south — ready for crate::terrain::encode_terrain.

§Panics

Panics if grid_size < 2.

Source

pub fn buffered_geodetic( &self, bounds: &TileBounds, tile_grid_size: u32, buffer: u32, ) -> BufferedElevations

Resample onto a halo-extended geodetic grid — a BufferedElevations for crate::terrain::NormalMode::BufferedGradient.

The inner tile_grid_size × tile_grid_size block matches geodetic_grid; the surrounding buffer-cell strip is sampled from the neighbour area (so make sure this MercatorDem was built to cover bounds widened by the halo).

§Panics

Panics if tile_grid_size < 2.

Trait Implementations§

Source§

impl Clone for MercatorDem

Source§

fn clone(&self) -> MercatorDem

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 Debug for MercatorDem

Source§

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

Formats the value using the given formatter. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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.