S2Polyline

An S2Polyline represents a sequence of zero or more vertices connected by straight edges (geodesics). Edges of length 0 and 180 degrees are not allowed, i.e. adjacent vertices should not be identical or antipodal.

Constructors

this
this()

Creates an empty S2Polyline that should be initialized by calling Init() or Decode().

this
this(S2Point[] vertices)

Convenience constructors that call Init() with the given vertices.

this
this(S2LatLng[] vertices)
Undocumented in source.
this
this(S2Point[] vertices, S2Debug s2debugOverride)

Convenience constructors to disable the automatic validity checking controlled by the --s2debug flag. Example:

this
this(S2LatLng[] vertices, S2Debug s2debugOverride)
Undocumented in source.

Members

Classes

Shape
class Shape

Wrapper class for indexing a polyline (see S2ShapeIndex). Once this object is inserted into an S2ShapeIndex it is owned by that index, and will be automatically deleted when no longer needed by the index. Note that this class does not take ownership of the polyline itself (see OwningShape below). You can also subtype this class to store additional data (see S2Shape for details).

Functions

approxEquals
bool approxEquals(S2Polyline b, S1Angle max_error)

Return true if two polylines have the same number of vertices, and corresponding vertex pairs are separated by no more than "max_error". (For testing purposes.)

clone
S2Polyline clone()

/////////////////////////////////////////////////////////////////////

contains
bool contains(S2Cell cell)
Undocumented in source. Be warned that the author may not have intended to support it.
contains
bool contains(S2Point p)

Always return false, because "containment" is not numerically well-defined except at the polyline vertices.

decode
bool decode(Decoder!IRangeT decoder)

Decodes an S2Polyline encoded with Encode(). Returns true on success.

encode
void encode(Encoder!ORangeT encoder)

Appends a serialized representation of the S2Polyline to "encoder".

findValidationError
bool findValidationError(S2Error error)

Returns true if this is *not* a valid polyline and sets "error" appropriately. Otherwise returns false and leaves "error" unchanged.

getCapBound
S2Cap getCapBound()
Undocumented in source. Be warned that the author may not have intended to support it.
getCellUnionBound
void getCellUnionBound(S2CellId[] cell_ids)
Undocumented in source. Be warned that the author may not have intended to support it.
getCentroid
S2Point getCentroid()

Return the true centroid of the polyline multiplied by the length of the polyline (see s2centroids.h for details on centroids). The result is not unit length, so you may want to normalize it.

getLength
S1Angle getLength()

Return the length of the polyline.

getRectBound
S2LatLngRect getRectBound()
Undocumented in source. Be warned that the author may not have intended to support it.
getSuffix
S2Point getSuffix(double fraction, int next_vertex)

Like Interpolate(), but also return the index of the next polyline vertex after the interpolated point P. This allows the caller to easily construct a given suffix of the polyline by concatenating P with the polyline vertices starting at "next_vertex". Note that P is guaranteed to be different than vertex(*next_vertex), so this will never result in a duplicate vertex.

initialize
void initialize(S2Point[] vertices)

Initialize a polyline that connects the given vertices. Empty polylines are allowed. Adjacent vertices should not be identical or antipodal. All vertices should be unit length.

initialize
void initialize(S2LatLng[] vertices)

Convenience initialization function that accepts latitude-longitude coordinates rather than S2Points.

interpolate
S2Point interpolate(double fraction)

Return the point whose distance from vertex 0 along the polyline is the given fraction of the polyline's total length. Fractions less than zero or greater than one are clamped. The return value is unit length. This cost of this function is currently linear in the number of vertices. The polyline must not be empty.

intersects
bool intersects(S2Polyline line)

Return true if this polyline intersects the given polyline. If the polylines share a vertex they are considered to be intersecting. When a polyline endpoint is the only intersection with the other polyline, the function may return true or false arbitrarily.

isOnRight
bool isOnRight(S2Point point)

Returns true if the point given is on the right hand side of the polyline, using a naive definition of "right-hand-sideness" where the point is on the RHS of the polyline iff the point is on the RHS of the line segment in the polyline which it is closest to.

isValid
bool isValid()

Return true if the given vertices form a valid polyline.

mayIntersect
bool mayIntersect(S2Cell cell)
Undocumented in source. Be warned that the author may not have intended to support it.
nearlyCovers
bool nearlyCovers(S2Polyline covered, S1Angle max_error)
Undocumented in source. Be warned that the author may not have intended to support it.
numVertices
int numVertices()
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Object o)

Return true if two polylines are exactly the same.

project
S2Point project(S2Point point, int next_vertex)

Given a point, returns a point on the polyline that is closest to the given point. See GetSuffix() for the meaning of "next_vertex", which is chosen here w.r.t. the projected point as opposed to the interpolated point in GetSuffix().

reverse
void reverse()

Reverse the order of the polyline vertices.

s2debugOverride
S2Debug s2debugOverride()
Undocumented in source. Be warned that the author may not have intended to support it.
setS2debugOverride
void setS2debugOverride(S2Debug s2debugOverride)

Allows overriding the automatic validity checks controlled by the --s2debug flag. If this flag is true, then polylines are automatically checked for validity as they are initialized. The main reason to disable this flag is if you intend to call IsValid() explicitly, like this:

spaceUsed
size_t spaceUsed()
Undocumented in source. Be warned that the author may not have intended to support it.
subsampleVertices
void subsampleVertices(S1Angle tolerance, int[] indices)

Return a subsequence of vertex indices such that the polyline connecting these vertices is never further than "tolerance" from the original polyline. Provided the first and last vertices are distinct, they are always preserved; if they are not, the subsequence may contain only a single index.

unInterpolate
double unInterpolate(S2Point point, int next_vertex)

The inverse operation of GetSuffix/Interpolate. Given a point on the polyline, returns the ratio of the distance to the point from the beginning of the polyline over the length of the polyline. The return value is always betwen 0 and 1 inclusive. See GetSuffix() for the meaning of "next_vertex".

vertex
const(S2Point) vertex(int k)
Undocumented in source.
vertices
const(S2Point[]) vertices()
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From S2Region

clone
S2Region clone()

Returns a deep copy of the region.

getCapBound
S2Cap getCapBound()

Returns a bounding spherical cap that contains the region. The bound may not be tight.

getRectBound
S2LatLngRect getRectBound()

Returns a bounding latitude-longitude rectangle that contains the region. The bound may not be tight.

getCellUnionBound
void getCellUnionBound(S2CellId[] cellIds)

Returns a small collection of S2CellIds whose union covers the region. The cells are not sorted, may have redundancies (such as cells that contain other cells), and may cover much more area than necessary.

contains
bool contains(S2Cell cell)

Returns true if the region completely contains the given cell, otherwise returns false.

mayIntersect
bool mayIntersect(S2Cell cell)

If this method returns false, the region does not intersect the given cell. Otherwise, either region intersects the cell, or the intersection relationship could not be determined.

contains
bool contains(S2Point p)

Returns true if and only if the given point is contained by the region. The point 'p' is generally required to be unit length, although some subtypes may relax this restriction.

Meta