pub struct Line<T>where
T: CoordinateType,{
pub start: Coordinate<T>,
pub end: Coordinate<T>,
}
Expand description
A line segment made up of exactly two Point
s
Fields
start: Coordinate<T>
end: Coordinate<T>
Implementations
sourceimpl<T> Line<T>where
T: CoordinateType,
impl<T> Line<T>where
T: CoordinateType,
sourcepub fn new<C>(start: C, end: C) -> Line<T>where
C: Into<Coordinate<T>>,
pub fn new<C>(start: C, end: C) -> Line<T>where
C: Into<Coordinate<T>>,
Creates a new line segment.
Examples
use geo_types::{Coordinate, Line};
let line = Line::new(
Coordinate { x: 0., y: 0. },
Coordinate { x: 1., y: 2. },
);
assert_eq!(line.start, Coordinate { x: 0., y: 0. });
assert_eq!(line.end, Coordinate { x: 1., y: 2. });
sourcepub fn dx(&self) -> T
pub fn dx(&self) -> T
Calculate the difference in ‘x’ components (Δx).
Equivalent to:
line.end.x - line.start.x
sourcepub fn dy(&self) -> T
pub fn dy(&self) -> T
Calculate the difference in ‘y’ components (Δy).
Equivalent to:
line.end.y - line.start.y
sourcepub fn slope(&self) -> T
pub fn slope(&self) -> T
Calculate the slope (Δy/Δx).
Equivalent to:
line.dy() / line.dx()
Note that:
Line::new(a, b).slope() ==
Line::new(b, a).slope()
sourcepub fn determinant(&self) -> T
pub fn determinant(&self) -> T
Calculate the determinant of the line.
Equivalent to:
line.start.x * line.end.y -
line.start.y * line.end.x
Note that:
Line::new(a, b).determinant() ==
-Line::new(b, a).determinant()
pub fn start_point(&self) -> Point<T>
pub fn end_point(&self) -> Point<T>
pub fn points(&self) -> (Point<T>, Point<T>)
Trait Implementations
sourceimpl<T: Clone> Clone for Line<T>where
T: CoordinateType,
impl<T: Clone> Clone for Line<T>where
T: CoordinateType,
sourceimpl<T: Debug> Debug for Line<T>where
T: CoordinateType,
impl<T: Debug> Debug for Line<T>where
T: CoordinateType,
sourceimpl<T: PartialEq> PartialEq<Line<T>> for Line<T>where
T: CoordinateType,
impl<T: PartialEq> PartialEq<Line<T>> for Line<T>where
T: CoordinateType,
impl<T: Copy> Copy for Line<T>where
T: CoordinateType,
impl<T> StructuralPartialEq for Line<T>where
T: CoordinateType,
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more