Line

Struct Line 

Source
#[repr(C)]
pub struct Line<T> { pub start: T, pub end: T, }
Expand description

Expresses a linear set by its starting and termination points

This type is fully isomorphic with core::ops::Range and Span. However, unlike core::ops::Range, this type is not an iterator and therefore can implement Copy. Points may have any number of dimensions.

Fields§

§start: T

The start point

§end: T

The first point excluded by the set

Implementations§

Source§

impl<T> Line<T>

Source

pub const fn new(start: T, end: T) -> Self

Create a new line

§Example
let line = lset::Line::new(5, 10);
assert_eq!(line.start, 5);
assert_eq!(line.end, 10);
Source

pub fn is_empty(&self) -> bool
where T: PartialEq,

Indicates whether the line is empty

§Example
use lset::*;
assert!(Line::from(2..2).is_empty());
assert!(!Line::from(2..3).is_empty());
Source§

impl<T: PartialOrd> Line<T>

Source

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

Returns the intersection between the sets, if any.

use lset::*;

let a = Line::new(0, 5);
let b = Line::new(2, 7);
let c = Line::new(5, 10);

assert_eq!(a.intersection(b), Some(Line::new(2, 5)));
assert_eq!(b.intersection(c), Some(Line::new(5, 7)));
assert_eq!(a.intersection(a), Some(a));
assert_eq!(b.intersection(b), Some(b));
assert_eq!(c.intersection(c), Some(c));
assert_eq!(a.intersection(c), None);

Trait Implementations§

Source§

impl<T: Add<T, Output = T>> Add<T> for Line<T>

Source§

fn add(self, rhs: T) -> Self::Output

Grows the line by the size of the operand

§Example
let before = lset::Line::new(5, 10);
let after = before + 5;
assert_eq!(after.start, 5);
assert_eq!(after.end, 15);
Source§

type Output = Line<T>

The resulting type after applying the + operator.
Source§

impl<T: AddAssign<T>> AddAssign<T> for Line<T>

Source§

fn add_assign(&mut self, rhs: T)

Grows the line by the size of the operand

§Example
let mut line = lset::Line::new(5, 10);
line += 5;
assert_eq!(line.start, 5);
assert_eq!(line.end, 15);
Source§

impl<T: Clone> Clone for Line<T>

Source§

fn clone(&self) -> Line<T>

Returns a duplicate 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<T: PartialOrd> Contains<Line<T>> for Line<T>

Source§

fn contains(&self, value: &Self) -> bool

Indicates whether the line contains another line

§Example
use lset::*;
assert!(Line::from(4..8).contains(&Line::from(5..7)));
assert!(Line::from(4..8).contains(&Line::from(4..7)));
assert!(Line::from(4..8).contains(&Line::from(5..8)));
assert!(Line::from(4..8).contains(&Line::from(4..8)));
assert!(!Line::from(4..8).contains(&Line::from(3..8)));
assert!(!Line::from(4..8).contains(&Line::from(4..9)));
assert!(!Line::from(4..8).contains(&Line::from(3..9)));
assert!(!Line::from(4..8).contains(&Line::from(2..10)));
assert!(!Line::from(4..8).contains(&Line::from(6..5)));
assert!(!Line::from(7..3).contains(&Line::from(5..6)));
Source§

impl<T: PartialOrd> Contains<T> for Line<T>

Source§

fn contains(&self, value: &T) -> bool

Indicates whether the line contains a point

§Example
use lset::*;
assert!(!Line::from(2..3).contains(&1));
assert!(Line::from(2..3).contains(&2));
assert!(!Line::from(2..3).contains(&3));
assert!(!Line::from(3..2).contains(&1));
assert!(!Line::from(3..2).contains(&2));
assert!(!Line::from(3..2).contains(&3));
Source§

impl<T: Debug> Debug for Line<T>

Source§

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

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

impl<T: Default> Default for Line<T>

Source§

fn default() -> Line<T>

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

impl<T> From<Line<T>> for Range<T>

Source§

fn from(value: Line<T>) -> Self

Converts a Line into a Range

§Example
use lset::*;
assert_eq!(5..10, std::ops::Range::from(Line::new(5, 10)));
assert_eq!(5..10, Line::new(5, 10).into());
Source§

impl<T: Clone + Sub<T, Output = U>, U> From<Line<T>> for Span<T, U>

Source§

fn from(value: Line<T>) -> Self

Converts a Line into a Span

§Example
use lset::*;
assert_eq!(Span::new(5, 10), Span::from(Line::new(5, 15)));
assert_eq!(Span::new(5, 10), (Line::new(5, 15)).into());
Source§

impl<T> From<Range<T>> for Line<T>

Source§

fn from(value: Range<T>) -> Self

Converts a Range into a Line

§Example
use lset::*;
assert_eq!(Line::new(5, 10), Line::from(5..10));
assert_eq!(Line::new(5, 10), (5..10).into());
Source§

impl<T: Clone + Add<U, Output = T>, U> From<Span<T, U>> for Line<T>

Source§

fn from(value: Span<T, U>) -> Self

