pub struct Line<T = f64>where
T: CoordNum,{
pub start: Coord<T>,
pub end: Coord<T>,
}Available on crate feature
geo-types only.Expand description
Fields§
§start: Coord<T>§end: Coord<T>Implementations§
Source§impl<T> Line<T>where
T: CoordNum,
impl<T> Line<T>where
T: CoordNum,
Sourcepub fn new<C>(start: C, end: C) -> Line<T>
pub fn new<C>(start: C, end: C) -> Line<T>
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.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§
Source§impl<T> From<&Line<T>> for LineString<T>where
T: CoordNum,
impl<T> From<&Line<T>> for LineString<T>where
T: CoordNum,
Source§fn from(line: &Line<T>) -> LineString<T>
fn from(line: &Line<T>) -> LineString<T>
Converts to this type from the input type.
Source§impl<T> From<Line<T>> for LineString<T>where
T: CoordNum,
impl<T> From<Line<T>> for LineString<T>where
T: CoordNum,
Source§fn from(line: Line<T>) -> LineString<T>
fn from(line: Line<T>) -> LineString<T>
Converts to this type from the input type.
Source§impl<'a, T> GeometryTrait for &'a Line<T>where
T: CoordNum + 'a,
impl<'a, T> GeometryTrait for &'a Line<T>where
T: CoordNum + 'a,
Source§type PointType<'b> = Point<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type PointType<'b> = Point<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying Point, which implements PointTrait
Source§type LineStringType<'b> = LineString<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type LineStringType<'b> = LineString<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying LineString, which implements LineStringTrait
Source§type PolygonType<'b> = Polygon<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type PolygonType<'b> = Polygon<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying Polygon, which implements PolygonTrait
Source§type MultiPointType<'b> = MultiPoint<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type MultiPointType<'b> = MultiPoint<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying MultiPoint, which implements MultiPointTrait
Source§type MultiLineStringType<'b> = MultiLineString<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying MultiLineString, which implements MultiLineStringTrait
Source§type MultiPolygonType<'b> = MultiPolygon<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying MultiPolygon, which implements MultiPolygonTrait
Source§type GeometryCollectionType<'b> = GeometryCollection<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying GeometryCollection, which implements GeometryCollectionTrait
Source§type RectType<'b> = Rect<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type RectType<'b> = Rect<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying Rect, which implements RectTrait
Source§type TriangleType<'b> = Triangle<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type TriangleType<'b> = Triangle<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying Triangle, which implements TriangleTrait
Source§type LineType<'b> = Line<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type LineType<'b> = Line<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying Line, which implements LineTrait
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
The dimension of this geometry
Source§fn as_type(
&self,
) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
fn as_type( &self, ) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
Cast this geometry to a
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<T> GeometryTrait for Line<T>where
T: CoordNum,
impl<T> GeometryTrait for Line<T>where
T: CoordNum,
Source§type PointType<'b> = Point<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type PointType<'b> = Point<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying Point, which implements PointTrait
Source§type LineStringType<'b> = LineString<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type LineStringType<'b> = LineString<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying LineString, which implements LineStringTrait
Source§type PolygonType<'b> = Polygon<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type PolygonType<'b> = Polygon<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying Polygon, which implements PolygonTrait
Source§type MultiPointType<'b> = MultiPoint<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type MultiPointType<'b> = MultiPoint<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying MultiPoint, which implements MultiPointTrait
Source§type MultiLineStringType<'b> = MultiLineString<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type MultiLineStringType<'b> = MultiLineString<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying MultiLineString, which implements MultiLineStringTrait
Source§type MultiPolygonType<'b> = MultiPolygon<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type MultiPolygonType<'b> = MultiPolygon<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying MultiPolygon, which implements MultiPolygonTrait
Source§type GeometryCollectionType<'b> = GeometryCollection<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type GeometryCollectionType<'b> = GeometryCollection<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying GeometryCollection, which implements GeometryCollectionTrait
Source§type RectType<'b> = Rect<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type RectType<'b> = Rect<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying Rect, which implements RectTrait
Source§type TriangleType<'b> = Triangle<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type TriangleType<'b> = Triangle<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying Triangle, which implements TriangleTrait
Source§type LineType<'b> = Line<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'b
type LineType<'b> = Line<<Line<T> as GeometryTrait>::T> where Line<T>: 'b
The type of each underlying Line, which implements LineTrait
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
The dimension of this geometry
Source§fn as_type(
&self,
) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
fn as_type( &self, ) -> GeometryType<'_, Point<T>, LineString<T>, Polygon<T>, MultiPoint<T>, MultiLineString<T>, MultiPolygon<T>, GeometryCollection<T>, Rect<T>, Triangle<T>, Line<T>>
Cast this geometry to a
GeometryType enum, which allows for downcasting to a specific
typeSource§impl<'a, T> LineTrait for &'a Line<T>where
T: CoordNum,
impl<'a, T> LineTrait for &'a Line<T>where
T: CoordNum,
Source§type CoordType<'b> = &'a Coord<<&'a Line<T> as GeometryTrait>::T>
where
&'a Line<T>: 'b
type CoordType<'b> = &'a Coord<<&'a Line<T> as GeometryTrait>::T> where &'a Line<T>: 'b
The type of each underlying coordinate, which implements CoordTrait
Source§fn start(&self) -> <&'a Line<T> as LineTrait>::CoordType<'_>
fn start(&self) -> <&'a Line<T> as LineTrait>::CoordType<'_>
Access the start coordinate in this Line
Source§impl<T> LineTrait for Line<T>where
T: CoordNum,
impl<T> LineTrait for Line<T>where
T: CoordNum,
Source§type CoordType<'a> = &'a Coord<<Line<T> as GeometryTrait>::T>
where
Line<T>: 'a
type CoordType<'a> = &'a Coord<<Line<T> as GeometryTrait>::T> where Line<T>: 'a
The type of each underlying coordinate, which implements CoordTrait
Source§fn start(&self) -> <Line<T> as LineTrait>::CoordType<'_>
fn start(&self) -> <Line<T> as LineTrait>::CoordType<'_>
Access the start coordinate in this Line
Source§impl<T> ToWkt<T> for Line<T>
§Examples
use geo_types::{coord, Line};
use wkt::ToWkt;
let line = Line::<f64>::new(coord!(x: 1., y: 2.), coord!(x: 3., y: 4.));
assert_eq!(line.wkt_string(), "LINESTRING(1 2,3 4)");
impl<T> ToWkt<T> for Line<T>
§Examples
use geo_types::{coord, Line};
use wkt::ToWkt;
let line = Line::<f64>::new(coord!(x: 1., y: 2.), coord!(x: 3., y: 4.));
assert_eq!(line.wkt_string(), "LINESTRING(1 2,3 4)");Source§impl<T> TryFrom<Geometry<T>> for Line<T>where
T: CoordNum,
Convert a Geometry enum into its inner type.
impl<T> TryFrom<Geometry<T>> for Line<T>where
T: CoordNum,
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.
Source§impl<T> TryFrom<Wkt<T>> for Line<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
impl<T> TryFrom<Wkt<T>> for Line<T>where
T: CoordNum,
Fallibly convert this WKT primitive into this geo_types primitive
Source§impl<T> TryFromWkt<T> for Line<T>
impl<T> TryFromWkt<T> for Line<T>
impl<T> Copy for Line<T>
impl<T> Eq for Line<T>
impl<T> StructuralPartialEq for Line<T>where
T: CoordNum,
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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> ⓘ
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 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> ⓘ
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