Struct cavalier_contours::polyline::PlineViewData
source · 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,
impl<T> PlineViewData<T>where T: Real,
sourcepub fn view<'a, P>(&self, source: &'a P) -> PlineView<'a, P>where
P: PlineSource<Num = T> + ?Sized,
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.
sourcepub 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,
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).
sourcepub 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
) -> Selfwhere
P: PlineSource<Num = T> + ?Sized,
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 ) -> Selfwhere 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.
sourcepub fn from_entire_pline<P>(source: &P) -> Selfwhere
P: PlineSource<Num = T> + ?Sized,
pub fn from_entire_pline<P>(source: &P) -> Selfwhere 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
.
sourcepub 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,
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
.
sourcepub 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,
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
.
sourcepub fn validate_for_source<P>(&self, source: &P) -> ViewDataValidation<T>where
P: PlineSource<Num = T> + ?Sized,
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>
impl<T: Clone> Clone for PlineViewData<T>
source§fn clone(&self) -> PlineViewData<T>
fn clone(&self) -> PlineViewData<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more