Converts a Span into a Line

§Example
use lset::*;
assert_eq!(Line::new(5, 10), Line::from(Span::new(5, 5)));
assert_eq!(Line::new(5, 10), Span::new(5, 5).into());
Source§

impl<T: PartialEq> PartialEq for Line<T>

Source§

fn eq(&self, other: &Line<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Line<T>

Source§

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

Compares two Line types.

§Example
use lset::*;
assert!(Line::new(5, 10) <= Line::new(5, 10));
assert!(Line::new(5, 10) >= Line::new(5, 10));
assert!(Line::new(5, 10) < Line::new(10, 15));
assert!(Line::new(10, 15) > Line::new(5, 10));
1.0.0 · Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Copy + Sub<T, Output = T>> Shl<T> for Line<T>

Source§

fn shl(self, rhs: T) -> Self::Output

Shifts the line downwards without changing size

§Example
let before = lset::Line::new(5, 10);
let after = before << 5;
assert_eq!(after.start, 0);
assert_eq!(after.end, 5);
Source§

type Output = Line<T>

The resulting type after applying the << operator.
Source§

impl<T: Copy + SubAssign<T>> ShlAssign<T> for Line<T>

Source§

fn shl_assign(&mut self, rhs: T)

Shifts the line downwards without changing size

§Example
let mut line = lset::Line::new(5, 10);
line <<= 5;
assert_eq!(line.start, 0);
assert_eq!(line.end, 5);
Source§

impl<T: Copy + Add<T, Output = T>> Shr<T> for Line<T>

Source§

fn shr(self, rhs: T) -> Self::Output

Shifts the line upwards without changing size

§Example
let before = lset::Line::new(5, 10);
let after = before >> 5;
assert_eq!(after.start, 10);
assert_eq!(after.end, 15);
Source§

type Output = Line<T>

The resulting type after applying the >> operator.
Source§

impl<T: Copy + AddAssign<T>> ShrAssign<T> for Line<T>

Source§

fn shr_assign(&mut self, rhs: T)

Shifts the line upwards without changing size

§Example
let mut line = lset::Line::new(5, 10);
line >>= 5;
assert_eq!(line.start, 10);
assert_eq!(line.end, 15);
Source§

impl<T: PartialOrd> Split<Line<T>> for Line<T>

Source§

fn split(self, at: Self) -> Option<(Self, Self)>

Splits a line by another line

§Example
use lset::*;
let line = Line::from(2..5);
assert_eq!(line.split(Line::from(1..4)), None);
assert_eq!(line.split(Line::from(3..6)), None);
assert_eq!(line.split(Line::from(2..2)), None);
assert_eq!(line.split(Line::from(2..3)), Some((Line::from(2..2), Line::from(3..5))));
assert_eq!(line.split(Line::from(3..3)), None);
assert_eq!(line.split(Line::from(3..4)), Some((Line::from(2..3), Line::from(4..5))));
assert_eq!(line.split(Line::from(4..4)), None);
assert_eq!(line.split(Line::from(4..5)), Some((Line::from(2..4), Line::from(5..5))));
assert_eq!(line.split(Line::from(5..5)), None);
assert_eq!(line.split(line), Some((Line::from(2..2), Line::from(5..5))));
Source§

impl<T: PartialOrd + Copy> Split<T> for Line<T>

Source§

fn split(self, at: T) -> Option<(Self, Self)>

Splits a line at a point

§Example
use lset::*;
let line = Line::from(2..4);
assert_eq!(line.split(1), None);
assert_eq!(line.split(2), Some((Line::from(2..2), line)));
assert_eq!(line.split(3), Some((Line::from(2..3), Line::from(3..4))));
assert_eq!(line.split(4), Some((line, Line::from(4..4))));
assert_eq!(line.split(5), None);
Source§

impl<T: Sub<T, Output = T>> Sub<T> for Line<T>

Source§

fn sub(self, rhs: T) -> Self::Output

Shrinks the line by the size of the operand

§Example
let before = lset::Line::new(5, 10);
let after = before - 5;
assert_eq!(after.start, 5);
assert_eq!(after.end, 5);
Source§

type Output = Line<T>

The resulting type after applying the - operator.
Source§

impl<T: SubAssign<T>> SubAssign<T> for Line<T>

Source§

fn sub_assign(&mut self, rhs: T)

Shrinks the line by the size of the operand

§Example
let mut line = lset::Line::new(5, 10);
line -= 5;
assert_eq!(line.start, 5);
assert_eq!(line.end, 5);
Source§

impl<T: Copy> Copy for Line<T>

Source§

impl<T: Eq> Eq for Line<T>

Source§

impl<T> StructuralPartialEq for Line<T>

Auto Trait Implementations§

§

impl<T> Freeze for Line<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Line<T>
where T: RefUnwindSafe,

§

impl<T> Send for Line<T>
where T: Send,

§

impl<T> Sync for Line<T>
where T: Sync,

§

impl<T> Unpin for Line<T>
where T: Unpin,

§

impl<T> UnwindSafe for Line<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.