pub struct Polygon {
pub srid: SRID,
pub geom: Polygon<f64>,
}
Expand description
A bounded two-dimensional area.
MySQL extension: The spatial reference system identifier (SRID) may identify the used coordinate system.
Fields§
§srid: SRID
§geom: Polygon<f64>
Methods from Deref<Target = Polygon<f64>>§
Sourcepub fn exterior(&self) -> &LineString<T>
pub fn exterior(&self) -> &LineString<T>
Return a reference to the exterior LineString
ring.
§Examples
use geo_types::{LineString, Polygon};
let exterior = LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]);
let polygon = Polygon::new(exterior.clone(), vec![]);
assert_eq!(polygon.exterior(), &exterior);
Sourcepub fn exterior_mut<F>(&mut self, f: F)where
F: FnOnce(&mut LineString<T>),
pub fn exterior_mut<F>(&mut self, f: F)where
F: FnOnce(&mut LineString<T>),
Execute the provided closure f
, which is provided with a mutable
reference to the exterior LineString
ring.
After the closure executes, the exterior LineString
will be closed.
§Examples
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
polygon.exterior_mut(|exterior| {
exterior.0[1] = coord! { x: 1., y: 2. };
});
assert_eq!(
polygon.exterior(),
&LineString::from(vec![(0., 0.), (1., 2.), (1., 0.), (0., 0.),])
);
If the first and last Coord
s of the exterior LineString
no
longer match, the LineString
will be closed:
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
polygon.exterior_mut(|exterior| {
exterior.0[0] = coord! { x: 0., y: 1. };
});
assert_eq!(
polygon.exterior(),
&LineString::from(vec![(0., 1.), (1., 1.), (1., 0.), (0., 0.), (0., 1.),])
);
Sourcepub fn try_exterior_mut<F, E>(&mut self, f: F) -> Result<(), E>
pub fn try_exterior_mut<F, E>(&mut self, f: F) -> Result<(), E>
Fallible alternative to exterior_mut
.
Sourcepub fn interiors(&self) -> &[LineString<T>]
pub fn interiors(&self) -> &[LineString<T>]
Return a slice of the interior LineString
rings.
§Examples
use geo_types::{coord, LineString, Polygon};
let interiors = vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])];
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
interiors.clone(),
);
assert_eq!(interiors, polygon.interiors());
Sourcepub fn interiors_mut<F>(&mut self, f: F)where
F: FnOnce(&mut [LineString<T>]),
pub fn interiors_mut<F>(&mut self, f: F)where
F: FnOnce(&mut [LineString<T>]),
Execute the provided closure f
, which is provided with a mutable
reference to the interior LineString
rings.
After the closure executes, each of the interior LineString
s will be
closed.
§Examples
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])],
);
polygon.interiors_mut(|interiors| {
interiors[0].0[1] = coord! { x: 0.8, y: 0.8 };
});
assert_eq!(
polygon.interiors(),
&[LineString::from(vec![
(0.1, 0.1),
(0.8, 0.8),
(0.9, 0.1),
(0.1, 0.1),
])]
);
If the first and last Coord
s of any interior LineString
no
longer match, those LineString
s will be closed:
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])],
);
polygon.interiors_mut(|interiors| {
interiors[0].0[0] = coord! { x: 0.1, y: 0.2 };
});
assert_eq!(
polygon.interiors(),
&[LineString::from(vec![
(0.1, 0.2),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
(0.1, 0.2),
])]
);
Sourcepub fn try_interiors_mut<F, E>(&mut self, f: F) -> Result<(), E>
pub fn try_interiors_mut<F, E>(&mut self, f: F) -> Result<(), E>
Fallible alternative to interiors_mut
.
Sourcepub fn interiors_push(&mut self, new_interior: impl Into<LineString<T>>)
pub fn interiors_push(&mut self, new_interior: impl Into<LineString<T>>)
Add an interior ring to the Polygon
.
The new LineString
interior ring will be closed:
§Examples
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
assert_eq!(polygon.interiors().len(), 0);
polygon.interiors_push(vec![(0.1, 0.1), (0.9, 0.9), (0.9, 0.1)]);
assert_eq!(
polygon.interiors(),
&[LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])]
);
Sourcepub fn num_rings(&self) -> usize
pub fn num_rings(&self) -> usize
Count the total number of rings (interior and exterior) in the polygon
§Examples
use geo_types::{coord, LineString, Polygon};
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
assert_eq!(polygon.num_rings(), 1);
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![(0.1, 0.1), (0.9, 0.9), (0.9, 0.1)])],
);
assert_eq!(polygon.num_rings(), 2);
Sourcepub fn num_interior_rings(&self) -> usize
pub fn num_interior_rings(&self) -> usize
Count the number of interior rings in the polygon
§Examples
use geo_types::{coord, LineString, Polygon};
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
assert_eq!(polygon.num_interior_rings(), 0);
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![(0.1, 0.1), (0.9, 0.9), (0.9, 0.1)])],
);
assert_eq!(polygon.num_interior_rings(), 1);
Trait Implementations§
Source§impl From<BoundingBox> for Polygon
impl From<BoundingBox> for Polygon
Source§fn from(other: BoundingBox) -> Self
fn from(other: BoundingBox) -> Self
Source§impl<__ST, __DB> FromSqlRow<__ST, __DB> for Polygon
impl<__ST, __DB> FromSqlRow<__ST, __DB> for Polygon
Source§const FIELDS_NEEDED: usize = 1usize
const FIELDS_NEEDED: usize = 1usize
row.take()
in build_from_row
impl StructuralPartialEq for Polygon
Auto Trait Implementations§
impl Freeze for Polygon
impl RefUnwindSafe for Polygon
impl Send for Polygon
impl Sync for Polygon
impl Unpin for Polygon
impl UnwindSafe for Polygon
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: Sized + AsExpression<T>,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: Sized + AsExpression<T>,
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
&self
to an expression for Diesel’s query builder. Read more