Struct Polyline

Source
pub struct Polyline {
    pub guid: String,
    pub name: String,
    pub points: Vec<Point>,
    pub plane: Plane,
    pub width: f32,
    pub linecolor: Color,
    pub xform: Xform,
}
Expand description

A polyline defined by a collection of points with an associated plane.

Fields§

§guid: String§name: String§points: Vec<Point>§plane: Plane§width: f32§linecolor: Color§xform: Xform

Implementations§

Source§

impl Polyline

Source

pub fn new(points: Vec<Point>) -> Self

Creates a new Polyline with default guid and name.

§Arguments
  • points - The collection of points.
Source

pub fn len(&self) -> usize

Returns the number of points in the polyline.

Source

pub fn is_empty(&self) -> bool

Returns true if the polyline has no points.

Source

pub fn segment_count(&self) -> usize

Returns the number of segments in the polyline. A polyline with n points has n-1 segments.

Source

pub fn length(&self) -> f32

Calculates the total length of the polyline.

Source

pub fn get_point(&self, index: usize) -> Option<&Point>

Returns a reference to the point at the given index.

Source

pub fn get_point_mut(&mut self, index: usize) -> Option<&mut Point>

Returns a mutable reference to the point at the given index.

Source

pub fn add_point(&mut self, point: Point)

Adds a point to the end of the polyline.

Source

pub fn insert_point(&mut self, index: usize, point: Point)

Inserts a point at the specified index.

Source

pub fn remove_point(&mut self, index: usize) -> Option<Point>

Removes and returns the point at the specified index.

Source

pub fn reverse(&mut self)

Reverses the order of points in the polyline.

Source

pub fn reversed(&self) -> Self

Returns a new polyline with reversed point order.

Source

pub fn jsondump(&self) -> Result<String, Box<dyn Error>>

Serializes the Polyline to a JSON string.

Source

pub fn jsonload(json_data: &str) -> Result<Self, Box<dyn Error>>

Deserializes a Polyline from a JSON string.

Source

pub fn to_json(&self, filepath: &str) -> Result<(), Box<dyn Error>>

Serializes the Polyline to a JSON file.

Source

pub fn from_json(filepath: &str) -> Result<Self, Box<dyn Error>>

Deserializes a Polyline from a JSON file.

Source

pub fn shift(&mut self, times: i32)

Shift polyline points by specified number of positions

Source

pub fn length_squared(&self) -> f64

Calculate squared length of polyline (faster, no sqrt)

Source

pub fn point_at_parameter(start: &Point, end: &Point, t: f64) -> Point

Get point at parameter t along a line segment (t=0 is start, t=1 is end)

Source

pub fn closest_point_to_line( point: &Point, line_start: &Point, line_end: &Point, ) -> f64

Find closest point on line segment to given point, returns parameter t

Source

pub fn line_line_overlap( line0_start: &Point, line0_end: &Point, line1_start: &Point, line1_end: &Point, ) -> Option<(Point, Point)>

Check if two line segments overlap and return the overlapping segment

Source

pub fn line_line_average( line0_start: &Point, line0_end: &Point, line1_start: &Point, line1_end: &Point, ) -> (Point, Point)

Calculate average of two line segments

Source

pub fn line_line_overlap_average( line0_start: &Point, line0_end: &Point, line1_start: &Point, line1_end: &Point, ) -> (Point, Point)

Calculate overlap average of two line segments

Source

pub fn line_from_projected_points( line_start: &Point, line_end: &Point, points: &[Point], ) -> Option<(Point, Point)>

Create line from projected points onto a base line

Source

pub fn closest_distance_and_point(&self, point: &Point) -> (f64, usize, Point)

Find closest distance and point from a point to this polyline

Source

pub fn is_closed(&self) -> bool

Check if polyline is closed (first and last points are the same)

Source

pub fn center(&self) -> Point

Calculate center point of polyline

Source

pub fn center_vec(&self) -> Vector

Calculate center as vector

Source

pub fn get_average_plane(&self) -> (Point, Vector, Vector, Vector)

Get average plane from polyline points

Source

pub fn get_fast_plane(&self) -> (Point, Plane)

Get fast plane calculation from polyline

Source

pub fn get_middle_line( line0_start: &Point, line0_end: &Point, line1_start: &Point, line1_end: &Point, ) -> (Point, Point)

Calculate middle line between two line segments

Source

pub fn extend_line( line_start: &mut Point, line_end: &mut Point, distance0: f64, distance1: f64, )

Extend line segment by specified distances at both ends

Source

pub fn scale_line(line_start: &mut Point, line_end: &mut Point, distance: f64)

Scale line segment inward by specified distance

Source

pub fn extend_segment( &mut self, segment_id: usize, dist0: f64, dist1: f64, proportion0: f64, proportion1: f64, )

Extend polyline segment

Source

pub fn extend_segment_equally_static( segment_start: &mut Point, segment_end: &mut Point, dist: f64, proportion: f64, )

Extend segment equally on both ends (static utility)

Source

pub fn extend_segment_equally( &mut self, segment_id: usize, dist: f64, proportion: f64, )

Extend polyline segment equally

Source

pub fn move_by(&mut self, direction: &Vector)

Move polyline by direction vector

Source

pub fn is_clockwise(&self, _plane: &Plane) -> bool

Check if polyline is clockwise oriented

Source

pub fn flip(&mut self)

Flip polyline direction (reverse point order)

Source

pub fn get_convex_corners(&self) -> Vec<bool>

Get convex/concave corners of polyline

Source

pub fn tween_two_polylines( polyline0: &Polyline, polyline1: &Polyline, weight: f64, ) -> Polyline

Interpolate between two polylines

Source

fn average_normal(&self) -> Vector

Calculate average normal from polyline points

Trait Implementations§

Source§

impl Add<&Vector> for Polyline

Source§

fn add(self, other: &Vector) -> Polyline

Translates the polyline by a vector and returns a new polyline.

§Arguments
  • other - The translation vector.
Source§

type Output = Polyline

The resulting type after applying the + operator.
Source§

impl AddAssign<&Vector> for Polyline

Source§

fn add_assign(&mut self, other: &Vector)

Translates all points in the polyline by a vector.

§Arguments
  • other - The translation vector.
Source§

impl Clone for Polyline

Source§

fn clone(&self) -> Polyline

Returns a duplicate 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 Debug for Polyline

Source§

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

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

impl Default for Polyline

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Polyline

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Polyline

Source§

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

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

impl Serialize for Polyline

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<&Vector> for Polyline

Source§

fn sub(self, other: &Vector) -> Polyline

Translates the polyline by the negative of a vector and returns a new polyline.

§Arguments
  • other - The vector to subtract.
Source§

type Output = Polyline

The resulting type after applying the - operator.
Source§

impl SubAssign<&Vector> for Polyline

Source§

fn sub_assign(&mut self, other: &Vector)

Translates all points in the polyline by the negative of a vector.

§Arguments
  • other - The vector to subtract.

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,