pub struct Line<T: CoordNum = f64> {
pub start: Coord<T>,
pub end: Coord<T>,
}
Expand description
Fields§
§start: Coord<T>
§end: Coord<T>
Implementations§
source§impl<T: CoordNum> Line<T>
impl<T: CoordNum> Line<T>
sourcepub fn new<C>(start: C, end: C) -> Self
pub fn new<C>(start: C, end: C) -> Self
Creates a new line segment.
§Examples
use geo_types::{coord, Line};
let line = Line::new(coord! { x: 0., y: 0. }, coord! { x: 1., y: 2. });
assert_eq!(line.start, coord! { x: 0., y: 0. });
assert_eq!(line.end, coord! { 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§
source§impl<'de, T> Deserialize<'de> for Line<T>where
T: Deserialize<'de> + CoordNum,
impl<'de, T> Deserialize<'de> for Line<T>where
T: Deserialize<'de> + CoordNum,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<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 + CoordNum> Copy for Line<T>
impl<T: Eq + CoordNum> Eq for Line<T>
impl<T: CoordNum> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)