pub enum PolygonRing<PointType> {
Outer(Vec<PointType>),
Inner(Vec<PointType>),
}Expand description
Rings composing a Polygon
Inner rings define holes in polygons.
In shapefile, the point ordering is what is used to know if a ring is an outer or inner one:
- Outer ring => points in clockwise order
- Inner ring => points in counter-clockwise order
§Note
Rings you get access from a GenericPolygon will always have its points ordered
according to its type (outer, inner).
But PolygonRings you create won’t be reordered until you move them into
a GenericPolygon.
§Example
use shapefile::{PolygonRing, Polygon, Point};
// Here the points are not in the correct order to be an Outer ring for a shapefile
let mut points = vec![
Point::new(-12.0, 6.0),
Point::new(-12.0, -6.0),
Point::new(12.0, -6.0),
Point::new(12.0, 6.0),
Point::new(-12.0, 6.0),
];
let mut reversed_points = points.clone();
reversed_points.reverse();
let ring = PolygonRing::Outer(points);
assert_ne!(ring.points(), reversed_points.as_slice());
assert_eq!(ring[0], Point::new(-12.0, 6.0));
// Now the points will be reversed
let polygon = Polygon::new(ring);
assert_eq!(polygon.rings()[0].points(), reversed_points.as_slice());Variants§
Outer(Vec<PointType>)
The outer ring of a polygon.
Inner(Vec<PointType>)
Defines a hole in a polygon
Implementations§
Source§impl<PointType> PolygonRing<PointType>
impl<PointType> PolygonRing<PointType>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of points inside the ring
§Example
use shapefile::{PolygonRing, Point};
let ring = PolygonRing::Inner(vec![
Point::new(-12.0, 6.0),
Point::new(-12.0, -6.0),
Point::new(12.0, -6.0),
Point::new(12.0, 6.0),
Point::new(-12.0, 6.0),
]);
assert_eq!(ring.len(), 5);Sourcepub fn points(&self) -> &[PointType]
pub fn points(&self) -> &[PointType]
Returns a non-mutable slice to the points inside the ring
use shapefile::{PolygonRing, Point};
let ring = PolygonRing::Inner(vec![
Point::new(-12.0, 6.0),
Point::new(-12.0, -6.0),
Point::new(12.0, -6.0),
Point::new(12.0, 6.0),
Point::new(-12.0, 6.0),
]);
assert_eq!(ring.points()[2], Point::new(12.0, -6.0));Sourcepub fn into_inner(self) -> Vec<PointType>
pub fn into_inner(self) -> Vec<PointType>
Consumes the ring and returns its points
Trait Implementations§
Source§impl<PointType> AsRef<[PointType]> for PolygonRing<PointType>
impl<PointType> AsRef<[PointType]> for PolygonRing<PointType>
Source§fn as_ref(&self) -> &[PointType]
fn as_ref(&self) -> &[PointType]
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl<PointType: Clone> Clone for PolygonRing<PointType>
impl<PointType: Clone> Clone for PolygonRing<PointType>
Source§fn clone(&self) -> PolygonRing<PointType>
fn clone(&self) -> PolygonRing<PointType>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<PointType: Debug> Debug for PolygonRing<PointType>
impl<PointType: Debug> Debug for PolygonRing<PointType>
Source§impl<PointType, I: SliceIndex<[PointType]>> Index<I> for PolygonRing<PointType>
impl<PointType, I: SliceIndex<[PointType]>> Index<I> for PolygonRing<PointType>
Source§impl<PointType: PartialEq> PartialEq for PolygonRing<PointType>
impl<PointType: PartialEq> PartialEq for PolygonRing<PointType>
impl<PointType> StructuralPartialEq for PolygonRing<PointType>
Auto Trait Implementations§
impl<PointType> Freeze for PolygonRing<PointType>
impl<PointType> RefUnwindSafe for PolygonRing<PointType>where
PointType: RefUnwindSafe,
impl<PointType> Send for PolygonRing<PointType>where
PointType: Send,
impl<PointType> Sync for PolygonRing<PointType>where
PointType: Sync,
impl<PointType> Unpin for PolygonRing<PointType>where
PointType: Unpin,
impl<PointType> UnwindSafe for PolygonRing<PointType>where
PointType: UnwindSafe,
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
Mutably borrows from an owned value. Read more