Struct substrate::geometry::span::Span

source ·
pub struct Span { /* private fields */ }
Expand description

A closed interval of coordinates in one dimension.

Represents the range [start, stop].

Implementations§

source§

impl Span

source

pub const fn until(stop: i64) -> Span

Creates a new Span from 0 until the specified stop.

§Panics

This function panics if stop is less than 0.

source

pub const unsafe fn new_unchecked(start: i64, stop: i64) -> Span

Creates a new Span between two integers.

§Safety

The caller must ensure that start is less than or equal to stop.

source

pub fn new(start: i64, stop: i64) -> Span

Creates a new Span between two integers.

source

pub const fn from_point(x: i64) -> Span

Creates a span of zero length encompassing the given point.

source

pub const fn with_start_and_length(start: i64, length: i64) -> Span

Creates a span of the given length starting from start.

source

pub const fn with_stop_and_length(stop: i64, length: i64) -> Span

Creates a span of the given length ending at stop.

source

pub const fn with_point_and_length(sign: Sign, point: i64, length: i64) -> Span

Creates a span with the given endpoint and length.

If sign is Sign::Pos, point is treated as the ending/stopping point of the span. If sign is Sign::Neg, point is treated as the beginning/starting point of the span.

source

pub const fn expand(self, sign: Sign, amount: i64) -> Span

Creates a new Span expanded by amount in the direction indicated by pos.

source

pub const fn expand_all(self, amount: i64) -> Span

Creates a new Span expanded by amount in both directions.

source

pub const fn endpoint(&self, sign: Sign) -> i64

Gets the starting (Sign::Neg) or stopping (Sign::Pos) endpoint of a span.

source

pub fn dist_to(&self, point: i64) -> i64

Gets the shortest distance between this span and a point.

§Example
let span = Span::new(10, 20);
assert_eq!(span.dist_to(4), 6);
assert_eq!(span.dist_to(12), 0);
assert_eq!(span.dist_to(27), 7);
source

pub fn from_center_span(center: i64, span: i64) -> Span

Creates a new Span with center center and length span.

span must be a positive, even integer.

§Example
let span = Span::from_center_span(0, 40);
assert_eq!(span, Span::new(-20, 20));
§Panics

Passing an odd span to this method results in a panic:

let span = Span::from_center_span(0, 25);

Passing a negative span to this method also results in a panic:

let span = Span::from_center_span(0, -200);
source

pub fn from_center_span_gridded(center: i64, span: i64, grid: i64) -> Span

Creates a new Span with center center and length span and snap the edges to the grid.

§Example
let span = Span::from_center_span_gridded(0, 40, 5);
assert_eq!(span, Span::new(-20, 20));

let span = Span::from_center_span_gridded(35, 40, 5);
assert_eq!(span, Span::new(15, 55));
§Panics

This function panics if span is negative, odd, or not an integer multiple of grid.

source

pub const fn center(&self) -> i64

Gets the center of the span.

source

pub const fn length(&self) -> i64

Gets the length of the span.

source

pub const fn start(&self) -> i64

Gets the start of the span.

source

pub const fn stop(&self) -> i64

Gets the stop of the span.

source

pub const fn intersects(&self, other: &Span) -> bool

Checks if the span intersects with the Span other.

source

pub fn merge(spans: impl IntoIterator<Item = Span>) -> Span

Creates a new minimal Span that contains all of the elements of spans.

source

pub fn union(self, other: Span) -> Span

Calculates the smallest interval containing this span and other.

source

pub fn union_all<T>(spans: impl Iterator<Item = T>) -> Span
where T: Into<Span>,

Calculates the minimal bounding interval of all spans provided.

§Example
let spans = vec![
    Span::new(10, 40),
    Span::new(35, 60),
    Span::new(20, 30),
    Span::new(-10, 5),
];
assert_eq!(Span::union_all(spans.into_iter()), Span::new(-10, 60));
§Panics

This function panics if the provided iterator has no elements. If your iterator may be empty, consider using Span::union_all_option.

source

pub fn union_all_option<T>(spans: impl Iterator<Item = T>) -> Option<Span>
where T: Into<Option<Span>>,

Calculates the minimal bounding interval of all Option<Span>s provided.

All None elements in the iterator are ignored. If the iterator has no Some(_) elements, this function returns None.

§Example
let spans = vec![
    Some(Span::new(10, 40)),
    Some(Span::new(35, 60)),
    None,
    Some(Span::new(20, 30)),
    None,
    Some(Span::new(-10, 5)),
];
assert_eq!(Span::union_all_option(spans.into_iter()), Some(Span::new(-10, 60)));
source

