pub struct Polygon<T: CoordStorage = f64> { /* private fields */ }Expand description
A polygon whose coordinates are stored as T (f64 degrees by default,
or scaled i32, see I32Polygon).
The bounding box, the acceleration indexes and the raycast all operate in
storage space: Polygon::contains_point multiplies the query point by
the polygon’s scale exactly once, and segment endpoints are converted to
f64 in registers during the raycast.
Implementations§
Source§impl<T: CoordStorage> Polygon<T>
impl<T: CoordStorage> Polygon<T>
Sourcepub fn contains_point(&self, p: Point) -> bool
pub fn contains_point(&self, p: Point) -> bool
Do point-in-polygon search. p is in unscaled (degree) coordinates.
pub fn exterior(&self) -> &[Point<T>]
pub fn holes(&self) -> &[Vec<Point<T>>]
Sourcepub fn rect(&self) -> Rect
pub fn rect(&self) -> Rect
The polygon’s bounding box in storage space (degrees for f64
polygons, scaled integers for I32Polygon).
Sourcepub fn scale(&self) -> f64
pub fn scale(&self) -> f64
The factor a degree coordinate is multiplied by to reach storage
space: 1.0 for f64 polygons, e.g. 1e5 for I32Polygon.
pub fn options(&self) -> PolygonBuildOptions
pub fn index_stats(&self) -> &PolygonIndexStats
pub fn set_exterior(&mut self, exterior: Vec<Point<T>>)
pub fn set_holes(&mut self, holes: Vec<Vec<Point<T>>>)
pub fn set_options(&mut self, options: PolygonBuildOptions)
Source§impl Polygon
impl Polygon
Sourcepub fn new(
exterior: Vec<Point>,
holes: Vec<Vec<Point>>,
options: Option<PolygonBuildOptions>,
) -> Polygon
pub fn new( exterior: Vec<Point>, holes: Vec<Vec<Point>>, options: Option<PolygonBuildOptions>, ) -> Polygon
Create a new Polygon instance from exterior and holes.
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![],
None,
);
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§impl Polygon<i32>
impl Polygon<i32>
Sourcepub fn new_with_mode(
exterior: Vec<I32Point>,
holes: Vec<Vec<I32Point>>,
scale: f64,
raycast_mode: I32RaycastMode,
) -> Self
pub fn new_with_mode( exterior: Vec<I32Point>, holes: Vec<Vec<I32Point>>, scale: f64, raycast_mode: I32RaycastMode, ) -> Self
Create a polygon from scaled integer coordinates with no acceleration index.
(There is intentionally no I32Polygon::new: a second inherent new
would make plain Polygon::new(...) calls ambiguous.)
Sourcepub fn new_with_options(
exterior: Vec<I32Point>,
holes: Vec<Vec<I32Point>>,
scale: f64,
raycast_mode: I32RaycastMode,
options: Option<PolygonBuildOptions>,
) -> Self
pub fn new_with_options( exterior: Vec<I32Point>, holes: Vec<Vec<I32Point>>, scale: f64, raycast_mode: I32RaycastMode, options: Option<PolygonBuildOptions>, ) -> Self
Create a polygon from scaled integer coordinates with explicit build
options; the acceleration indexes operate directly in the scaled
integer storage space. The indexes only serve the default (float)
raycast; I32RaycastMode::Integer always scans segments linearly.