#[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: TThe start point
end: TThe first point excluded by the set
Implementations§
Source§impl<T> Line<T>
impl<T> Line<T>
Source§impl<T: PartialOrd> Line<T>
impl<T: PartialOrd> Line<T>
Sourcepub fn intersection(self, other: Self) -> Option<Self>
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: AddAssign<T>> AddAssign<T> for Line<T>
impl<T: AddAssign<T>> AddAssign<T> for Line<T>
Source§fn add_assign(&mut self, rhs: T)
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: PartialOrd> Contains<Line<T>> for Line<T>
impl<T: PartialOrd> Contains<Line<T>> for Line<T>
Source§fn contains(&self, value: &Self) -> bool
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>
impl<T: PartialOrd> Contains<T> for Line<T>
Source§fn contains(&self, value: &T) -> bool
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: PartialOrd> PartialOrd for Line<T>
impl<T: PartialOrd> PartialOrd for Line<T>
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
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));Source§impl<T: Copy + SubAssign<T>> ShlAssign<T> for Line<T>
impl<T: Copy + SubAssign<T>> ShlAssign<T> for Line<T>
Source§fn shl_assign(&mut self, rhs: T)
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 + AddAssign<T>> ShrAssign<T> for Line<T>
impl<T: Copy + AddAssign<T>> ShrAssign<T> for Line<T>
Source§fn shr_assign(&mut self, rhs: T)
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>
impl<T: PartialOrd> Split<Line<T>> for Line<T>
Source§fn split(self, at: Self) -> Option<(Self, Self)>
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>
impl<T: PartialOrd + Copy> Split<T> for Line<T>
Source§fn split(self, at: T) -> Option<(Self, Self)>
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: SubAssign<T>> SubAssign<T> for Line<T>
impl<T: SubAssign<T>> SubAssign<T> for Line<T>
Source§fn sub_assign(&mut self, rhs: T)
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);impl<T: Copy> Copy for Line<T>
impl<T: Eq> Eq for Line<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more