pub struct PolygonArea<'a> { /* private fields */ }
Expand description

Compute the perimeter and area of a polygon on a Geodesic.

Implementations§

source§

impl<'a> PolygonArea<'a>

PolygonArea can be used to compute the perimeter and area of a polygon on a Geodesic.

§Example

use geographiclib_rs::{Geodesic, PolygonArea, Winding};

let g = Geodesic::wgs84();
let mut pa = PolygonArea::new(&g, Winding::CounterClockwise);

pa.add_point(0.0, 0.0);
pa.add_point(0.0, 1.0);
pa.add_point(1.0, 1.0);
pa.add_point(1.0, 0.0);

let (perimeter, area, _num) = pa.compute(false);

use approx::assert_relative_eq;
assert_relative_eq!(perimeter, 443770.917248302);
assert_relative_eq!(area, 12308778361.469452);
source

pub fn new(geoid: &'a Geodesic, winding: Winding) -> PolygonArea<'_>

Create a new PolygonArea using a Geodesic.

source

pub fn add_point(&mut self, lat: f64, lon: f64)

Add a point to the polygon

source

pub fn add_edge(&mut self, azimuth: f64, distance: f64)

Add an edge to the polygon using an azimuth (in degrees) and a distance (in meters). This can only be called after at least one point has been added.

§Panics

Panics if no points have been added yet.

source

pub fn compute(self, sign: bool) -> (f64, f64, usize)

Consumes the PolygonArea and returns the following tuple:

  • 0: Perimeter in (meters) of the polygon.
  • 1: Area (meters²) of the polygon.
  • 2: Number of points added to the polygon.
§Parameters
  • sign: Whether to allow negative values for the area.
    • true: Interpret an inversely wound polygon to be a “negative” area. This will produce incorrect results if the polygon covers over half the geodesic. See “Interpreting negative area values” below.
    • false: Always return a positive area. Inversely wound polygons are treated as if they are always wound the same way as the winding specified during creation of the PolygonArea. This is useful if you are dealing with very large polygons that might cover over half the geodesic, or if you are certain of your winding.
§Interpreting negative area values

A negative value can mean one of two things:

  1. The winding of the polygon is opposite the winding specified during creation of the PolygonArea.
  2. The polygon is larger than half the planet. In this case, to get the final area of the polygon, add the area of the planet to the result. If you expect to be dealing with polygons of this size pass signed = false to compute() to get the correct result.
§Large polygon example
use geographiclib_rs::{Geodesic, PolygonArea, Winding};
let g = Geodesic::wgs84();

// Describe a polygon that covers all of the earth EXCEPT this small square.
// The outside of the polygon is in this square, the inside of the polygon is the rest of the earth.
let mut pa = PolygonArea::new(&g, Winding::CounterClockwise);
pa.add_point(0.0, 0.0);
pa.add_point(1.0, 0.0);
pa.add_point(1.0, 1.0);
pa.add_point(0.0, 1.0);

let (_perimeter, area, _count) = pa.compute(false);

// Over 5 trillion square meters!
assert_eq!(area, 510053312945726.94);
source

pub fn test_point(&self, lat: f64, lon: f64, sign: bool) -> (f64, f64, usize)

Check what the perimeter and area would be if this point was added to the polygon without actually adding it

source

pub fn test_edge( &self, azimuth: f64, distance: f64, sign: bool ) -> (f64, f64, usize)

Check what the perimeter and area would be if this edge was added to the polygon without actually adding it

Trait Implementations§

source§

impl<'a> Clone for PolygonArea<'a>

source§

fn clone(&self) -> PolygonArea<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for PolygonArea<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for PolygonArea<'a>

§

impl<'a> Send for PolygonArea<'a>

§

impl<'a> Sync for PolygonArea<'a>

§

impl<'a> Unpin for PolygonArea<'a>

§

impl<'a> UnwindSafe for PolygonArea<'a>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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