S2ClosestPointQueryBase

S2ClosestPointQueryBase is a templatized class for finding the closest point(s) to a given target. It is not intended to be used directly, but rather to serve as the implementation of various specialized classes with more convenient APIs (such as S2ClosestPointQuery). It is flexible enough so that it can be adapted to compute maximum distances and even potentially Hausdorff distances.

By using the appropriate options, this class can answer questions such as:

- Find the minimum distance between a point collection A and a target B. - Find all points in collection A that are within a distance D of target B. - Find the k points of collection A that are closest to a given point P.

The target is any class that implements the S2DistanceTarget interface. There are predefined targets for points, edges, S2Cells, and S2ShapeIndexes (arbitrary collctions of points, polylines, and polygons).

The Distance template argument is used to represent distances. Usually this type is a thin wrapper around S1ChordAngle, but another distance type may be substituted as long as it implements the API below. This can be used to change the comparison function (e.g., to find the furthest edges from the target), or to get more accuracy if desired.

The Distance concept is as follows:

class Distance { public: // Default and copy constructors, assignment operator: Distance(); Distance(const Distance&); Distance& operator=(const Distance&);

// Factory methods: static Distance Zero(); // Returns a zero distance. static Distance Infinity(); // Larger than any valid distance. static Distance Negative(); // Smaller than any valid distance.

// Comparison operators: friend bool operator==(Distance x, Distance y); friend bool operator<(Distance x, Distance y);

// Delta represents the positive difference between two distances. // It is used together with operator-() to implement Options::max_error(). // Typically Distance::Delta is simply S1ChordAngle. class Delta { public: Delta(); Delta(const Delta&); Delta& operator=(const Delta&); friend bool operator==(Delta x, Delta y); static Delta Zero(); };

// Subtraction operator. Note that the second argument represents a // delta between two distances. This distinction is important for // classes that compute maximum distances (e.g., S2FurthestEdgeQuery). friend Distance operator-(Distance x, Delta delta);

// Method that returns an upper bound on the S1ChordAngle corresponding // to this Distance (needed to implement Options::max_distance // efficiently). For example, if Distance measures WGS84 ellipsoid // distance then the corresponding angle needs to be 0.56% larger. S1ChordAngle GetChordAngleBound() const; };

Constructors

this
this()

Default constructor; requires initialize() to be called.

this
this(Index index)

Convenience constructor that calls Init().

Members

Aliases

Delta
alias Delta = Distance.Delta
Undocumented in source.
Index
alias Index = S2PointIndex!Data
Undocumented in source.
Options
alias Options = S2ClosestPointQueryBaseOptions!Distance
Undocumented in source.
PointData
alias PointData = Index.PointData
Undocumented in source.
Target
alias Target = S2DistanceTarget!Distance

The Target class represents the geometry to which the distance is measured. For example, there can be subtypes for measuring the distance to a point, an edge, or to an S2ShapeIndex (an arbitrary collection of geometry).

Functions

findClosestPoint
Result findClosestPoint(Target target, Options options)

Convenience method that returns exactly one point. If no points satisfy the given search criteria, then a Result with distance() == Infinity() and is_empty() == true is returned.

findClosestPoints
Result[] findClosestPoints(Target target, Options options)

Returns the closest points to the given target that satisfy the given options. This method may be called multiple times.

findClosestPoints
void findClosestPoints(Target target, Options options, Result[] results)

This version can be more efficient when this method is called many times, since it does not require allocating a new vector on each call.

index
const(Index) index()

Return a reference to the underlying S2PointIndex.

initialize
void initialize(S2PointIndex!Data index)

Initializes the query. REQUIRES: ReInit() must be called if "index" is modified.

reInitialize
void reInitialize()

Reinitializes the query. This method must be called whenever the underlying index is modified.

Structs

Result
struct Result

Each "Result" object represents a closest point.

Variables

MIN_POINTS_TO_ENQUEUE
enum int MIN_POINTS_TO_ENQUEUE;

The minimum number of points that a cell must contain to enqueue it rather than processing its contents immediately.

Meta