Struct visioncortex::Path

source ·
pub struct Path<T> {
    pub path: Vec<T>,
}
Expand description

Path of generic points in 2D space

Fields§

§path: Vec<T>

T can be PointI32/PointF64, etc. (see src/point.rs).

Implementations§

source§

impl<T> Path<T>

source

pub fn new() -> Self

Creates a new 2D Path with no points

source

pub fn from_points(points: Vec<T>) -> Self

Creates a 2D Path with ‘points’ as its points

source

pub fn add(&mut self, point: T)

Adds a point to the end of the path

source

pub fn pop(&mut self) -> Option<T>

Removes the last point from the path and returns it, or None if it is empty.

source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator on the vector of points in the path

source

pub fn len(&self) -> usize

Returns the number of points in the path

source

pub fn is_empty(&self) -> bool

Returns true if the path is empty, false otherwise

source§

impl<T> Path<T>
where T: Clone + PartialEq,

source

pub fn to_open(&self) -> Self

Convert a closed path to an open path. A clone of ‘self’ is returned untouched if ‘self’ is empty or open.

source

pub fn to_closed(&self) -> Self

Convert an unclosed path to a closed path. A clone of ‘self’ is returned untouched if ‘self’ is empty or closed.

source§

impl<T> Path<T>
where T: AddAssign + Copy,

source

pub fn offset(&mut self, o: &T)

Applies an offset to all points in the path

source§

impl<T> Path<T>
where T: ToSvgString + Copy + Add<Output = T>,

source

pub fn to_svg_string( &self, close: bool, offset: &T, precision: Option<u32> ) -> String

Generates a string representation of the path in SVG format.

Takes a bool to indicate whether the end should be wrapped back to start.

An offset is specified to apply an offset to the display points (useful when displaying on canvas elements).

If close is true, assume the last point of the path repeats the first point

source§

impl<T> Path<Point2<T>>
where T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + PartialEq + PartialOrd + Copy + Into<f64>,

source

pub fn reduce(&self, tolerance: f64) -> Option<Self>

Path is a closed path (shape), but the reduce algorithm only reduces open paths. We divide the path into four sections, spliced at the extreme points (max-x max-y min-x min-y), and reduce each section individually. Thus the most simplified path consists of at least 4 points. This function assumes the last point of the path repeats the first point.

source§

impl Path<Point2<i32>>

source

pub fn smooth( &self, corner_threshold: f64, outset_ratio: f64, segment_length: f64, max_iterations: usize ) -> PathF64

Returns a copy of self after Path Smoothing, preserving corners.

corner_threshold is specified in radians. outset_ratio is a real number >= 1.0. segment_length is specified in pixels (length unit in path coordinate system).

source§

impl Path<Point2<f64>>

source

pub fn smooth( &self, corner_threshold: f64, outset_ratio: f64, segment_length: f64, max_iterations: usize ) -> PathF64

source§

impl Path<Point2<i32>>

source

pub fn simplify(&self, clockwise: bool) -> Self

Returns a copy of self after Path Simplification:

First remove staircases then simplify by limiting penalties.

source

pub fn image_to_path( image: &BinaryImage, clockwise: bool, mode: PathSimplifyMode ) -> PathI32

Converts outline of pixel cluster to path with Path Walker. Takes a bool representing the clockwiseness of traversal (useful in svg representation to represent holes). Takes an enum PathSimplifyMode which indicates the required operation:

  • Polygon - Walk path and simplify it
  • Otherwise - Walk path only
source

pub fn to_path_f64(&self) -> PathF64

Returns a copy of self converted to PathF64

Trait Implementations§

source§

impl<T: Clone> Clone for Path<T>

source§

fn clone(&self) -> Path<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 Path<T>

source§

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

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

impl<T: Default> Default for Path<T>

source§

fn default() -> Path<T>

Returns the “default value” for a type. Read more
source§

impl<T> Index<Range<usize>> for Path<T>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T> Index<RangeFrom<usize>> for Path<T>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T> Index<RangeInclusive<usize>> for Path<T>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T> Index<usize> for Path<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T> IndexMut<usize> for Path<T>

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Path<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Path<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.