pub struct Polygon {
pub(crate) rings: Vec<Ring>,
pub(crate) tessellation: Option<Tessellation>,
}
Fields
rings: Vec<Ring>
tessellation: Option<Tessellation>
Implementations
sourceimpl Polygon
impl Polygon
pub fn with_holes(outer: Ring, inner: Vec<Ring>) -> Self
pub fn from_rings(rings: Vec<Ring>) -> Self
pub(crate) fn pretessellated(
rings: Vec<Ring>,
tessellation: Tessellation
) -> Self
pub fn from_geojson(raw: &[Vec<Vec<f64>>]) -> Result<Self>
pub fn from_triangle(tri: &Triangle) -> Self
pub fn triangles(&self) -> Vec<Triangle>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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
sourcefn transform<F: Fn(&Pt2D) -> Pt2D>(&self, f: F) -> Result<Self>
fn transform<F: Fn(&Pt2D) -> Pt2D>(&self, f: F) -> Result<Self>
Transformations must preserve Rings.
pub fn translate(&self, dx: f64, dy: f64) -> Self
sourcepub fn scale(&self, factor: f64) -> Result<Self>
pub fn scale(&self, factor: f64) -> Result<Self>
When factor
is small, this may collapse Rings and thus fail.
sourcepub fn must_scale(&self, factor: f64) -> Self
pub fn must_scale(&self, factor: f64) -> Self
When factor
is known to be over 1, then scaling can’t fail.
pub fn rotate(&self, angle: Angle) -> Self
pub fn rotate_around(&self, angle: Angle, pivot: Pt2D) -> Self
pub fn centered_on(&self, center: Pt2D) -> Self
pub fn get_outer_ring(&self) -> &Ring
pub fn into_outer_ring(self) -> Ring
sourcepub fn center(&self) -> Pt2D
pub fn center(&self) -> Pt2D
Returns the arithmetic mean of the outer ring’s points. The result could wind up inside a
hole in the polygon. Consider using polylabel
too.
sourcepub fn maybe_rectangle(width: f64, height: f64) -> Result<Self>
pub fn maybe_rectangle(width: f64, height: f64) -> Result<Self>
Top-left at the origin. Doesn’t take Distance, because this is usually pixels, actually.
sourcepub fn rectangle(width: f64, height: f64) -> Self
pub fn rectangle(width: f64, height: f64) -> Self
Top-left at the origin. Doesn’t take Distance, because this is usually pixels, actually.
Note this will panic if width
or height
is 0.
pub fn rectangle_centered(center: Pt2D, width: Distance, height: Distance) -> Self
pub fn rectangle_two_corners(pt1: Pt2D, pt2: Pt2D) -> Option<Self>
sourcepub fn maybe_rounded_rectangle<R: Into<CornerRadii>>(
w: f64,
h: f64,
r: R
) -> Option<Self>
pub fn maybe_rounded_rectangle<R: Into<CornerRadii>>(
w: f64,
h: f64,
r: R
) -> Option<Self>
Top-left at the origin. Doesn’t take Distance, because this is usually pixels, actually.
sourcepub fn pill(w: f64, h: f64) -> Self
pub fn pill(w: f64, h: f64) -> Self
A rectangle, two sides of which are fully rounded half-circles.
sourcepub fn rounded_rectangle<R: Into<CornerRadii>>(w: f64, h: f64, r: R) -> Self
pub fn rounded_rectangle<R: Into<CornerRadii>>(w: f64, h: f64, r: R) -> Self
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.
sourcepub fn union_all_into_multipolygon(list: Vec<Self>) -> MultiPolygon
pub fn union_all_into_multipolygon(list: Vec<Self>) -> MultiPolygon
Union all of the polygons into one geo::MultiPolygon
pub fn intersection(&self, other: &Self) -> Result<Vec<Self>>
pub fn difference(&self, other: &Self) -> Result<Vec<Self>>
pub fn convex_hull(list: Vec<Self>) -> Result<Self>
pub fn concave_hull(points: Vec<Pt2D>, concavity: u32) -> Result<Self>
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: &Self) -> bool
pub fn intersects(&self, other: &Self) -> 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?
pub(crate) fn get_rings(&self) -> &[Ring]
sourcepub fn to_outline(&self, thickness: Distance) -> Tessellation
pub fn to_outline(&self, thickness: Distance) -> Tessellation
Creates the outline around the polygon (both the exterior and holes), with the thickness half straddling the polygon and half of it just outside.
Returns a Tessellation
that may union together the outline from the exterior and multiple
holes. Callers that need a Polygon
must call to_outline
on the individual Rings
.
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
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<(Self, Tags)>>
pub fn from_geojson_bytes(
raw_bytes: &[u8],
gps_bounds: &GPSBounds,
require_in_bounds: bool
) -> Result<Vec<(Self, 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
.
sourcepub fn simplify(&self, epsilon: f64) -> Self
pub fn simplify(&self, epsilon: f64) -> Self
If simplification fails, just keep the original 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
sourceimpl From<Polygon> for Tessellation
impl From<Polygon> for Tessellation
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