Struct rsgeo::prelude::Polygon [−][src]
pub struct Polygon { /* fields omitted */ }
Polygon is a vector of points,which points should be closed. (The first and the last point should be same.)
The polygon can be convex or concave.
Implementations
impl Polygon
[src]
pub fn new(points: Vec<Point>) -> Result<Self, &'static str>
[src]
Create a new polygon
.
But the rest of points should not be same.
Example
use rsgeo::prelude::{Point,Polygon}; let pa = Point::new(32.0,112.0).unwrap(); let pb = Point::new(35.1,112.0).unwrap(); let pc = Point::new(35.3,112.5).unwrap(); let pg = Polygon::new(vec![pa,pb,pc]); assert!(pg.is_err()); let pg = Polygon::new(vec![pa,pb,pc,pa]); assert_eq!(pg.unwrap().len(),4);
pub fn len(&self) -> usize
[src]
Returns the number of elements in the polygon
pub fn contains(&self, p: &Point) -> bool
[src]
judge if a point is in the polygon area
Example
use rsgeo::prelude::{Point,Polygon}; let pa = Point::new(32.0,112.0).unwrap(); let pb = Point::new(35.1,112.0).unwrap(); let pc = Point::new(35.3,112.5).unwrap(); let pg = Polygon::new(vec![pa,pb,pc,pa]).unwrap(); let pt1 = Point::new(35.0,112.2).unwrap(); let pt2 = Point::new(34.29,110.3).unwrap(); assert!(pg.contains(&pt1)); assert!(!pg.contains(&pt2));
pub fn is_empty(&self) -> bool
[src]
Returns true if the Polygon contains no elements.
Trait Implementations
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,