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>

source

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);
source

pub fn is_empty(&self) -> bool

Returns whether the rings contains any points

source

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));
source

pub fn into_inner(self) -> Vec<PointType>

Consumes the ring and returns its points

Trait Implementations§

source§

impl<PointType> AsRef<[PointType]> for PolygonRing<PointType>

source§

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>

source§

fn clone(&self) -> PolygonRing<PointType>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<PointType: Debug> Debug for PolygonRing<PointType>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<PointType: HasXY> From<Vec<PointType>> for PolygonRing<PointType>

source§

fn from(p: Vec<PointType>) -> Self

Converts to this type from the input type.
source§

impl<PointType, I: SliceIndex<[PointType]>> Index<I> for PolygonRing<PointType>

§

type Output = <I as SliceIndex<[PointType]>>::Output

The returned type after indexing.
source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<PointType: PartialEq> PartialEq for PolygonRing<PointType>

source§

fn eq(&self, other: &PolygonRing<PointType>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.