Expand description
A line segment.
Tuple Fields
0: Pt2D
1: Pt2D
Implementations
sourceimpl Line
impl Line
sourcepub fn new(pt1: Pt2D, pt2: Pt2D) -> Result<Line>
pub fn new(pt1: Pt2D, pt2: Pt2D) -> Result<Line>
Creates a line segment between two points, which must not be the same
sourcepub fn must_new(pt1: Pt2D, pt2: Pt2D) -> Line
pub fn must_new(pt1: Pt2D, pt2: Pt2D) -> Line
Equivalent to Line::new(pt1, pt2).unwrap()
. Use this to effectively document an assertion
at the call-site.
sourcepub fn infinite(&self) -> InfiniteLine
pub fn infinite(&self) -> InfiniteLine
Returns an infinite line passing through this line’s two points.
sourcepub fn points(&self) -> Vec<Pt2D>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn points(&self) -> Vec<Pt2D>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns the two points in this line segment.
sourcepub fn to_polyline(&self) -> PolyLine
pub fn to_polyline(&self) -> PolyLine
Returns a polyline containing these two points.
sourcepub fn make_polygons(&self, thickness: Distance) -> Polygon
pub fn make_polygons(&self, thickness: Distance) -> Polygon
Returns a thick line segment.
sourcepub fn intersection(&self, other: &Line) -> Option<Pt2D>
pub fn intersection(&self, other: &Line) -> Option<Pt2D>
If two line segments intersect – including endpoints – return the point where they hit. Undefined if the two lines have more than one intersection point!
sourcepub fn crosses(&self, other: &Line) -> bool
pub fn crosses(&self, other: &Line) -> bool
Determine if two line segments intersect, but more so than just two endpoints touching.
sourcepub fn intersection_infinite(&self, other: &InfiniteLine) -> Option<Pt2D>
pub fn intersection_infinite(&self, other: &InfiniteLine) -> Option<Pt2D>
If the line segment intersects with an infinite line – including endpoints – return the point where they hit. Undefined if the segment and infinite line intersect at more than one point!
sourcepub fn shift_right(&self, width: Distance) -> Line
pub fn shift_right(&self, width: Distance) -> Line
Perpendicularly shifts the line over to the right. Width must be non-negative.
sourcepub fn shift_left(&self, width: Distance) -> Line
pub fn shift_left(&self, width: Distance) -> Line
Perpendicularly shifts the line over to the left. Width must be non-negative.
sourcepub fn shift_either_direction(&self, width: Distance) -> Line
pub fn shift_either_direction(&self, width: Distance) -> Line
Perpendicularly shifts the line to the right if positive or left if negative.
sourcepub fn dist_along(&self, dist: Distance) -> Result<Pt2D>
pub fn dist_along(&self, dist: Distance) -> Result<Pt2D>
Returns a point along the line segment, unless the distance exceeds the segment’s length.
sourcepub fn must_dist_along(&self, dist: Distance) -> Pt2D
pub fn must_dist_along(&self, dist: Distance) -> Pt2D
Equivalent to self.dist_along(dist).unwrap()
. Use this to document an assertion at the
call-site.
pub fn unbounded_dist_along(&self, dist: Distance) -> Pt2D
pub fn unbounded_percent_along(&self, percent: f64) -> Pt2D
pub fn percent_along(&self, percent: f64) -> Result<Pt2D>
pub fn slice(&self, from: Distance, to: Distance) -> Result<Line>
sourcepub fn percent_slice(&self, from: f64, to: f64) -> Result<Line>
pub fn percent_slice(&self, from: f64, to: f64) -> Result<Line>
Returns a subset of this line, with two percentages along the line’s length.
pub fn middle(&self) -> Result<Pt2D>
pub fn contains_pt(&self, pt: Pt2D) -> bool
pub fn dist_along_of_point(&self, pt: Pt2D) -> Option<Distance>
pub fn percent_along_of_point(&self, pt: Pt2D) -> Option<f64>
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Line
impl<'de> Deserialize<'de> for Line
sourcefn 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
impl StructuralPartialEq for Line
Auto Trait Implementations
impl RefUnwindSafe for Line
impl Send for Line
impl Sync for Line
impl Unpin for Line
impl UnwindSafe for Line
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more