pub struct Polygon { /* private fields */ }Expand description
A polygon on a unit sphere, given by its vertices and the edge direction
Implementations§
Source§impl Polygon
impl Polygon
Sourcepub fn new(
vertices_in: Vec<SphericalPoint>,
edges_direction: EdgeDirection,
) -> Result<Self, SphericalError>
pub fn new( vertices_in: Vec<SphericalPoint>, edges_direction: EdgeDirection, ) -> Result<Self, SphericalError>
Creates a new polygon with the vertices and edges direction provided.
§Important
If the final vertex is not equal to the first one, it will be added automatically.
Flipping the direction of the edges will cause a polygon to be the complement of what you would expect to be your polygon (if you wanted to create a small triangle around the North Pole but flipped the edge orientation, you would define the polygon to be everywhere apart from the North Pole).
§Panics
This function panics if no vertices were provided. That does not constitute a valid polygon, and you should always provide at least two vertices.
§Errors
If any edge is defined by essentially equal or antipodal points, returns SphericalError::AntipodalOrTooClosePoints as in the case of identical or antipodal points the great circle (and therefore also the edge) is not uniquely defined.
Sourcepub fn vertices(&self) -> &Vec<SphericalPoint>
pub fn vertices(&self) -> &Vec<SphericalPoint>
Returns a reference to the vertices list
Sourcepub fn edges_direction(&self) -> EdgeDirection
pub fn edges_direction(&self) -> EdgeDirection
Returns the edges direction
Sourcepub fn contains_point(
&self,
point: &SphericalPoint,
) -> Result<bool, SphericalError>
pub fn contains_point( &self, point: &SphericalPoint, ) -> Result<bool, SphericalError>
Checks if the polygon contains the given point
§Errors
This function does not produce its own errors, but it will propagate inner errors out, see below. That should however never happen - if it does, it is a bug in an implementation in the library, so please report it should you encounter it.
If any of the edges fails to be constructed as a GreatCircleArc, returns the corresponding error. This should however never happen, as that is checked when the polygon is constructed.
Also, if any intersections fail the corresponding error will be returned. This should however also never happen.
Sourcepub fn great_circle_arc_intersections(
&self,
arc: &GreatCircleArc,
) -> Result<Vec<SphericalPoint>, SphericalError>
pub fn great_circle_arc_intersections( &self, arc: &GreatCircleArc, ) -> Result<Vec<SphericalPoint>, SphericalError>
Returns the intersections of the edges of the polygon with a given great circle arc
§Errors
This function does not generate its own errors, but may propagate the following:
- If any of the edges fails to be constructed as a GreatCircleArc, returns the corresponding error (see GreatCircleArc::new). This should however never happen, as that is checked when the polygon is constructed.
- If an edge fails to be intersected with the arc, it returns the corresponding error (refer to GreatCircleArc::intersect_great_circle_arc for more details).
Sourcepub fn intersects_great_circle_arc(
&self,
arc: &GreatCircleArc,
) -> Result<bool, SphericalError>
pub fn intersects_great_circle_arc( &self, arc: &GreatCircleArc, ) -> Result<bool, SphericalError>
Checks if there exists an intersection of the edges of the polygon with the provided GreatCircleArc
This function will in theory return errors less often than Self::great_circle_arc_intersections as it handles the cases when arcs are parallel
§Errors
This function does not generate its own errors, but may propagate the following:
- If any of the edges fails to be constructed as a GreatCircleArc, returns the corresponding error (see GreatCircleArc::new). This should however never happen, as that is checked when the polygon is constructed.
- If an edge fails to be intersected with the arc, it returns the corresponding error (refer to GreatCircleArc::intersects_great_circle_arc for more details). Handles parallel circles as infinite intersections (returns
Ok(true)) though.
Sourcepub fn great_circle_intersections(
&self,
circle: &GreatCircle,
) -> Result<Vec<SphericalPoint>, SphericalError>
pub fn great_circle_intersections( &self, circle: &GreatCircle, ) -> Result<Vec<SphericalPoint>, SphericalError>
Returns the intersections of the edges of the polygon with a given great circle
§Errors
This function does not generate its own errors, but may propagate the following:
- If any of the edges fails to be constructed as a GreatCircleArc, returns the corresponding error (see GreatCircleArc::new). This should however never happen, as that is checked when the polygon is constructed.
- If an edge fails to be intersected with the circle, it returns the corresponding error (refer to GreatCircleArc::intersect_great_circle for more details).
Sourcepub fn intersects_great_circle(
&self,
circle: &GreatCircle,
) -> Result<bool, SphericalError>
pub fn intersects_great_circle( &self, circle: &GreatCircle, ) -> Result<bool, SphericalError>
Checks if there exists an intersection of the edges of the polygon with the provided GreatCircle
This function will in theory return errors less often than Self::great_circle_intersections as it handles the cases when circles are parallel
§Errors
This function does not generate its own errors, but may propagate the following:
- If any of the edges fails to be constructed as a GreatCircleArc, returns the corresponding error (see GreatCircleArc::new). This should however never happen, as that is checked when the polygon is constructed.
- If an edge fails to be intersected with the circle, it returns the corresponding error (refer to GreatCircleArc::intersects_great_circle for more details). Handles parallel circles as infinite intersections (returns
Ok(true)) though.
Auto Trait Implementations§
impl Freeze for Polygon
impl RefUnwindSafe for Polygon
impl Send for Polygon
impl Sync for Polygon
impl Unpin for Polygon
impl UnwindSafe for Polygon
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.