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
impl Polyline
Sourcepub fn segment_count(&self) -> usize
pub fn segment_count(&self) -> usize
Returns the number of segments in the polyline. A polyline with n points has n-1 segments.
Sourcepub fn get_point(&self, index: usize) -> Option<&Point>
pub fn get_point(&self, index: usize) -> Option<&Point>
Returns a reference to the point at the given index.
Sourcepub fn get_point_mut(&mut self, index: usize) -> Option<&mut Point>
pub fn get_point_mut(&mut self, index: usize) -> Option<&mut Point>
Returns a mutable reference to the point at the given index.
Sourcepub fn insert_point(&mut self, index: usize, point: Point)
pub fn insert_point(&mut self, index: usize, point: Point)
Inserts a point at the specified index.
Sourcepub fn remove_point(&mut self, index: usize) -> Option<Point>
pub fn remove_point(&mut self, index: usize) -> Option<Point>
Removes and returns the point at the specified index.
Sourcepub fn jsondump(&self) -> Result<String, Box<dyn Error>>
pub fn jsondump(&self) -> Result<String, Box<dyn Error>>
Serializes the Polyline to a JSON string.
Sourcepub fn jsonload(json_data: &str) -> Result<Self, Box<dyn Error>>
pub fn jsonload(json_data: &str) -> Result<Self, Box<dyn Error>>
Deserializes a Polyline from a JSON string.
Sourcepub fn to_json(&self, filepath: &str) -> Result<(), Box<dyn Error>>
pub fn to_json(&self, filepath: &str) -> Result<(), Box<dyn Error>>
Serializes the Polyline to a JSON file.
Sourcepub fn from_json(filepath: &str) -> Result<Self, Box<dyn Error>>
pub fn from_json(filepath: &str) -> Result<Self, Box<dyn Error>>
Deserializes a Polyline from a JSON file.
Sourcepub fn length_squared(&self) -> f64
pub fn length_squared(&self) -> f64
Calculate squared length of polyline (faster, no sqrt)
Sourcepub fn point_at_parameter(start: &Point, end: &Point, t: f64) -> Point
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)
Sourcepub fn closest_point_to_line(
point: &Point,
line_start: &Point,
line_end: &Point,
) -> f64
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
Sourcepub fn line_line_overlap(
line0_start: &Point,
line0_end: &Point,
line1_start: &Point,
line1_end: &Point,
) -> Option<(Point, Point)>
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
Sourcepub fn line_line_average(
line0_start: &Point,
line0_end: &Point,
line1_start: &Point,
line1_end: &Point,
) -> (Point, Point)
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
Sourcepub fn line_line_overlap_average(
line0_start: &Point,
line0_end: &Point,
line1_start: &Point,
line1_end: &Point,
) -> (Point, Point)
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
Sourcepub fn line_from_projected_points(
line_start: &Point,
line_end: &Point,
points: &[Point],
) -> Option<(Point, Point)>
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
Sourcepub fn closest_distance_and_point(&self, point: &Point) -> (f64, usize, Point)
pub fn closest_distance_and_point(&self, point: &Point) -> (f64, usize, Point)
Find closest distance and point from a point to this polyline
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Check if polyline is closed (first and last points are the same)
Sourcepub fn center_vec(&self) -> Vector
pub fn center_vec(&self) -> Vector
Calculate center as vector
Sourcepub fn get_average_plane(&self) -> (Point, Vector, Vector, Vector)
pub fn get_average_plane(&self) -> (Point, Vector, Vector, Vector)
Get average plane from polyline points
Sourcepub fn get_fast_plane(&self) -> (Point, Plane)
pub fn get_fast_plane(&self) -> (Point, Plane)
Get fast plane calculation from polyline
Sourcepub fn get_middle_line(
line0_start: &Point,
line0_end: &Point,
line1_start: &Point,
line1_end: &Point,
) -> (Point, Point)
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
Sourcepub fn extend_line(
line_start: &mut Point,
line_end: &mut Point,
distance0: f64,
distance1: f64,
)
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
Sourcepub fn scale_line(line_start: &mut Point, line_end: &mut Point, distance: f64)
pub fn scale_line(line_start: &mut Point, line_end: &mut Point, distance: f64)
Scale line segment inward by specified distance
Sourcepub fn extend_segment(
&mut self,
segment_id: usize,
dist0: f64,
dist1: f64,
proportion0: f64,
proportion1: f64,
)
pub fn extend_segment( &mut self, segment_id: usize, dist0: f64, dist1: f64, proportion0: f64, proportion1: f64, )
Extend polyline segment
Sourcepub fn extend_segment_equally_static(
segment_start: &mut Point,
segment_end: &mut Point,
dist: f64,
proportion: f64,
)
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)
Sourcepub fn extend_segment_equally(
&mut self,
segment_id: usize,
dist: f64,
proportion: f64,
)
pub fn extend_segment_equally( &mut self, segment_id: usize, dist: f64, proportion: f64, )
Extend polyline segment equally
Sourcepub fn is_clockwise(&self, _plane: &Plane) -> bool
pub fn is_clockwise(&self, _plane: &Plane) -> bool
Check if polyline is clockwise oriented
Sourcepub fn get_convex_corners(&self) -> Vec<bool>
pub fn get_convex_corners(&self) -> Vec<bool>
Get convex/concave corners of polyline
Sourcepub fn tween_two_polylines(
polyline0: &Polyline,
polyline1: &Polyline,
weight: f64,
) -> Polyline
pub fn tween_two_polylines( polyline0: &Polyline, polyline1: &Polyline, weight: f64, ) -> Polyline
Interpolate between two polylines
Sourcefn average_normal(&self) -> Vector
fn average_normal(&self) -> Vector
Calculate average normal from polyline points