Line

Struct Line 

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

Source

pub fn from_endpoints(start: Point<T>, end: Point<T>) -> Line<T>

Source

pub fn is_empty(&self) -> bool

Return true if this line has zero length.

Source

pub fn width(&self) -> T

Return the difference between the starting and ending X coordinates of the line.

Source

pub fn height(&self) -> T

Return the difference between the starting and ending Y coordinates of the line.

Source

pub fn is_horizontal(&self) -> bool

Return true if the Y coordinate of the line’s start and end points are the same.

Source

pub fn reverse(&self) -> Line<T>

Return a copy of this line with the start and end points swapped.

Source

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.

Source

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.

Source

pub fn vertical_overlap(&self, other: Line<T>) -> T

Return the number of pixels by which this line overlaps other in the vertical direction.

Source

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>

Source

pub fn distance(&self, p: PointF) -> f32

Return the euclidean distance between a point and the closest coordinate that lies on the line.

Source

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>

Source

pub fn center(&self) -> PointF

Return the midpoint between the start and end points of the line.

Source

pub fn x_for_y(&self, y: f32) -> Option<f32>

Return the X coordinate that corresponds to a given Y coordinate on the line.

Returns None if the Y coordinate is not on the line or the line is horizontal.

Source

pub fn y_for_x(&self, x: f32) -> Option<f32>

Return the Y coordinate that corresponds to a given X coordinate on the line.

Returns None if the X coordinate is not on the line or the line is vertical.

Source§

impl Line<i32>

Source

pub fn to_f32(&self) -> LineF

Source

pub fn distance(&self, p: Point) -> f32

Return the euclidean distance between a point and the closest coordinate that lies on the line.

Source

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>

Source§

type Coord = T

Coordinate type of bounding rect.
Source§

fn bounding_rect(&self) -> Rect<T>

Return the smallest axis-aligned bounding rect which contains this shape.
Source§

impl<T: Clone + Coord> 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: Coord> Debug for Line<T>

Source§

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

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

impl<T: PartialEq + Coord> 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: Copy + Coord> Copy for Line<T>

Source§

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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

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.