NodeLocation

Struct NodeLocation 

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

A variable-precision geographic location encoded as a 1–7 byte grid code.

Each byte refines the location to a 16×16 sub-grid. Within each byte, the high nibble indexes longitude and the low nibble indexes latitude. All (longitude, latitude) tuples in this type use that order.

The zero-length UNSPECIFIED sentinel represents an unknown location.

Implementations§

Source§

impl NodeLocation

Source

pub const UNSPECIFIED: NodeLocation

An unspecified location with zero-byte precision.

Source

pub fn from_bytes(bytes: &[u8]) -> Self

Construct from a byte slice, silently truncating to MAX_PRECISION. Never panics.

Source

pub fn from_lat_lon(lon: f32, lat: f32, precision: u8) -> Self

Encode a (longitude, latitude) position in degrees at the given precision.

precision is clamped to MAX_PRECISION. Inputs are clamped to valid ranges ([-180, +180] and [-90, +90]).

Internal arithmetic uses f32 by default. Enable the f64 crate feature for accurate results at 6–7 byte precision.

Source

pub fn from_lat_lon_f64(lon: f64, lat: f64, precision: u8) -> Self

Encode a (longitude, latitude) position in degrees at the given precision.

Only available with the f64 crate feature. Prefer this over from_lat_lon when working with f64 coordinates and 6–7 byte precision.

Source

pub fn as_bytes(&self) -> &[u8]

The raw encoded bytes.

Source

pub fn len(&self) -> usize

Number of encoded bytes (0 if unspecified).

Source

pub fn is_unspecified(&self) -> bool

Returns true if this location is unspecified (zero-byte precision).

Source

pub fn precision(&self) -> u8

Precision level (0–7). Zero means unspecified.

Source

pub fn clamped(&self, precision: u8) -> Self

Return a copy truncated to at most precision bytes.

Because the encoding is strictly hierarchical, the truncated value is the correct encoding of the same position at the lower precision.

Source

pub fn bounds(&self) -> ((f32, f32), (f32, f32))

The grid cell as ((lon_min, lat_min), (lon_max, lat_max)), in degrees.

Cell bounds are half-open [lo, hi), matching the floor-based encoding. An unspecified location returns the full globe ((-180, -90), (180, 90)).

Source

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

Center of the encoded grid cell as (longitude, latitude), in degrees.

Source

pub fn contains(&self, lon: f32, lat: f32) -> bool

Returns true if (longitude, latitude) falls within this cell.

An unspecified location contains all points.

Source

pub fn contains_location(&self, other: &Self) -> bool

Returns true if other is the same cell or a sub-cell of this one.

An unspecified location contains everything. A finer location cannot contain a coarser one.

Trait Implementations§

Source§

impl Clone for NodeLocation

Source§

fn clone(&self) -> NodeLocation

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeLocation

Source§

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

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

impl Default for NodeLocation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for NodeLocation

Displays as "longitude, latitude" with decimal places matched to the encoded precision.

An unspecified location displays as "(unspecified)".

Source§

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

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

impl From<(f32, f32)> for NodeLocation

Encodes a (longitude, latitude) pair at maximum precision (7 bytes).

Source§

fn from((lon, lat): (f32, f32)) -> Self

Converts to this type from the input type.
Source§

impl From<(f64, f64)> for NodeLocation

Available on crate feature f64 only.

Encodes a (longitude, latitude) pair at maximum precision (7 bytes).

Only available with the f64 crate feature.

Source§

fn from((lon, lat): (f64, f64)) -> Self

Converts to this type from the input type.
Source§

impl From<NodeLocation> for (f32, f32)

Converts to the (longitude, latitude) center of the cell.

Source§

fn from(loc: NodeLocation) -> Self

Converts to this type from the input type.
Source§

impl Hash for NodeLocation

Source§

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

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

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 PartialEq for NodeLocation

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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 Copy for NodeLocation

Source§

impl Eq for NodeLocation

Source§

impl StructuralPartialEq for NodeLocation

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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

Source§

type Output = T

Should always be Self
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.