S2Cap

Struct S2Cap 

Source
pub struct S2Cap<T = ()> {
    pub center: S2Point,
    pub radius: S1ChordAngle,
    pub data: T,
}
Expand description

S2Cap represents a disc-shaped region defined by a center and radius. Technically this shape is called a “spherical cap” (rather than disc) because it is not planar; the cap represents a portion of the sphere that has been cut off by a plane. The boundary of the cap is the circle defined by the intersection of the sphere and the plane. For containment purposes, the cap is a closed set, i.e. it contains its boundary.

For the most part, you can use a spherical cap wherever you would use a disc in planar geometry. The radius of the cap is measured along the surface of the sphere (rather than the straight-line distance through the interior). Thus a cap of radius Pi/2 is a hemisphere, and a cap of radius Pi covers the entire sphere.

A cap can also be defined by its center point and height. The height is simply the distance from the center point to the cutoff plane. There is also support for empty and full caps, which contain no points and all points respectively.

This class is intended to be copied by value as desired. It uses the default copy constructor and assignment operator, however it is not a “plain old datatype” (POD) because it has virtual functions.

Here are some useful relationships between the cap height (h), the cap radius (r), the maximum chord length from the cap’s center (d), and the radius of cap’s base (a).

$$ h = 1 - cos(r) $$ $$ = 2 * sin^2(r/2) $$ $$ d^2 = 2 * h $$ $$ = a^2 + h^2 $$

§Usage

Methods that are available:

Fields§

§center: S2Point

the center of the cap

§radius: S1ChordAngle

the radius of the cap

§data: T

the data associated with the cap

Implementations§

Source§

impl<T> S2Cap<T>
where T: Clone,

Source

pub fn new(center: S2Point, radius: S1ChordAngle, data: T) -> Self

Constructs a cap with the given center and radius.

Source

pub fn empty(data: T) -> Self

Return an empty cap, i.e. a cap that contains no points.

Source

pub fn full(data: T) -> Self

Return a full cap, i.e. a cap that contains all points.

Source

pub fn area(&self) -> f64

Return the area of the cap.

Source

pub fn is_empty(&self) -> bool

Return true if the cap is empty, i.e. it contains no points.

Source

pub fn is_full(&self) -> bool

Return true if the cap is full, i.e. it contains all points.

Source

pub fn height(&self) -> f64

Returns the height of the cap, i.e. the distance from the center point to the cutoff plane.

Source

pub fn from_s1_angle(center: S2Point, radius: S1Angle, data: T) -> Self

Constructs a cap with the given center and radius. A negative radius yields an empty cap; a radius of 180 degrees or more yields a full cap (containing the entire sphere). “center” should be unit length.

Source

pub fn from_s1_chord_angle( center: S2Point, radius: S1ChordAngle, data: T, ) -> Self

Constructs a cap where the angle is expressed as an S1ChordAngle. This constructor is more efficient than the one above.

Source

pub fn from_s2_point(center: S2Point, data: T) -> Self

Convenience function that creates a cap containing a single point. This method is more efficient that the S2Cap(center, radius) constructor.

Source

pub fn radius(&self) -> S1Angle

Return the cap radius as an S1Angle. (Note that the cap angle is stored internally as an S1ChordAngle, so this method requires a trigonometric operation and may yield a slightly different result than the value passed to the (S2Point, S1Angle) constructor.)

Source

pub fn contains_s2_point(&self, p: &S2Point) -> bool

Returns true if the cap contains the given point.

NOTE: The point “p” should be a unit-length vector.

Source

pub fn complement(&self) -> S2Cap<T>

Return the complement of the interior of the cap. A cap and its complement have the same boundary but do not share any interior points. The complement operator is not a bijection because the complement of a singleton cap (containing a single point) is the same as the complement of an empty cap.

Source

pub fn contains_s2_cell_vertex_count(&self, cell: S2CellId) -> usize

Return count of vertices the cap contains for the given cell.

Source

pub fn contains_s2_cell(&self, cell: S2CellId) -> bool

Return true if the cap contains the given cell.

Source

pub fn intersects_s2_cell_fast(&self, cell: S2CellId) -> bool

Return true if the cap intersects “cell”, given that the cap does intersect any of the cell vertices or edges.

Source

pub fn intersects_s2_cell( &self, cell: S2CellId, vertices: &[S2Point; 4], ) -> bool

Return true if the cap intersects “cell”, given that the cap does contain any of the cell vertices (supplied in “vertices”, an array of length 4). Return true if this cap intersects any point of ‘cell’ excluding its vertices (which are assumed to already have been checked).

Source

pub fn get_intersecting_cells(&self) -> Vec<S2CellId>

Return the cells that intersect the cap.

Trait Implementations§

Source§

impl<T: Clone> Clone for S2Cap<T>

Source§

fn clone(&self) -> S2Cap<T>

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for S2Cap<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Copy> Copy for S2Cap<T>

Auto Trait Implementations§

§

impl<T> Freeze for S2Cap<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for S2Cap<T>
where T: RefUnwindSafe,

§

impl<T> Send for S2Cap<T>
where T: Send,

§

impl<T> Sync for S2Cap<T>
where T: Sync,

§

impl<T> Unpin for S2Cap<T>
where T: Unpin,

§

impl<T> UnwindSafe for S2Cap<T>
where T: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V