Fields
pts: Vec<Pt2D>
length: Distance
Implementations
sourceimpl PolyLine
impl PolyLine
pub fn new(pts: Vec<Pt2D>) -> Result<PolyLine>
pub fn must_new(pts: Vec<Pt2D>) -> PolyLine
sourcepub fn unchecked_new(pts: Vec<Pt2D>) -> PolyLine
pub fn unchecked_new(pts: Vec<Pt2D>) -> PolyLine
Doesn’t check for duplicates. Use at your own risk.
sourcepub fn to_thick_ring(&self, width: Distance) -> Ring
pub fn to_thick_ring(&self, width: Distance) -> Ring
Like make_polygons, but make sure the points actually form a ring.
pub fn to_thick_boundary(
&self,
self_width: Distance,
boundary_width: Distance
) -> Option<Polygon>
pub fn reversed(&self) -> PolyLine
pub fn maybe_reverse(&self, reverse: bool) -> PolyLine
sourcepub fn quadrant(&self) -> i64
pub fn quadrant(&self) -> i64
Returns the quadrant where the overall angle of this polyline (pointing from the first to last point) is in. Output between 0 and 3.
sourcepub fn extend(self, other: PolyLine) -> Result<PolyLine>
pub fn extend(self, other: PolyLine) -> Result<PolyLine>
Glue together two polylines in order. The last point of self
must be the same as the
first point of other
. This method handles removing unnecessary intermediate points if the
extension happens to be at the same angle as the last line segment of self
.
sourcepub fn must_extend(self, other: PolyLine) -> PolyLine
pub fn must_extend(self, other: PolyLine) -> PolyLine
Like extend
, but panics on failure.
sourcepub fn optionally_push(self, pt: Pt2D) -> PolyLine
pub fn optionally_push(self, pt: Pt2D) -> PolyLine
Extends self
by a single point. If the new point is close enough to the last, dedupes.
Doesn’t clean up any intermediate points.
sourcepub fn force_extend(self, other: PolyLine) -> Result<PolyLine>
pub fn force_extend(self, other: PolyLine) -> Result<PolyLine>
Like extend
, but handles the last and first point not matching by inserting that point.
Doesn’t clean up any intermediate points.
sourcepub fn append(first: Vec<Pt2D>, second: Vec<Pt2D>) -> Result<Vec<Pt2D>>
pub fn append(first: Vec<Pt2D>, second: Vec<Pt2D>) -> Result<Vec<Pt2D>>
One or both args might be empty.
pub fn points(&self) -> &Vec<Pt2D>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn into_points(self) -> Vec<Pt2D>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn lines(&self) -> impl Iterator<Item = Line> + '_
pub fn length(&self) -> Distance
sourcepub fn slice(
&self,
start: Distance,
end: Distance
) -> Result<(PolyLine, Distance)>
pub fn slice(
&self,
start: Distance,
end: Distance
) -> Result<(PolyLine, Distance)>
Returns the excess distance left over from the end
sourcepub fn exact_slice(&self, start: Distance, end: Distance) -> PolyLine
pub fn exact_slice(&self, start: Distance, end: Distance) -> PolyLine
No excess leftover distance allowed.
pub fn maybe_exact_slice(
&self,
start: Distance,
end: Distance
) -> Result<PolyLine>
pub fn first_half(&self) -> PolyLine
pub fn second_half(&self) -> PolyLine
pub fn dist_along(&self, dist_along: Distance) -> Result<(Pt2D, Angle)>
pub fn must_dist_along(&self, dist_along: Distance) -> (Pt2D, Angle)
pub fn middle(&self) -> Pt2D
pub fn first_pt(&self) -> Pt2D
pub fn last_pt(&self) -> Pt2D
pub fn first_line(&self) -> Line
pub fn last_line(&self) -> Line
pub fn shift_right(&self, width: Distance) -> Result<PolyLine>
pub fn must_shift_right(&self, width: Distance) -> PolyLine
pub fn shift_left(&self, width: Distance) -> Result<PolyLine>
pub fn must_shift_left(&self, width: Distance) -> PolyLine
sourcepub fn shift_either_direction(&self, width: Distance) -> Result<PolyLine>
pub fn shift_either_direction(&self, width: Distance) -> Result<PolyLine>
Perpendicularly shifts the polyline to the right if positive or left if negative.
sourcepub fn shift_from_center(
&self,
total_width: Distance,
width_from_left_side: Distance
) -> Result<PolyLine>
pub fn shift_from_center(
&self,
total_width: Distance,
width_from_left_side: Distance
) -> Result<PolyLine>
self
represents some center, with total_width
. Logically this shifts left by
total_width / 2
, then right by width_from_left_side
, but without exasperating sharp
bends.
fn shift_with_corrections(&self, width: Distance) -> Result<PolyLine>
fn shift_with_sharp_angles(
&self,
width: Distance,
miter_threshold: f64
) -> Result<Vec<Pt2D>>
sourcepub fn make_polygons(&self, width: Distance) -> Polygon
pub fn make_polygons(&self, width: Distance) -> Polygon
The resulting polygon is manually triangulated and may not have a valid outer Ring (but it usually does).
sourcepub fn get_four_corners_of_thickened(
&self,
width: Distance
) -> Option<(Pt2D, Pt2D, Pt2D, Pt2D)>
pub fn get_four_corners_of_thickened(
&self,
width: Distance
) -> Option<(Pt2D, Pt2D, Pt2D, Pt2D)>
This does the equivalent of make_polygons, returning the (start left, start right, end left, end right). Fails rarely.
pub fn exact_dashed_polygons(
&self,
width: Distance,
dash_len: Distance,
dash_separation: Distance
) -> Vec<Polygon>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
sourcepub fn dashed_lines(
&self,
width: Distance,
dash_len: Distance,
dash_separation: Distance
) -> Vec<Polygon>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn dashed_lines(
&self,
width: Distance,
dash_len: Distance,
dash_separation: Distance
) -> Vec<Polygon>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Don’t draw the dashes too close to the ends.
sourcepub fn maybe_make_arrow(
&self,
thickness: Distance,
cap: ArrowCap
) -> Option<Polygon>
pub fn maybe_make_arrow(
&self,
thickness: Distance,
cap: ArrowCap
) -> Option<Polygon>
Fail if the length is too short.
sourcepub fn make_arrow(&self, thickness: Distance, cap: ArrowCap) -> Polygon
pub fn make_arrow(&self, thickness: Distance, cap: ArrowCap) -> Polygon
If the length is too short, just give up and make the thick line
pub fn make_double_arrow(&self, thickness: Distance, cap: ArrowCap) -> Polygon
pub fn dashed_arrow(
&self,
width: Distance,
dash_len: Distance,
dash_separation: Distance,
cap: ArrowCap
) -> Vec<Polygon>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
sourcepub fn intersection(&self, other: &PolyLine) -> Option<(Pt2D, Angle)>
pub fn intersection(&self, other: &PolyLine) -> Option<(Pt2D, Angle)>
Also return the angle of the line where the hit was found
pub fn intersection_infinite(&self, other: &InfiniteLine) -> Option<Pt2D>
sourcepub fn get_slice_ending_at(&self, pt: Pt2D) -> Option<PolyLine>
pub fn get_slice_ending_at(&self, pt: Pt2D) -> Option<PolyLine>
Panics if the pt is not on the polyline. Returns None if the point is the first point (meaning the slice is empty).
sourcepub fn get_slice_starting_at(&self, pt: Pt2D) -> Option<PolyLine>
pub fn get_slice_starting_at(&self, pt: Pt2D) -> Option<PolyLine>
Returns None if the point is the last point.
sourcepub fn safe_get_slice_ending_at(&self, pt: Pt2D) -> Option<PolyLine>
pub fn safe_get_slice_ending_at(&self, pt: Pt2D) -> Option<PolyLine>
Same as get_slice_ending_at, but returns None if the point isn’t on the polyline.
sourcepub fn safe_get_slice_starting_at(&self, pt: Pt2D) -> Option<PolyLine>
pub fn safe_get_slice_starting_at(&self, pt: Pt2D) -> Option<PolyLine>
Same as get_slice_starting_at, but returns None if the point isn’t on the polyline.
pub fn dist_along_of_point(&self, pt: Pt2D) -> Option<(Distance, Angle)>
pub fn trim_to_endpts(&self, pt1: Pt2D, pt2: Pt2D) -> PolyLine
pub fn get_bounds(&self) -> Bounds
sourcepub fn extend_to_length(&self, min_len: Distance) -> PolyLine
pub fn extend_to_length(&self, min_len: Distance) -> PolyLine
If the current line is at least this long, return it. Otherwise, extend the end of it, following the angle of the last line.
sourcepub fn to_geojson(&self, gps: Option<&GPSBounds>) -> Geometry
pub fn to_geojson(&self, gps: Option<&GPSBounds>) -> Geometry
Produces a GeoJSON linestring, optionally mapping the world-space points back to GPS.
pub fn from_geojson(
feature: &Feature,
gps: Option<&GPSBounds>
) -> Result<PolyLine>
sourcepub fn project_pt(&self, query: Pt2D) -> Pt2D
pub fn project_pt(&self, query: Pt2D) -> Pt2D
Returns the point on the polyline closest to the query.
sourcepub fn overall_angle(&self) -> Angle
pub fn overall_angle(&self) -> Angle
Returns the angle from the start to end of this polyline.
pub(crate) fn to_geo(&self) -> LineString
sourcepub fn step_along(
&self,
step_size: Distance,
buffer_ends: Distance
) -> Vec<(Pt2D, Angle)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn step_along(
&self,
step_size: Distance,
buffer_ends: Distance
) -> Vec<(Pt2D, Angle)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Walk along the PolyLine, starting buffer_ends
from the start and ending buffer_ends
before the end. Advance in increments of step_size
. Returns the point and angle at each
step.
sourcepub fn step_along_start_end(
&self,
step_size: Distance,
start_buffer: Distance,
end_buffer: Distance
) -> Vec<(Pt2D, Angle)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn step_along_start_end(
&self,
step_size: Distance,
start_buffer: Distance,
end_buffer: Distance
) -> Vec<(Pt2D, Angle)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Walk along the PolyLine, from start_buffer
to length - end_buffer
. Advance in
increments of step_size
. Returns the point and angle at each step.
sourcepub fn interpolate_points(&self, max_step: Distance) -> PolyLine
pub fn interpolate_points(&self, max_step: Distance) -> PolyLine
use geom::{PolyLine, Pt2D, Distance};
let polyline = PolyLine::must_new(vec![
Pt2D::new(0.0, 0.0),
Pt2D::new(0.0, 10.0),
Pt2D::new(10.0, 20.0),
]);
assert_eq!(
polyline.interpolate_points(Distance::meters(20.0)).points(),
&vec![
Pt2D::new(0.0, 0.0),
Pt2D::new(0.0, 10.0),
Pt2D::new(10.0, 20.0),
]
);
assert_eq!(
polyline.interpolate_points(Distance::meters(10.0)).points(),
&vec![
Pt2D::new(0.0, 0.0),
Pt2D::new(0.0, 10.0),
Pt2D::new(5.0, 15.0),
Pt2D::new(10.0, 20.0),
]
);
Trait Implementations
sourceimpl<'de> Deserialize<'de> for PolyLine
impl<'de> Deserialize<'de> for PolyLine
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for PolyLine
Auto Trait Implementations
impl RefUnwindSafe for PolyLine
impl Send for PolyLine
impl Sync for PolyLine
impl Unpin for PolyLine
impl UnwindSafe for PolyLine
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more