Struct geometry_rs::Polygon

source ·
pub struct Polygon { /* private fields */ }

Implementations§

source§

impl Polygon

source

pub fn contains_point(&self, p: Point) -> bool

Do point-in-polygon search.

source

pub fn new(exterior: Vec<Point>, holes: Vec<Vec<Point>>) -> Polygon

Create a new Polygon instance from exterior and holes.

Please note that set with_index to true will increase performance, but requires more memory. See #4 for more details.

Example:

use std::vec;
use geometry_rs;
let poly = geometry_rs::Polygon::new(
    vec![
        geometry_rs::Point {
            x: 90.48826291293898,
            y: 45.951129815858565,
        },
        geometry_rs::Point {
            x: 90.48826291293898,
            y: 27.99437617512571,
        },
        geometry_rs::Point {
            x: 122.83201291294,
            y: 27.99437617512571,
        },
        geometry_rs::Point {
            x: 122.83201291294,
            y: 45.951129815858565,
        },
        geometry_rs::Point {
            x: 90.48826291293898,
            y: 45.951129815858565,
        },
    ],
    vec![],
);

let p_out = geometry_rs::Point {
    x: 130.74216916294148,
    y: 37.649011392900306,
};

print!("{:?}\n", poly.contains_point(p_out));

let p_in = geometry_rs::Point {
    x: 99.9804504129416,
    y: 39.70716466970461,
};
print!("{:?}\n", poly.contains_point(p_in));
source

pub fn new_with_rtree_index_opt( exterior: Vec<Point>, holes: Vec<Vec<Point>>, with_index: bool ) -> Polygon

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.