pub fn intersection(self, other: Span) -> Option<Span>

Calculates the intersection of this span with other.

source

pub fn add_point(self, pos: i64) -> Span

Returns a new Span representing the union of the current span with the given point.

source

pub fn shrink(self, side: Sign, amount: i64) -> Span

Shrinks the given side by the given amount.

Behavior is controlled by the given Sign:

  • If side is Sign::Pos, shrinks from the positive end (ie. decreases the stop).
  • If side is Sign::Neg, shrinks from the negative end (ie. increases the start).
source

pub const fn shrink_all(self, amount: i64) -> Span

Shrinks the span by the given amount on all sides.

source

pub const fn translate(self, amount: i64) -> Span

Translates the span by the given amount.

source

pub fn dist_to_span(self, other: Span) -> i64

The minimum separation between this span and other.

§Example
let s1 = Span::new(10, 20);
let s2 = Span::new(30, 50);
let s3 = Span::new(25, 40);
assert_eq!(s1.dist_to_span(s2), 10);
assert_eq!(s1.dist_to_span(s3), 5);
assert_eq!(s2.dist_to_span(s3), 0);
assert_eq!(s3.dist_to_span(s3), 0);
source

pub fn has_integer_center(&self) -> bool

Returns whether the span’s center is at an integer coordinate.

§Example
let span = Span::new(0, 100);
assert!(span.has_integer_center());

let span = Span::new(0, 99);
assert!(!span.has_integer_center());

Trait Implementations§

source§

impl BoundingUnion<Span> for Span

§

type Output = Span

The type of the output shape representing the bounding union.
source§

fn bounding_union(&self, other: &Span) -> <Span as BoundingUnion<Span>>::Output

Calculates the bounding union of this shape with other. Read more
source§

impl Clone for Span

source§

fn clone(&self) -> Span

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Contains<Span> for Span

source§

fn contains(&self, other: &Span) -> Containment

Returns a Containment indicating how other is enclosed within this shape. Read more
source§

fn encloses(&self, other: &T) -> bool

Returns true if other is fully enclosed in this shape.
source§

fn partially_intersects(&self, other: &T) -> bool

Returns true if other is fully or partially enclosed in this shape.
source§

impl Debug for Span

source§

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

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

impl Default for Span

source§

fn default() -> Span

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

impl<'de> Deserialize<'de> for Span

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<Span, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<(i64, i64)> for Span

source§

fn from(tup: (i64, i64)) -> Span

Converts to this type from the input type.
source§

impl FromIterator<Span> for EnumeratedTracks

source§

fn from_iter<T: IntoIterator<Item = Span>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for Span

source§

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

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

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 Intersect<Span> for Span

§

type Output = Span

The type of the output shape representing the intersection.
source§

fn intersect(&self, other: &Span) -> Option<<Span as Intersect<Span>>::Output>

Calculates the intersection of this shape with other. Read more
source§

impl Ord for Span

source§

fn cmp(&self, other: &Span) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Span

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Span

source§

fn partial_cmp(&self, other: &Span) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Span

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Span

source§

impl Eq for Span

source§

impl StructuralPartialEq for Span

Auto Trait Implementations§

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnwindSafe for Span

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> BoundingUnion<Option<T>> for T
where T: BoundingUnion<T, Output = T> + Clone,

§

type Output = T

The type of the output shape representing the bounding union.
source§

fn bounding_union( &self, other: &Option<T> ) -> <T as BoundingUnion<Option<T>>>::Output

Calculates the bounding union of this shape with other. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<T, U> CustomHardwareType<Flipped<T>> for U

source§

fn from_layout_type(other: &Flipped<T>) -> U

Creates this layout type from another layout type.
source§

impl<T, U> CustomHardwareType<InOut<T>> for U

source§

fn from_layout_type(other: &InOut<T>) -> U

Creates this layout type from another layout type.
source§

impl<T, U> CustomHardwareType<Input<T>> for U

source§

fn from_layout_type(other: &Input<T>) -> U

Creates this layout type from another layout type.
source§

impl<T, U> CustomHardwareType<Output<T>> for U

source§

fn from_layout_type(other: &Output<T>) -> U

Creates this layout type from another layout type.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

source§

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

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> Connect<&T> for T

source§

impl<T> Connect<T> for T

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Primitive for T
where T: Clone + Send + Sync + Any,

source§

impl<T> Primitive for T