s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
173 lines • 6.75 kB
TypeScript
import type { S1Angle } from '../s1/angle';
import type { S1ChordAngle } from '../s1/chordAngle';
import type { Point3D, S2CellId, Vertices } from '../';
/**
* 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
*/
export interface S2Cap<T> {
/** the center of the cap */
center: Point3D;
/** the radius of the cap */
radius: S1ChordAngle;
/** the data associated with the cap */
data: T;
}
/**
* Return an empty cap, i.e. a cap that contains no points.
* @param data - the data
* @returns - the empty cap
*/
export declare function emptyCap<T>(data: T): S2Cap<T>;
/**
* Return a full cap, i.e. a cap that contains all points.
* @param data - the data
* @returns - the full cap
*/
export declare function fullCap<T>(data: T): S2Cap<T>;
/**
* Return the area of the cap.
* @param cap - the cap
* @returns - the area
*/
export declare function getArea<T>(cap: S2Cap<T>): number;
/**
* Return true if the cap is empty, i.e. it contains no points.
* @param cap - the cap
* @returns - true if the cap is empty
*/
export declare function isEmpty<T>(cap: S2Cap<T>): boolean;
/**
* Return true if the cap is full, i.e. it contains all points.
* @param cap - the cap
* @returns - true if the cap is full
*/
export declare function isFull<T>(cap: S2Cap<T>): boolean;
/**
* Returns the height of the cap, i.e. the distance from the center point to
* the cutoff plane.
* @param cap - the cap
* @returns - the height
*/
export declare function height<T>(cap: S2Cap<T>): number;
/**
* 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.
* @param center - the center point
* @param radius - the radius
* @param data - the data
* @returns - the cap
*/
export declare function fromS1Angle<T>(center: Point3D, radius: S1Angle, data: T): S2Cap<T>;
/**
* Constructs a cap where the angle is expressed as an S1ChordAngle. This
* constructor is more efficient than the one above.
* @param center - the center
* @param radius - the radius
* @param data - the data
* @returns - the cap
*/
export declare function fromS1ChordAngle<T>(center: Point3D, radius: S1ChordAngle, data: T): S2Cap<T>;
/**
* Convenience function that creates a cap containing a single point. This
* method is more efficient that the S2Cap(center, radius) constructor.
* @param center - the center
* @param data - the data
* @returns - an empty cap
*/
export declare function fromS2Point<T>(center: Point3D, data: T): S2Cap<T>;
/**
* 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.)
* @param cap - the cap
* @returns - the radius as an S1Angle in radians
*/
export declare function radius<T>(cap: S2Cap<T>): S1Angle;
/**
* Returns true if the cap contains the given point.
* NOTE: The point "p" should be a unit-length vector.
* @param cap - the cap
* @param p - the point
* @returns - true if the cap contains the point
*/
export declare function containsS2Point<T>(cap: S2Cap<T>, p: Point3D): boolean;
/**
* 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.
* @param cap - the cap
* @returns - the complement
*/
export declare function complement<T>(cap: S2Cap<T>): S2Cap<T>;
/**
* Return true if the cap contains the given cell.
* @param cap - the cap
* @param cell - the cell
* @returns - true if the cap contains the cell
*/
export declare function containsS2CellVertexCount<T>(cap: S2Cap<T>, cell: S2CellId): number;
/**
* Return true if the cap contains the given cell.
* @param cap - the cap
* @param cell - the cell
* @returns - true if the cap contains the cell
*/
export declare function containsS2Cell<T>(cap: S2Cap<T>, cell: S2CellId): boolean;
/**
* Return true if the cap intersects "cell", given that the cap does intersect
* any of the cell vertices or edges.
* @param cap - the cap
* @param cell - the cell
* @returns - true if the cap intersects the cell
*/
export declare function intersectsS2CellFast<T>(cap: S2Cap<T>, cell: S2CellId): boolean;
/**
* 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).
* @param cap - the cap
* @param cell - the cell
* @param vertices - the vertices of the cell
* @returns - true if the cap intersects the cell
*/
export declare function intersectsS2Cell<T>(cap: S2Cap<T>, cell: S2CellId, vertices: Vertices): boolean;
/**
* @param cap - the cap
* @returns - the cells that intersect the cap
*/
export declare function getIntersectingCells<T>(cap: S2Cap<T>): S2CellId[];
//# sourceMappingURL=cap.d.ts.map