pub struct LineSegment<S> {
pub from: Point<S>,
pub to: Point<S>,
}
Expand description
A linear segment.
Fields§
§from: Point<S>
§to: Point<S>
Implementations§
source§impl<S: Scalar> LineSegment<S>
impl<S: Scalar> LineSegment<S>
sourcepub fn x(&self, t: S) -> S
pub fn x(&self, t: S) -> S
Sample the x coordinate of the segment at t (expecting t between 0 and 1).
sourcepub fn y(&self, t: S) -> S
pub fn y(&self, t: S) -> S
Sample the y coordinate of the segment at t (expecting t between 0 and 1).
pub fn from(&self) -> Point<S>
pub fn to(&self) -> Point<S>
pub fn solve_t_for_x(&self, x: S) -> S
pub fn solve_t_for_y(&self, y: S) -> S
pub fn solve_y_for_x(&self, x: S) -> S
pub fn solve_x_for_y(&self, y: S) -> S
sourcepub fn flip(&self) -> Self
pub fn flip(&self) -> Self
Returns an inverted version of this segment where the beginning and the end points are swapped.
sourcepub fn split_range(&self, t_range: Range<S>) -> Self
pub fn split_range(&self, t_range: Range<S>) -> Self
Return the sub-segment inside a given range of t.
This is equivalent splitting at the range’s end points.
sourcepub fn before_split(&self, t: S) -> Self
pub fn before_split(&self, t: S) -> Self
Return the segment before the split point.
sourcepub fn after_split(&self, t: S) -> Self
pub fn after_split(&self, t: S) -> Self
Return the segment after the split point.
pub fn split_at_x(&self, x: S) -> (Self, Self)
sourcepub fn bounding_box(&self) -> Box2D<S>
pub fn bounding_box(&self) -> Box2D<S>
Return the smallest rectangle containing this segment.
sourcepub fn to_vector(&self) -> Vector<S>
pub fn to_vector(&self) -> Vector<S>
Returns the vector between this segment’s from
and to
points.
sourcepub fn square_length(&self) -> S
pub fn square_length(&self) -> S
Computes the squared length of this segment.
sourcepub fn set_length(&mut self, new_length: S)
pub fn set_length(&mut self, new_length: S)
Changes the segment’s length, moving destination point.
pub fn translate(&mut self, by: Vector<S>) -> Self
sourcepub fn transformed<T: Transformation<S>>(&self, transform: &T) -> Self
pub fn transformed<T: Transformation<S>>(&self, transform: &T) -> Self
Applies the transform to this segment and returns the results.
sourcepub fn intersection_t(&self, other: &Self) -> Option<(S, S)>
pub fn intersection_t(&self, other: &Self) -> Option<(S, S)>
Computes the intersection (if any) between this segment and another one.
The result is provided in the form of the t
parameter of each
segment. To get the intersection point, sample one of the segments
at the corresponding value.
pub fn intersection(&self, other: &Self) -> Option<Point<S>>
pub fn line_intersection_t(&self, line: &Line<S>) -> Option<S>
pub fn line_intersection(&self, line: &Line<S>) -> Option<Point<S>>
pub fn horizontal_line_intersection_t(&self, y: S) -> Option<S>
pub fn vertical_line_intersection_t(&self, x: S) -> Option<S>
pub fn horizontal_line_intersection(&self, y: S) -> Option<Point<S>>
pub fn vertical_line_intersection(&self, x: S) -> Option<Point<S>>
pub fn intersects(&self, other: &Self) -> bool
pub fn intersects_line(&self, line: &Line<S>) -> bool
pub fn overlaps_line(&self, line: &Line<S>) -> bool
pub fn overlaps_segment(&self, other: &LineSegment<S>) -> bool
pub fn contains_segment(&self, other: &LineSegment<S>) -> bool
sourcepub fn clipped_x(&self, clip: Range<S>) -> Option<Self>
pub fn clipped_x(&self, clip: Range<S>) -> Option<Self>
Horizontally clip this segment against a range of the x axis.
sourcepub fn clipped_y(&self, clip: Range<S>) -> Option<Self>
pub fn clipped_y(&self, clip: Range<S>) -> Option<Self>
Vertically clip this segment against a range of the y axis.
sourcepub fn distance_to_point(&self, p: Point<S>) -> S
pub fn distance_to_point(&self, p: Point<S>) -> S
Computes the distance between this segment and a point.
sourcepub fn square_distance_to_point(&self, p: Point<S>) -> S
pub fn square_distance_to_point(&self, p: Point<S>) -> S
Computes the squared distance between this segment and a point.
Can be useful to save a square root and a division when comparing against a distance that can be squared.
sourcepub fn closest_point(&self, p: Point<S>) -> Point<S>
pub fn closest_point(&self, p: Point<S>) -> Point<S>
Computes the closest point on this segment to p
.
pub fn to_f32(&self) -> LineSegment<f32>
pub fn to_f64(&self) -> LineSegment<f64>
Trait Implementations§
source§impl<S: Clone> Clone for LineSegment<S>
impl<S: Clone> Clone for LineSegment<S>
source§fn clone(&self) -> LineSegment<S>
fn clone(&self) -> LineSegment<S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<S: Debug> Debug for LineSegment<S>
impl<S: Debug> Debug for LineSegment<S>
source§impl<S: PartialEq> PartialEq for LineSegment<S>
impl<S: PartialEq> PartialEq for LineSegment<S>
source§impl<S: Scalar> Segment for LineSegment<S>
impl<S: Scalar> Segment for LineSegment<S>
type Scalar = S
source§fn derivative(&self, _t: S) -> Vector<S>
fn derivative(&self, _t: S) -> Vector<S>
source§fn before_split(&self, t: S) -> Self
fn before_split(&self, t: S) -> Self
source§fn after_split(&self, t: S) -> Self
fn after_split(&self, t: S) -> Self
source§fn split_range(&self, t_range: Range<S>) -> Self
fn split_range(&self, t_range: Range<S>) -> Self
source§fn approximate_length(&self, _tolerance: S) -> S
fn approximate_length(&self, _tolerance: S) -> S
source§fn for_each_flattened_with_t(
&self,
_tolerance: Self::Scalar,
callback: &mut dyn FnMut(&LineSegment<S>, Range<S>),
)
fn for_each_flattened_with_t( &self, _tolerance: Self::Scalar, callback: &mut dyn FnMut(&LineSegment<S>, Range<S>), )
impl<S: Copy> Copy for LineSegment<S>
impl<S> StructuralPartialEq for LineSegment<S>
Auto Trait Implementations§
impl<S> Freeze for LineSegment<S>where
S: Freeze,
impl<S> RefUnwindSafe for LineSegment<S>where
S: RefUnwindSafe,
impl<S> Send for LineSegment<S>where
S: Send,
impl<S> Sync for LineSegment<S>where
S: Sync,
impl<S> Unpin for LineSegment<S>where
S: Unpin,
impl<S> UnwindSafe for LineSegment<S>where
S: 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
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)
clone_to_uninit
)