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: f64The “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>
impl<const DIM: i32> Metric<DIM>
Sourcepub fn get_value(&self, level: i32) -> f64
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.
Sourcepub fn get_closest_level(&self, value: f64) -> i32
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
Sourcepub fn get_level_for_max_value(&self, value: f64) -> i32
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.
Sourcepub fn get_level_for_min_value(&self, value: f64) -> i32
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§
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> 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)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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