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
impl NodeLocation
Sourcepub const UNSPECIFIED: NodeLocation
pub const UNSPECIFIED: NodeLocation
An unspecified location with zero-byte precision.
Sourcepub fn from_bytes(bytes: &[u8]) -> Self
pub fn from_bytes(bytes: &[u8]) -> Self
Construct from a byte slice, silently truncating to MAX_PRECISION.
Never panics.
Sourcepub fn from_lat_lon(lon: f32, lat: f32, precision: u8) -> Self
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.
Sourcepub fn from_lat_lon_f64(lon: f64, lat: f64, precision: u8) -> Self
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.
Sourcepub fn is_unspecified(&self) -> bool
pub fn is_unspecified(&self) -> bool
Returns true if this location is unspecified (zero-byte precision).
Sourcepub fn clamped(&self, precision: u8) -> Self
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.
Sourcepub fn bounds(&self) -> ((f32, f32), (f32, f32))
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)).
Sourcepub fn center(&self) -> (f32, f32)
pub fn center(&self) -> (f32, f32)
Center of the encoded grid cell as (longitude, latitude), in degrees.
Sourcepub fn contains(&self, lon: f32, lat: f32) -> bool
pub fn contains(&self, lon: f32, lat: f32) -> bool
Returns true if (longitude, latitude) falls within this cell.
An unspecified location contains all points.
Sourcepub fn contains_location(&self, other: &Self) -> bool
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
impl Clone for NodeLocation
Source§fn clone(&self) -> NodeLocation
fn clone(&self) -> NodeLocation
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NodeLocation
impl Debug for NodeLocation
Source§impl Default for NodeLocation
impl Default for NodeLocation
Source§impl Display for NodeLocation
Displays as "longitude, latitude" with decimal places matched to the encoded precision.
impl Display for NodeLocation
Displays as "longitude, latitude" with decimal places matched to the encoded precision.
An unspecified location displays as "(unspecified)".
Source§impl From<(f32, f32)> for NodeLocation
Encodes a (longitude, latitude) pair at maximum precision (7 bytes).
impl From<(f32, f32)> for NodeLocation
Encodes a (longitude, latitude) pair at maximum precision (7 bytes).
Source§impl From<(f64, f64)> for NodeLocation
Available on crate feature f64 only.Encodes a (longitude, latitude) pair at maximum precision (7 bytes).
impl From<(f64, f64)> for NodeLocation
f64 only.Encodes a (longitude, latitude) pair at maximum precision (7 bytes).
Only available with the f64 crate feature.
Source§impl From<NodeLocation> for (f32, f32)
Converts to the (longitude, latitude) center of the cell.
impl From<NodeLocation> for (f32, f32)
Converts to the (longitude, latitude) center of the cell.
Source§fn from(loc: NodeLocation) -> Self
fn from(loc: NodeLocation) -> Self
Source§impl Hash for NodeLocation
impl Hash for NodeLocation
Source§impl PartialEq for NodeLocation
impl PartialEq for NodeLocation
impl Copy for NodeLocation
impl Eq for NodeLocation
impl StructuralPartialEq for NodeLocation
Auto Trait Implementations§
impl Freeze for NodeLocation
impl RefUnwindSafe for NodeLocation
impl Send for NodeLocation
impl Sync for NodeLocation
impl Unpin for NodeLocation
impl UnwindSafe for NodeLocation
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)