Polygon

Struct Polygon 

Source
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

Source

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.

Source

pub fn vertices(&self) -> &Vec<SphericalPoint>

Returns a reference to the vertices list

Source

pub fn edges_direction(&self) -> EdgeDirection

Returns the edges direction

Source

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.

Source

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:

Source

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.
Source

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).
Source

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§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.