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>
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§
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
)