Fields
points: Vec<Pt2D>
indices: Vec<u16>
Groups of three indices make up the triangles
rings: Option<Vec<Ring>>
If the polygon has holes, explicitly store all the rings (the one outer and all of the inner) so they can later be used to generate outlines and such. If the polygon has no holes, then this will just be None, since the points form a ring.
Implementations
sourceimpl Polygon
impl Polygon
pub fn buggy_new(orig_pts: Vec<Pt2D>) -> Polygon
pub fn with_holes(outer: Ring, inner: Vec<Ring>) -> Polygon
pub fn from_rings(rings: Vec<Ring>) -> Polygon
pub fn from_geojson(raw: &[Vec<Vec<f64>>]) -> Result<Polygon>
pub fn precomputed(points: Vec<Pt2D>, indices: Vec<usize>) -> Polygon
pub fn from_triangle(tri: &Triangle) -> Polygon
pub fn triangles(&self) -> Vec<Triangle>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn raw_for_rendering(&self) -> (&Vec<Pt2D>, &Vec<u16>)
sourcepub fn contains_pt(&self, pt: Pt2D) -> bool
pub fn contains_pt(&self, pt: Pt2D) -> bool
Does this polygon contain the point in its interior?
pub fn get_bounds(&self) -> Bounds
fn transform<F: Fn(&Pt2D) -> Pt2D>(&self, f: F) -> Polygon
pub fn translate(&self, dx: f64, dy: f64) -> Polygon
pub fn scale(&self, factor: f64) -> Polygon
pub fn scale_xy(&self, x_factor: f64, y_factor: f64) -> Polygon
pub fn rotate(&self, angle: Angle) -> Polygon
pub fn rotate_around(&self, angle: Angle, pivot: Pt2D) -> Polygon
pub fn centered_on(&self, center: Pt2D) -> Polygon
sourcepub fn inplace_multi_transform(
&mut self,
scale: f64,
translate_x: f64,
translate_y: f64,
rotate: Angle,
pivot: Pt2D
)
pub fn inplace_multi_transform(
&mut self,
scale: f64,
translate_x: f64,
translate_y: f64,
rotate: Angle,
pivot: Pt2D
)
Equivalent to self.strip_rings().scale(scale).translate(translate_x, translate_y).rotate_around(rotate, pivot)
, but modifies the polygon in-place and is faster.
sourcepub fn points(&self) -> &Vec<Pt2D>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn points(&self) -> &Vec<Pt2D>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
The order of these points depends on the constructor! The first and last point may or may not match. Polygons constructed from PolyLines will have a very weird order.
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 into_ring(self) -> Ring
sourcepub fn get_outer_ring(&self) -> Option<Ring>
pub fn get_outer_ring(&self) -> Option<Ring>
Get the outer ring of this polygon. This should usually succeed.
pub fn center(&self) -> Pt2D
sourcepub fn rectangle(width: f64, height: f64) -> Polygon
pub fn rectangle(width: f64, height: f64) -> Polygon
Top-left at the origin. Doesn’t take Distance, because this is usually pixels, actually.
pub fn rectangle_centered(
center: Pt2D,
width: Distance,
height: Distance
) -> Polygon
pub fn rectangle_two_corners(pt1: Pt2D, pt2: Pt2D) -> Option<Polygon>
sourcepub fn maybe_rounded_rectangle<R: Into<CornerRadii>>(
w: f64,
h: f64,
r: R
) -> Option<Polygon>
pub fn maybe_rounded_rectangle<R: Into<CornerRadii>>(
w: f64,
h: f64,
r: R
) -> Option<Polygon>
Top-left at the origin. Doesn’t take Distance, because this is usually pixels, actually.
sourcepub fn pill(w: f64, h: f64) -> Polygon
pub fn pill(w: f64, h: f64) -> Polygon
A rectangle, two sides of which are fully rounded half-circles.
sourcepub fn rounded_rectangle<R: Into<CornerRadii>>(w: f64, h: f64, r: R) -> Polygon
pub fn rounded_rectangle<R: Into<CornerRadii>>(w: f64, h: f64, r: R) -> Polygon
Top-left at the origin. Doesn’t take Distance, because this is usually pixels, actually. If it’s not possible to apply the specified radius, fallback to a regular rectangle.
pub fn union(self, other: Polygon) -> Polygon
pub fn union_all(list: Vec<Polygon>) -> Polygon
sourcepub fn union_all_into_multipolygon(list: Vec<Polygon>) -> MultiPolygon
pub fn union_all_into_multipolygon(list: Vec<Polygon>) -> MultiPolygon
Union all of the polygons into one geo::MultiPolygon
pub fn intersection(&self, other: &Polygon) -> Vec<Polygon>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn difference(&self, other: &Polygon) -> Vec<Polygon>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn convex_hull(list: Vec<Polygon>) -> Polygon
pub fn concave_hull(points: Vec<Pt2D>, concavity: u32) -> Polygon
sourcepub fn polylabel(&self) -> Pt2D
pub fn polylabel(&self) -> Pt2D
Find the “pole of inaccessibility” – the most distant internal point from the polygon outline
sourcepub fn intersects(&self, other: &Polygon) -> bool
pub fn intersects(&self, other: &Polygon) -> bool
Do two polygons intersect at all?
sourcepub fn intersects_polyline(&self, pl: &PolyLine) -> bool
pub fn intersects_polyline(&self, pl: &PolyLine) -> bool
Does this polygon intersect a polyline?
sourcepub fn to_outline(&self, thickness: Distance) -> Result<Polygon>
pub fn to_outline(&self, thickness: Distance) -> Result<Polygon>
Creates the outline around the polygon, with the thickness half straddling the polygon and half of it just outside. Only works for polygons that’re formed from rings. Those made from PolyLines won’t work, for example.
sourcepub fn strip_rings(&self) -> Polygon
pub fn strip_rings(&self) -> Polygon
Remove the internal rings used for to_outline. This is fine to do if the polygon is being added to some larger piece of geometry that won’t need an outline.
sourcepub fn clip_polyline(&self, input: &PolyLine) -> Option<Vec<Pt2D>>
pub fn clip_polyline(&self, input: &PolyLine) -> Option<Vec<Pt2D>>
Doesn’t handle multiple crossings in and out.
pub fn clip_ring(&self, input: &Ring) -> Option<Vec<Pt2D>>
sourcepub fn to_geojson(&self, gps: Option<&GPSBounds>) -> Geometry
pub fn to_geojson(&self, gps: Option<&GPSBounds>) -> Geometry
If the polygon is just a single outer ring, produces a GeoJSON polygon. Otherwise, produces a GeoJSON multipolygon consisting of individual triangles. Optionally map the world-space points back to GPS.
sourcepub fn from_geojson_bytes(
raw_bytes: &[u8],
gps_bounds: &GPSBounds,
require_in_bounds: bool
) -> Result<Vec<(Polygon, Tags)>>
pub fn from_geojson_bytes(
raw_bytes: &[u8],
gps_bounds: &GPSBounds,
require_in_bounds: bool
) -> Result<Vec<(Polygon, Tags)>>
Extracts all polygons from raw bytes representing a GeoJSON file, along with the string
key/value properties. Only the first polygon from multipolygons is returned. If
require_in_bounds
is set, then the polygon must completely fit within the gps_bounds
.
pub fn simplify(&self, epsilon: f64) -> Polygon
fn to_geo(&self) -> Polygon
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Polygon
impl<'de> Deserialize<'de> for Polygon
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 Polygon
Auto Trait Implementations
impl RefUnwindSafe for Polygon
impl Send for Polygon
impl Sync for Polygon
impl Unpin for Polygon
impl UnwindSafe for Polygon
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