IntervalTrait

Trait IntervalTrait 

Source
pub trait IntervalTrait: Debug + PartialEq {
Show 15 methods // Required methods fn new(lo: f64, hi: f64) -> Self; fn empty() -> Self; fn full() -> Self; fn lo(&self) -> f64; fn hi(&self) -> f64; fn is_wraparound(&self) -> bool; fn intersects_value(&self, value: f64) -> bool; fn intersects_interval(&self, other: &Self) -> bool; fn contains_interval(&self, other: &Self) -> bool; fn width(&self) -> f64; fn mid(&self) -> f64; fn is_empty(&self) -> bool; fn merge_interval(&self, other: &Self) -> Self; fn merge_value(&self, other: f64) -> Self; fn expand_by(&self, distance: f64) -> Self;
}
Expand description

Generic 1D intervals with wraparound support

This trait specifies common behaviour implemented by the Interval and WraparoundInterval.

Briefly, “wraparound” support was included in the Parquet specification to ensure that geometries or geographies with components on both sides of antimeridian (180 degrees longitude) can be reasonably summarized. This concept was borrowed from the widely used GeoJSON and matches identical bounding box specifications for GeoParquet and STAC, among others.

Because the Parquet specification also states that longitude values are always stored as x values (i.e., the first coordinate component), this contingency is only available for the xmin/xmax component of the GeoStatistics. Thus, the xmin/xmax pair may either represent a regular interval (specified by xmin = 10 and xmax = 20):

          10         20
           |==========|

…or a “wraparound” interval (specified by xmin = 20 and xmax = 10). This interval is the union of the two regular intervals (-Inf, 10] and (20, Inf). Infinity was chosen rather than any particular value to ensure that Parquet implementations did not have to consider the value of the coordinate reference system when comparing intervals.

          10         20
<==========|          |============>

In general, one should use Interval unless specifically working with wraparound, as the contingency of wraparound incurs overhead (particularly in a loop). This trait is mostly used to simplify testing and unify documentation for the two concrete implementations.

Required Methods§

Source

fn new(lo: f64, hi: f64) -> Self

Create an interval from lo and hi values

Source

fn empty() -> Self

Create an empty interval that intersects nothing (except the full interval)

Source

fn full() -> Self

Create the full interval (that intersects everything, including the empty interval)

Source

fn lo(&self) -> f64

Lower bound

If is_wraparound() returns false, this is also the minimum value. When empty, this value is Infinity; when full, this value is -Infinity.

Source

fn hi(&self) -> f64

Upper bound

If is_wraparound() returns false, this is also the maximum value. When empty, this value is -Infinity; when full, this value is Infinity.

Source

fn is_wraparound(&self) -> bool

Check for wraparound

If is_wraparound() returns false, this interval represents the values that are between lo and hi. If is_wraparound() returns true, this interval represents the values that are not between lo and hi.

It is recommended to work directly with an Interval where this is guaranteed to return false unless wraparound support is specifically required.

Source

fn intersects_value(&self, value: f64) -> bool

Check for potential intersection with a value

Note that intervals always contain their endpoints (for both the wraparound and non-wraparound case).

Source

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

Check for potential intersection with an interval

Note that intervals always contain their endpoints (for both the wraparound and non-wraparound case).

This method accepts Self for performance reasons to prevent unnecessary checking of is_wraparound() when not required for an implementation.

Source

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

Check for potential containment of an interval

Note that intervals always contain their endpoints (for both the wraparound and non-wraparound case).

This method accepts Self for performance reasons to prevent unnecessary checking of is_wraparound() when not required for an implementation.

Source

fn width(&self) -> f64

The width of the interval

For the non-wraparound case, this is the distance between lo and hi. For the wraparound case, this is infinity.

Source

fn mid(&self) -> f64

The midpoint of the interval

For the non-wraparound case, this is the point exactly between lo and hi. For the wraparound case, this is arbitrarily chosen as infinity (to preserve the property that intervals intersect their midpoint).

Source

fn is_empty(&self) -> bool

True if this interval is empty (i.e. intersects no values)

Source

fn merge_interval(&self, other: &Self) -> Self

Compute a new interval that is the union of both

When accumulating intervals in a loop, use Interval::update_interval.

Source

fn merge_value(&self, other: f64) -> Self

Compute a new interval that is the union of both

When accumulating intervals in a loop, use Interval::update_value.

Source

fn expand_by(&self, distance: f64) -> Self

Expand this interval by a given distance

Returns a new interval where both endpoints are moved outward by the given distance. For regular intervals, this expands both lo and hi by the distance. For wraparound intervals, this may result in the full interval if expansion is large enough.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§