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:
S2Cap::new: Create a new S2CapS2Cap::empty: Return an empty cap, i.e. a cap that contains no points.S2Cap::full: Return a full cap, i.e. a cap that contains all points.S2Cap::area: Return the area of the cap.S2Cap::is_empty: Return true if the cap is empty, i.e. it contains no points.S2Cap::is_full: Return true if the cap is full, i.e. it contains all points.S2Cap::height: Return the cap height.S2Cap::from_s1_angle: Convenience function that creates a cap where the angle is expressed as an S1Angle.S2Cap::from_s1_chord_angle: Convenience function that creates a cap where the angle is expressed as an S1ChordAngle.S2Cap::from_s2_point: Convenience function that creates a cap containing a single point.S2Cap::radius: Return the cap radius as an S1Angle.S2Cap::contains_s2_point: Returns true if the cap contains the given point.S2Cap::complement: Return the complement of the interior of the cap.S2Cap::contains_s2_cell_vertex_count: Return count of vertices the cap contains for the given cell.S2Cap::contains_s2_cell: Return true if the cap contains the given cell.S2Cap::intersects_s2_cell_fast: Return true if the cap intersects “cell”, given that the cap does contain any of the cell vertices.S2Cap::intersects_s2_cell: 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).S2Cap::get_intersecting_cells: Return the cells that intersect the cap.
Fields§
§center: S2Pointthe center of the cap
radius: S1ChordAnglethe radius of the cap
data: Tthe data associated with the cap
Implementations§
Source§impl<T> S2Cap<T>where
T: Clone,
impl<T> S2Cap<T>where
T: Clone,
Sourcepub fn new(center: S2Point, radius: S1ChordAngle, data: T) -> Self
pub fn new(center: S2Point, radius: S1ChordAngle, data: T) -> Self
Constructs a cap with the given center and radius.
Sourcepub fn height(&self) -> f64
pub fn height(&self) -> f64
Returns the height of the cap, i.e. the distance from the center point to the cutoff plane.
Sourcepub fn from_s1_angle(center: S2Point, radius: S1Angle, data: T) -> Self
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.
Sourcepub fn from_s1_chord_angle(
center: S2Point,
radius: S1ChordAngle,
data: T,
) -> Self
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.
Sourcepub fn from_s2_point(center: S2Point, data: T) -> Self
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.
Sourcepub fn radius(&self) -> S1Angle
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.)
Sourcepub fn contains_s2_point(&self, p: &S2Point) -> bool
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.
Sourcepub fn complement(&self) -> S2Cap<T>
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.
Sourcepub fn contains_s2_cell_vertex_count(&self, cell: S2CellId) -> usize
pub fn contains_s2_cell_vertex_count(&self, cell: S2CellId) -> usize
Return count of vertices the cap contains for the given cell.
Sourcepub fn contains_s2_cell(&self, cell: S2CellId) -> bool
pub fn contains_s2_cell(&self, cell: S2CellId) -> bool
Return true if the cap contains the given cell.
Sourcepub fn intersects_s2_cell_fast(&self, cell: S2CellId) -> bool
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.
Sourcepub fn intersects_s2_cell(
&self,
cell: S2CellId,
vertices: &[S2Point; 4],
) -> bool
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).
Sourcepub fn get_intersecting_cells(&self) -> Vec<S2CellId>
pub fn get_intersecting_cells(&self) -> Vec<S2CellId>
Return the cells that intersect the cap.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)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