Metric

Struct Metric 

Source
pub struct Metric<const DIM: i32> {
    pub deriv: f64,
}
Expand description

The following are various constants that describe the shapes and sizes of S2Cells (see s2coords.h and s2cell_id.h). They are useful for deciding which cell level to use in order to satisfy a given condition (e.g. that cell vertices must be no further than “x” apart). All of the raw constants are differential quantities; you can use the getValue(level) method to compute the corresponding length or area on the unit sphere for cells at a given level. The minimum and maximum bounds are valid for cells at all levels, but they may be somewhat conservative for very large cells (e.g. face cells).

All of the values below were obtained by a combination of hand analysis and Mathematica. In general, S2_TAN_PROJECTION produces the most uniform shapes and sizes of cells, S2_LINEAR_PROJECTION is considerably worse, and S2_QUADRATIC_PROJECTION is somewhere in between (but generally closer to the tangent projection than the linear one).

Note that S2_LINEAR_PROJECTION can be useful for analysis even when another projection is being used, since it allows many cell metrics to be bounded in terms of (u,v) coordinates rather than (s,t) coordinates. (With the linear projection, u = 2 * s - 1 and similarly for v.) Similarly, S2_TAN_PROJECTION allows cell metrics to be bounded in terms of (u,v) coordinate changes when they are measured as distances on the unit sphere.

Defines a cell metric of the given dimension (1 == length, 2 == area).

Fields§

§deriv: f64

The “deriv” value of a metric is a derivative, and must be multiplied by a length or area in (s,t)-space to get a useful value.

Implementations§

Source§

impl<const DIM: i32> Metric<DIM>

Source

pub fn get_value(&self, level: i32) -> f64

Return the value of a metric for cells at the given level. The value is either a length or an area on the unit sphere, depending on the particular metric.

Source

pub fn get_closest_level(&self, value: f64) -> i32

Return the level at which the metric has approximately the given value. For example, K_AVG_EDGE.getClosestLevel(0.1) returns the level at which the average cell edge length is approximately 0.1. The return value is

Source

pub fn get_level_for_max_value(&self, value: f64) -> i32

Return the minimum level such that the metric is at most the given value, or S2CellId::kMaxLevel if there is no such level. For example, K_MAX_DIAG.get_level_for_max_value(0.1) returns the minimum level such that all cell diagonal lengths are 0.1 or smaller. The return value is always a valid level.

Source

pub fn get_level_for_min_value(&self, value: f64) -> i32

Return the maximum level such that the metric is at least the given value, or 0 if there is no such level. For example, K_MAX_DIAG.getLevelForMinValue(0.1) returns the maximum level such that all cells have a minimum width of 0.1 or larger. The return value is always a valid level.

Trait Implementations§

Source§

impl<const DIM: i32> Clone for Metric<DIM>

Source§

fn clone(&self) -> Metric<DIM>

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<const DIM: i32> Debug for Metric<DIM>

Source§

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

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

impl<const DIM: i32> Copy for Metric<DIM>

Auto Trait Implementations§

§

impl<const DIM: i32> Freeze for Metric<DIM>

§

impl<const DIM: i32> RefUnwindSafe for Metric<DIM>

§

impl<const DIM: i32> Send for Metric<DIM>

§

impl<const DIM: i32> Sync for Metric<DIM>

§

impl<const DIM: i32> Unpin for Metric<DIM>

§

impl<const DIM: i32> UnwindSafe for Metric<DIM>

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> 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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V