pub struct Line<T> where
T: CoordNum, {
pub start: Coordinate<T>,
pub end: Coordinate<T>,
}Expand description
A line segment made up of exactly two
Coordinates.
Semantics
The interior and boundary are defined as with a
LineString with the two end points.
Fields
start: Coordinate<T>end: Coordinate<T>Implementations
sourceimpl<T> Line<T> where
T: CoordNum,
impl<T> Line<T> where
T: CoordNum,
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 delta(&self) -> Coordinate<T>
pub fn delta(&self) -> Coordinate<T>
Calculate the difference in coordinates (Δx, Δy).
sourcepub fn dx(&self) -> T
pub fn dx(&self) -> T
Calculate the difference in ‘x’ components (Δx).
Equivalent to:
line.end.x - line.start.xsourcepub fn dy(&self) -> T
pub fn dy(&self) -> T
Calculate the difference in ‘y’ components (Δy).
Equivalent to:
line.end.y - line.start.ysourcepub 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.xNote 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: CoordNum> From<Line<T>> for LineString<T>
impl<T: CoordNum> From<Line<T>> for LineString<T>
sourceimpl<T: CoordNum> TryFrom<Geometry<T>> for Line<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for Line<T>
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
impl<T: Copy> Copy for Line<T> where
T: CoordNum,
impl<T: Eq> Eq for Line<T> where
T: CoordNum,
impl<T> StructuralEq for Line<T> where
T: CoordNum,
impl<T> StructuralPartialEq for Line<T> where
T: CoordNum,
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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more
