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: PImplementations§
Source§impl<P: Copy> Line<P>
impl<P: Copy> Line<P>
Sourcepub fn from_origin_direction<V>(origin: P, direction: V) -> Selfwhere
P: Add<V, Output = P>,
pub fn from_origin_direction<V>(origin: P, direction: V) -> Selfwhere
P: Add<V, Output = P>,
initialize line from vector
Sourcepub fn to_bspline(self) -> BSplineCurve<P>
pub fn to_bspline(self) -> BSplineCurve<P>
to a bspline curve
Source§impl<P> Line<P>
impl<P> Line<P>
Sourcepub fn projection(self, point: P) -> P
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));Sourcepub fn distance_to_point(self, point: P) -> f64
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);Sourcepub fn distance_to_point_as_segment(self, point: P) -> f64
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>
impl Line<Point2>
Sourcepub fn intersection(self, other: Line<Point2>) -> Option<(f64, f64, Point2)>
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>
impl<P: ControlPoint<f64>> BoundedCurve for Line<P>
Source§impl<'de, P> Deserialize<'de> for Line<P>where
P: Deserialize<'de>,
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>,
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>
impl<P: Copy> Invertible for Line<P>
Source§impl<P: ControlPoint<f64>> ParameterDivision1D for Line<P>
impl<P: ControlPoint<f64>> ParameterDivision1D for Line<P>
Source§impl<P: ControlPoint<f64>> ParametricCurve for Line<P>
impl<P: ControlPoint<f64>> ParametricCurve for Line<P>
Source§fn parameter_range(&self) -> ParameterRange
fn parameter_range(&self) -> ParameterRange
Return 0.0..=1.0 i.e. we regard it as a segment
Source§impl<P> SearchNearestParameter<D1> for Line<P>
impl<P> SearchNearestParameter<D1> for Line<P>
Source§impl<P> SearchParameter<D1> for Line<P>
impl<P> SearchParameter<D1> for Line<P>
Source§impl<P: EuclideanSpace, M: Transform<P>> Transformed<M> for Line<P>
impl<P: EuclideanSpace, M: Transform<P>> Transformed<M> for Line<P>
Source§fn transform_by(&mut self, trans: M)
fn transform_by(&mut self, trans: M)
transform by
trans.Source§fn transformed(&self, trans: M) -> Self
fn transformed(&self, trans: M) -> Self
transformed geometry by
trans.impl<P: Copy> Copy for Line<P>
impl<P: Eq> Eq for Line<P>
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§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)