pub struct SPolygon { /* private fields */ }Expand description
A Simple Polygon is a polygon that does not intersect itself and contains no holes. It is a closed shape with a finite number of vertices and edges. read more
Implementations§
Source§impl SPolygon
impl SPolygon
Sourcepub const MIN_EDGE_LENGTH_RATIO: f32 = 1e-5
pub const MIN_EDGE_LENGTH_RATIO: f32 = 1e-5
Minimum length of an edge, as a fraction of the polygon’s diameter.
Shorter edges are removed on construction, see SPolygon::new.
The margin is large compared to the f32 rounding error of the coordinates of a centered polygon
(about 6e-8 times the diameter), so centering or rotating it cannot collapse an edge into a single point (issue #133).
Transformable::transform and TransformableFrom::transform_from do not uphold this minimum:
translated far from the origin, where the f32 spacing exceeds it, a short edge can still collapse.
Collision detection does not rely on the minimum; rebuild the polygon with SPolygon::new where it is needed.
Sourcepub fn new(points: Vec<Point>) -> Result<Self>
pub fn new(points: Vec<Point>) -> Result<Self>
Create a new simple polygon from a set of points, expensive operations are performed here! Use Self::clone() or Self::transform() to avoid recomputation.
Every vertex that lies closer than SPolygon::MIN_EDGE_LENGTH_RATIO times the diameter
to the previous kept vertex is removed, so no edge is shorter than that.
Returns an error if the remaining vertices do not form a valid simple polygon.
pub fn generate_surrogate(&mut self, config: SPSurrogateConfig) -> Result<()>
pub fn vertex(&self, i: usize) -> Point
pub fn edge(&self, i: usize) -> Edge
pub fn edge_iter(&self) -> impl Iterator<Item = Edge> + '_
pub fn n_vertices(&self) -> usize
pub fn surrogate(&self) -> &SPSurrogate
pub fn generate_bounding_box(points: &[Point]) -> Rect
pub fn calculate_area(points: &[Point]) -> f32
pub fn centroid(&self) -> Point
Sourcepub fn vertices(&self) -> &[Point]
pub fn vertices(&self) -> &[Point]
Vertices in counterclockwise order, including after reflection.
Sourcepub fn poi(&self) -> Circle
pub fn poi(&self) -> Circle
Pole of inaccessibility represented as a circle
Trait Implementations§
Source§impl CollidesWith<Point> for SPolygon
impl CollidesWith<Point> for SPolygon
fn collides_with(&self, point: &Point) -> bool
Source§impl DistanceTo<Point> for SPolygon
impl DistanceTo<Point> for SPolygon
Source§fn distance_to(&self, point: &Point) -> f32
fn distance_to(&self, point: &Point) -> f32
Source§fn sq_distance_to(&self, point: &Point) -> f32
fn sq_distance_to(&self, point: &Point) -> f32
DistanceTo::distance_toSource§impl SeparationDistance<Point> for SPolygon
impl SeparationDistance<Point> for SPolygon
Source§fn separation_distance(&self, point: &Point) -> (GeoPosition, f32)
fn separation_distance(&self, point: &Point) -> (GeoPosition, f32)
self and other, returns GeoPosition::Interior and the minimum distance to separate the two primitives.
Otherwise, returns GeoPosition::Exterior and the minimum distance between the two primitives. (similar to DistanceTo::distance_to)Source§fn sq_separation_distance(&self, point: &Point) -> (GeoPosition, f32)
fn sq_separation_distance(&self, point: &Point) -> (GeoPosition, f32)
SeparationDistance::separation_distanceSource§impl Transformable for SPolygon
impl Transformable for SPolygon
Source§fn transform(&mut self, t: &Transformation) -> &mut Self
fn transform(&mut self, t: &Transformation) -> &mut Self
self.Source§fn transform_clone(&self, t: &Transformation) -> Self
fn transform_clone(&self, t: &Transformation) -> Self
Source§impl TransformableFrom for SPolygon
impl TransformableFrom for SPolygon
Source§fn transform_from(&mut self, reference: &Self, t: &Transformation) -> &mut Self
fn transform_from(&mut self, reference: &Self, t: &Transformation) -> &mut Self
self.Auto Trait Implementations§
impl Freeze for SPolygon
impl RefUnwindSafe for SPolygon
impl Send for SPolygon
impl Sync for SPolygon
impl Unpin for SPolygon
impl UnsafeUnpin for SPolygon
impl UnwindSafe for SPolygon
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more