pub struct PlineViewData<T = f64> {
    pub start_index: usize,
    pub end_index_offset: usize,
    pub updated_start: PlineVertex<T>,
    pub updated_end_bulge: T,
    pub end_point: Vector2<T>,
    pub inverted_direction: bool,
}
Expand description

Structure to hold the minimum data required to create view as a partial selection over a source polyline. This structure is detached from the source polyline unlike PlineView.

A PlineViewData has all the information required to construct a complete polyline that represents the contiguous subpart of a source polyline (which optionally may be inverted).

PlineViewData::view is called to form an active view (using a reference to the source polyline to then iterate over or perform operations on).

§Examples

§Creating view over polyline from slice points


let mut polyline = Polyline::new_closed();
polyline.add(0.0, 0.0, 0.0);
polyline.add(5.0, 0.0, 0.0);
polyline.add(5.0, 5.0, 0.0);
polyline.add(0.0, 5.0, 0.0);
// construction view data from slice points, view data represents a slice of the source polyline
// starting at (2.5, 0.0) on the first segment (index 0) and ending at (2.5, 5.0) on the third
// segment (index 2)
let view_data =
    PlineViewData::from_slice_points(
        // source polyline
        &polyline,
        // start point
        Vector2::new(2.5, 0.0),
        // segment index start point lies on
        0,
        // end point
        Vector2::new(2.5, 5.0),
        // segment index end point lies on
        2,
        // position equal epsilon
        1e-5).expect("slice not collapsed");

// construct the view (which implements polyline traits) from the view data and source
let view = view_data.view(&polyline);

// we can now use common trait methods on the slice
// note we never had to copy the source polyline
let slice_length = view.path_length();
assert_fuzzy_eq!(view.path_length(), 10.0);
let slice_vertex_count = view.vertex_count();
assert_eq!(slice_vertex_count, 4);
let slice_extents = view.extents().unwrap();
assert_fuzzy_eq!(slice_extents.min_x, 2.5);
assert_fuzzy_eq!(slice_extents.min_y, 0.0);
assert_fuzzy_eq!(slice_extents.max_x, 5.0);
assert_fuzzy_eq!(slice_extents.max_y, 5.0);

Fields§

§start_index: usize

Source polyline start segment index.

§end_index_offset: usize

Wrapping offset from start_index to reach the last segment index in the source polyline.

§updated_start: PlineVertex<T>

First vertex of the view (positioned somewhere along the start_index segment with bulge and position updated).

§updated_end_bulge: T

Updated bulge value to be used in the end_index segment.

§end_point: Vector2<T>

Final end point of the view.

§inverted_direction: bool

Whether the view direction is inverted or not, note this just affects the way vertexes are constructed from the source polyline, all properties stay oriented/defined the same.

Implementations§

source§

impl<T> PlineViewData<T>
where T: Real,

source

pub fn view<'a, P>(&self, source: &'a P) -> PlineView<'a, P>
where P: PlineSource<Num = T> + ?Sized,

Create a PlineView by giving a reference to be borrowed as the source polyline.

source

pub fn create_on_single_segment<P>( source: &P, start_index: usize, updated_start: PlineVertex<T>, end_intersect: Vector2<T>, pos_equal_eps: T ) -> Option<Self>
where P: PlineSource<Num = T> + ?Sized,

Create view data from source polyline that selects over a single segment.

Returns None if updated_start is on top of end_intersect (collapsed selection).

source

pub fn create<P>( source: &P, start_index: usize, end_intersect: Vector2<T>, intersect_index: usize, updated_start: PlineVertex<T>, traverse_count: usize, pos_equal_eps: T ) -> Self
where P: PlineSource<Num = T> + ?Sized,

Create view data from source polyline and parameters.

§Panics

This function panics if traverse_count == 0 or indexes out of range for source. Use PlineViewData::create_on_single_segment if view selects over only a single segment.

source

pub fn from_entire_pline<P>(source: &P) -> Self
where P: PlineSource<Num = T> + ?Sized,

Construct view representing an entire polyline. The view is always considered an open polyline even if the source given is closed (but the view will geometrically follow the same closed path).

§Panics

This function panics if source has less than 2 vertexes or indexes out of range for source.

source

pub fn from_new_start<P>( source: &P, start_point: Vector2<T>, start_index: usize, pos_equal_eps: T ) -> Option<Self>
where P: PlineSource<Num = T> + ?Sized,

Construct view which changes the start point of a polyline. If the polyline is open this will trim the polyline up to the start point. If the polyline is closed then the entire polyline path is retained with just the start point changed. Returns None if polyline is open and start point equals the final vertex position for the polyline.

§Panics

This function panics if source has less than 2 vertexes or start_index out of range for source.

source

pub fn from_slice_points<P>( source: &P, start_point: Vector2<T>, start_index: usize, end_point: Vector2<T>, end_index: usize, pos_equal_eps: T ) -> Option<Self>
where P: PlineSource<Num = T> + ?Sized,

Construct view that is contiguous between two points on a source polyline (start and end of source polyline are trimmed).

§Panics

This function panics if source has less than 2 vertexes or indexes out of range for source.

source

pub fn validate_for_source<P>(&self, source: &P) -> ViewDataValidation<T>
where P: PlineSource<Num = T> + ?Sized,

Function mostly used for debugging and asserts, checks that this slice’s properties are valid for the source polyline provided.

Trait Implementations§

source§

impl<T: Clone> Clone for PlineViewData<T>

source§

fn clone(&self) -> PlineViewData<T>

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<T: Debug> Debug for PlineViewData<T>

source§

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

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

impl<T: Copy> Copy for PlineViewData<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for PlineViewData<T>
where T: RefUnwindSafe,

§

impl<T> Send for PlineViewData<T>
where T: Send,

§

impl<T> Sync for PlineViewData<T>
where T: Sync,

§

impl<T> Unpin for PlineViewData<T>
where T: Unpin,

§

impl<T> UnwindSafe for PlineViewData<T>
where T: 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> 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,

§

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

§

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

§

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.