pub struct Line<T: Coord = i32> {
pub start: Point<T>,
pub end: Point<T>,
}
Expand description
A bounded line segment defined by a start and end point.
Fields§
§start: Point<T>
§end: Point<T>
Implementations§
Source§impl<T: Coord> Line<T>
impl<T: Coord> Line<T>
pub fn from_endpoints(start: Point<T>, end: Point<T>) -> Line<T>
Sourcepub fn width(&self) -> T
pub fn width(&self) -> T
Return the difference between the starting and ending X coordinates of the line.
Sourcepub fn height(&self) -> T
pub fn height(&self) -> T
Return the difference between the starting and ending Y coordinates of the line.
Sourcepub fn is_horizontal(&self) -> bool
pub fn is_horizontal(&self) -> bool
Return true if the Y coordinate of the line’s start and end points are the same.
Sourcepub fn reverse(&self) -> Line<T>
pub fn reverse(&self) -> Line<T>
Return a copy of this line with the start and end points swapped.
Sourcepub fn downwards(&self) -> Line<T>
pub fn downwards(&self) -> Line<T>
Return a copy of this line with the same endpoints but swapped if
needed so that end.y >= start.y
.
Sourcepub fn rightwards(&self) -> Line<T>
pub fn rightwards(&self) -> Line<T>
Return a copy of this line with the same endpoints but swapped if
needed so that end.x >= start.x
.
Sourcepub fn vertical_overlap(&self, other: Line<T>) -> T
pub fn vertical_overlap(&self, other: Line<T>) -> T
Return the number of pixels by which this line overlaps other
in the
vertical direction.
Sourcepub fn horizontal_overlap(&self, other: Line<T>) -> T
pub fn horizontal_overlap(&self, other: Line<T>) -> T
Return the number of pixels by which this line overlaps other
in the
horizontal direction.
Source§impl Line<f32>
impl Line<f32>
Sourcepub fn distance(&self, p: PointF) -> f32
pub fn distance(&self, p: PointF) -> f32
Return the euclidean distance between a point and the closest coordinate that lies on the line.
Sourcepub fn intersects(&self, other: Line<f32>) -> bool
pub fn intersects(&self, other: Line<f32>) -> bool
Test whether this line segment intersects other
at a single point.
Returns false if the line segments do not intersect, or are coincident (ie. overlap for part of their lengths).
Source§impl Line<f32>
impl Line<f32>
Sourcepub fn center(&self) -> PointF
pub fn center(&self) -> PointF
Return the midpoint between the start and end points of the line.
Source§impl Line<i32>
impl Line<i32>
pub fn to_f32(&self) -> LineF
Sourcepub fn distance(&self, p: Point) -> f32
pub fn distance(&self, p: Point) -> f32
Return the euclidean distance between a point and the closest coordinate that lies on the line.
Sourcepub fn intersects(&self, other: Line) -> bool
pub fn intersects(&self, other: Line) -> bool
Test whether this line segment intersects other
at a single point.
Returns false if the line segments do not intersect, or are coincident (ie. overlap for part of their lengths).
Trait Implementations§
Source§impl<T: Coord> BoundingRect for Line<T>
impl<T: Coord> BoundingRect for Line<T>
impl<T: Copy + Coord> Copy for Line<T>
impl<T: Coord> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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