Struct truck_geometry::specifieds::Line

source ·
pub struct Line<P>(pub P, pub P);
Expand description

line

§Example

use truck_geometry::prelude::*;
let line = Line(Point2::new(0.0, 0.0), Point2::new(1.0, 1.0));
assert_near!(line.subs(0.5), Point2::new(0.5, 0.5));

Tuple Fields§

§0: P§1: P

Implementations§

source§

impl<P: Copy> Line<P>

source

pub fn from_origin_direction<V>(origin: P, direction: V) -> Self
where P: Add<V, Output = P>,

initialize line from vector

source

pub fn to_bspline(self) -> BSplineCurve<P>

to a bspline curve

source§

impl<P> Line<P>
where P: EuclideanSpace<Scalar = f64>, P::Diff: InnerSpace<Scalar = f64>,

source

pub fn projection(self, point: P) -> P

Returns the projected point to the line.

§Examples
use truck_geometry::prelude::*;
let line = Line(Point2::new(0.0, 0.0), Point2::new(1.0, 2.0));
let pt = Point2::new(0.0, 1.0);
assert_near!(line.projection(pt), Point2::new(0.4, 0.8));
source

pub fn distance_to_point(self, point: P) -> f64

Returns the distance between the line and the point point.

§Examples
use truck_geometry::prelude::*;
let line = Line(Point2::new(0.0, 0.0), Point2::new(3.0, 4.0));

// The foot of the perpendicular line is on a line segment
let pt = Point2::new(3.0, 0.0);
assert_near!(line.distance_to_point(pt), 2.4);

// The foot of the perpendicular line is not on a line segment
let pt = Point2::new(0.0, -4.0);
assert_near!(line.distance_to_point(pt), 2.4);
source

pub fn distance_to_point_as_segment(self, point: P) -> f64

Returns the distance between the sengment and the point point.

§Examples
use truck_geometry::prelude::*;
let line = Line(Point2::new(0.0, 0.0), Point2::new(3.0, 4.0));

// The foot of the perpendicular line is on a line segment
let pt = Point2::new(3.0, 0.0);
assert_near!(line.distance_to_point_as_segment(pt), 2.4);

// The foot of the perpendicular line is not on a line segment
let pt = Point2::new(0.0, -4.0);
assert_near!(line.distance_to_point_as_segment(pt), 4.0);
source§

impl Line<Point2>

source

pub fn intersection(self, other: Line<Point2>) -> Option<(f64, f64, Point2)>

Returns the intersection of two lines and its parameters.

§Examples
use truck_geometry::prelude::*;
let line0 = Line(Point2::new(0.0, 0.0), Point2::new(9.0, 3.0));
let line1 = Line(Point2::new(0.0, 6.0), Point2::new(9.0, 0.0));
let (s, t, p) = line0.intersection(line1).unwrap();
assert_near!(line0.subs(s), Point2::new(6.0, 2.0));
assert_near!(line1.subs(t), Point2::new(6.0, 2.0));
assert_near!(p, Point2::new(6.0, 2.0));
§Failures

Returns None if two lines are parallel.

use truck_geometry::prelude::*;
let line0 = Line(Point2::new(0.0, 0.0), Point2::new(9.0, 3.0));
let line1 = Line(Point2::new(-1.0, 0.0), Point2::new(8.0, 3.0));
assert!(line0.intersection(line1).is_none());

Trait Implementations§

source§

impl<P: ControlPoint<f64>> BoundedCurve for Line<P>

source§

fn range_tuple(&self) -> (f64, f64)

Return the ends of parameter_range by tuple.
source§

fn front(&self) -> Self::Point

The front end point of the curve.
source§

fn back(&self) -> Self::Point

The back end point of the curve.
source§

impl<P: Clone> Clone for Line<P>

source§

fn clone(&self) -> Line<P>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<P: ControlPoint<f64>> Cut for Line<P>

source§

fn cut(&mut self, t: f64) -> Self

Cuts one curve into two curves. Assigns the former curve to self and returns the later curve.
source§

impl<P: Debug> Debug for Line<P>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, P> Deserialize<'de> for Line<P>
where P: Deserialize<'de>,

source§

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<P: Copy> Invertible for Line<P>

source§

fn invert(&mut self)

Inverts self
source§

fn inverse(&self) -> Self

Returns the inverse.
source§

impl<P: ControlPoint<f64>> ParameterDivision1D for Line<P>

source§

type Point = P

The curve is in the space of Self::Point.
source§

fn parameter_division(&self, range: (f64, f64), _: f64) -> (Vec<f64>, Vec<P>)

Creates the curve division (parameters, corresponding points). Read more
source§

impl<P: ControlPoint<f64>> ParametricCurve for Line<P>

source§

fn parameter_range(&self) -> ParameterRange

Return 0.0..=1.0 i.e. we regard it as a segment

source§

type Point = P

The curve is in the space of Self::Point.
source§

type Vector = <P as ControlPoint<f64>>::Diff

The derivation vector of the curve.
source§

fn subs(&self, t: f64) -> Self::Point

Substitutes the parameter t.
source§

fn der(&self, _: f64) -> Self::Vector

Returns the derivation.
source§

fn der2(&self, _: f64) -> Self::Vector

Returns the 2nd-order derivation.
source§

fn try_range_tuple(&self) -> Option<(f64, f64)>

Return the ends of parameter_range by tuple. If the range is unbounded, return `None``.
source§

fn period(&self) -> Option<f64>

None in default implementation; Some(period) if periodic.
source§

impl<P: PartialEq> PartialEq for Line<P>

source§

fn eq(&self, other: &Line<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<P> SearchNearestParameter<D1> for Line<P>
where P: ControlPoint<f64>, P::Diff: InnerSpace<Scalar = f64>,

source§

type Point = P

point
source§

fn search_nearest_parameter<H: Into<SPHint1D>>( &self, pt: P, _: H, _: usize, ) -> Option<f64>

Search nearest parameter t such that self.subs(t) is nearest point.
Returns None if could not find such parameter.
source§

impl<P> SearchParameter<D1> for Line<P>
where P: ControlPoint<f64> + Tolerance, P::Diff: InnerSpace<Scalar = f64>,

source§

type Point = P

point
source§

fn search_parameter<H: Into<SPHint1D>>( &self, pt: P, _: H, _: usize, ) -> Option<f64>

Search parameter t such that self.subs(t) is near point.
Returns None if could not find such parameter.
source§

impl<P> Serialize for Line<P>
where P: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<P: EuclideanSpace, M: Transform<P>> Transformed<M> for Line<P>

source§

fn transform_by(&mut self, trans: M)

transform by trans.
source§

fn transformed(&self, trans: M) -> Self

transformed geometry by trans.
source§

impl<P: Copy> Copy for Line<P>

source§

impl<P: Eq> Eq for Line<P>

source§

impl<P> StructuralPartialEq for Line<P>

Auto Trait Implementations§

§

impl<P> Freeze for Line<P>
where P: Freeze,

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<C> ParametricCurve2D for C
where C: ParametricCurve<Point = Point2<f64>, Vector = Vector2<f64>>,

source§

impl<C> ParametricCurve3D for C
where C: ParametricCurve<Point = Point3<f64>, Vector = Vector3<f64>>,