lyon_geom

Struct LineSegment

source
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>

source

pub fn sample(&self, t: S) -> Point<S>

Sample the segment at t (expecting t between 0 and 1).

source

pub fn x(&self, t: S) -> S

Sample the x coordinate of the segment at t (expecting t between 0 and 1).

source

pub fn y(&self, t: S) -> S

Sample the y coordinate of the segment at t (expecting t between 0 and 1).

source

pub fn from(&self) -> Point<S>

source

pub fn to(&self) -> Point<S>

source

pub fn solve_t_for_x(&self, x: S) -> S

source

pub fn solve_t_for_y(&self, y: S) -> S

source

pub fn solve_y_for_x(&self, x: S) -> S

source

pub fn solve_x_for_y(&self, y: S) -> S

source

pub fn flip(&self) -> Self

Returns an inverted version of this segment where the beginning and the end points are swapped.

source

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.

source

pub fn split(&self, t: S) -> (Self, Self)

Split this curve into two sub-segments.

source

pub fn before_split(&self, t: S) -> Self

Return the segment before the split point.

source

pub fn after_split(&self, t: S) -> Self

Return the segment after the split point.

source

pub fn split_at_x(&self, x: S) -> (Self, Self)

source

pub fn bounding_box(&self) -> Box2D<S>

Return the smallest rectangle containing this segment.

source

pub fn to_vector(&self) -> Vector<S>

Returns the vector between this segment’s from and to points.

source

pub fn to_line(&self) -> Line<S>

Returns the line containing this segment.

source

pub fn length(&self) -> S

Computes the length of this segment.

source

pub fn square_length(&self) -> S

Computes the squared length of this segment.

source

pub fn set_length(&mut self, new_length: S)

Changes the segment’s length, moving destination point.

source

pub fn mid_point(&mut self) -> Point<S>

Computes third mid-point of this segment.

source

pub fn translate(&mut self, by: Vector<S>) -> Self

source

pub fn transformed<T: Transformation<S>>(&self, transform: &T) -> Self

Applies the transform to this segment and returns the results.

source

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.

source

pub fn intersection(&self, other: &Self) -> Option<Point<S>>

source

pub fn line_intersection_t(&self, line: &Line<S>) -> Option<S>

source

pub fn line_intersection(&self, line: &Line<S>) -> Option<Point<S>>

source

pub fn horizontal_line_intersection_t(&self, y: S) -> Option<S>

source

pub fn vertical_line_intersection_t(&self, x: S) -> Option<S>

source

pub fn horizontal_line_intersection(&self, y: S) -> Option<Point<S>>

source

pub fn vertical_line_intersection(&self, x: S) -> Option<Point<S>>

source

pub fn intersects(&self, other: &Self) -> bool

source

pub fn intersects_line(&self, line: &Line<S>) -> bool

source

pub fn overlaps_line(&self, line: &Line<S>) -> bool

source

pub fn overlaps_segment(&self, other: &LineSegment<S>) -> bool

source

pub fn contains_segment(&self, other: &LineSegment<S>) -> bool

source

pub fn clipped_x(&self, clip: Range<S>) -> Option<Self>

Horizontally clip this segment against a range of the x axis.

source

pub fn clipped_y(&self, clip: Range<S>) -> Option<Self>

Vertically clip this segment against a range of the y axis.

source

pub fn clipped(&self, clip: &Box2D<S>) -> Option<Self>

Clip this segment against a rectangle.

source

pub fn distance_to_point(&self, p: Point<S>) -> S

Computes the distance between this segment and a point.

source

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.

source

pub fn closest_point(&self, p: Point<S>) -> Point<S>

Computes the closest point on this segment to p.

source

pub fn to_f32(&self) -> LineSegment<f32>

source

pub fn to_f64(&self) -> LineSegment<f64>

Trait Implementations§

source§

impl<S: Clone> Clone for LineSegment<S>

source§

fn clone(&self) -> LineSegment<S>

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<S: Debug> Debug for LineSegment<S>

source§

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

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

impl<S: PartialEq> PartialEq for LineSegment<S>

source§

fn eq(&self, other: &LineSegment<S>) -> 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<S: Scalar> Segment for LineSegment<S>

source§

type Scalar = S

source§

fn from(&self) -> Point<S>

Start of the curve.
source§

fn to(&self) -> Point<S>

End of the curve.
source§

fn sample(&self, t: S) -> Point<S>

Sample the curve at t (expecting t between 0 and 1).
source§

fn x(&self, t: S) -> S

Sample x at t (expecting t between 0 and 1).
source§

fn y(&self, t: S) -> S

Sample y at t (expecting t between 0 and 1).
source§

fn derivative(&self, _t: S) -> Vector<S>

Sample the derivative at t (expecting t between 0 and 1).
source§

fn dx(&self, _t: S) -> S

Sample x derivative at t (expecting t between 0 and 1).
source§

fn dy(&self, _t: S) -> S

Sample y derivative at t (expecting t between 0 and 1).
source§

fn split(&self, t: S) -> (Self, Self)

Split this curve into two sub-curves.
source§

fn before_split(&self, t: S) -> Self

Return the curve before the split point.
source§

fn after_split(&self, t: S) -> Self

Return the curve after the split point.
source§

fn split_range(&self, t_range: Range<S>) -> Self

Return the curve inside a given range of t. Read more
source§

fn flip(&self) -> Self

Swap the direction of the segment.
source§

fn approximate_length(&self, _tolerance: S) -> S

Compute the length of the segment using a flattened approximation.
source§

fn for_each_flattened_with_t( &self, _tolerance: Self::Scalar, callback: &mut dyn FnMut(&LineSegment<S>, Range<S>), )

Approximates the curve with sequence of line segments. Read more
source§

impl<S: Copy> Copy for LineSegment<S>

source§

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> 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.