[][src]Struct rstar::primitives::Line

pub struct Line<P> where
    P: Point
{ pub from: P, pub to: P, }

A line defined by a start and and end point.

This struct can be inserted directly into an r-tree.

Type parameters

P: The line's Point type.

Example

use rstar::primitives::Line;
use rstar::{RTree, RTreeObject};

let line_1 = Line::new([0.0, 0.0], [1.0, 1.0]);
let line_2 = Line::new([0.0, 0.0], [-1.0, 1.0]);
let tree = RTree::bulk_load(vec![line_1, line_2]);

assert!(tree.contains(&line_1));

Fields

from: P

The line's start point

to: P

The line's end point.

Implementations

impl<P> Line<P> where
    P: Point
[src]

pub fn new(from: P, to: P) -> Self[src]

Creates a new line between two points.

impl<P> Line<P> where
    P: Point
[src]

pub fn length_2(&self) -> P::Scalar[src]

Returns the squared length of this line.

Example

use rstar::primitives::Line;

let line = Line::new([3, 3], [7, 6]);
assert_eq!(line.length_2(), 25);

pub fn nearest_point(&self, query_point: &P) -> P[src]

Returns the nearest point on this line relative to a given point.

Example

use rstar::primitives::Line;

let line = Line::new([0.0, 0.0], [1., 1.]);
assert_eq!(line.nearest_point(&[0.0, 0.0]), [0.0, 0.0]);
assert_eq!(line.nearest_point(&[1.0, 0.0]), [0.5, 0.5]);
assert_eq!(line.nearest_point(&[10., 12.]), [1.0, 1.0]);

Trait Implementations

impl<P: Clone> Clone for Line<P> where
    P: Point
[src]

impl<P: Copy> Copy for Line<P> where
    P: Point
[src]

impl<P: Debug> Debug for Line<P> where
    P: Point
[src]

impl<P: Eq> Eq for Line<P> where
    P: Point
[src]

impl<P: Ord> Ord for Line<P> where
    P: Point
[src]

impl<P: PartialEq> PartialEq<Line<P>> for Line<P> where
    P: Point
[src]

impl<P: PartialOrd> PartialOrd<Line<P>> for Line<P> where
    P: Point
[src]

impl<P> PointDistance for Line<P> where
    P: Point
[src]

impl<P> RTreeObject for Line<P> where
    P: Point
[src]

type Envelope = AABB<P>

The object's envelope type. Usually, AABB will be the right choice. This type also defines the objects dimensionality. Read more

impl<P> StructuralEq for Line<P> where
    P: Point
[src]

impl<P> StructuralPartialEq for Line<P> where
    P: Point
[src]

Auto Trait Implementations

impl<P> RefUnwindSafe for Line<P> where
    P: RefUnwindSafe

impl<P> Send for Line<P> where
    P: Send

impl<P> Sync for Line<P> where
    P: Sync

impl<P> Unpin for Line<P> where
    P: Unpin

impl<P> UnwindSafe for Line<P> where
    P: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.