S2CellIdSnapFunction

A SnapFunction that snaps vertices to S2CellId centers. This can be useful if you want to encode your geometry compactly using S2Polygon::Encode(), for example. You can snap to the centers of cells at any level.

Every snap level has a corresponding minimum snap radius, which is simply the maximum distance that a vertex can move when snapped. It is approximately equal to half of the maximum diagonal length for cells at the chosen level. You can also set the snap radius to a larger value; for example, you could snap to the centers of leaf cells (1cm resolution) but set the snap_radius() to 10m. This would result in significant extra simplification, without moving vertices unnecessarily (i.e., vertices that are at least 10m away from all other vertices will move by less than 1cm).

Constructors

this
this()

The default constructor snaps to S2CellId::kMaxLevel (i.e., the centers of leaf cells), and uses the minimum allowable snap radius at that level.

this
this(int level)

Convenience constructor equivalent to calling set_level(level).

this
this(S2CellIdSnapFunction other)
Undocumented in source.

Members

Functions

clone
S2Builder.SnapFunction clone()
Undocumented in source. Be warned that the author may not have intended to support it.
level
int level()
Undocumented in source. Be warned that the author may not have intended to support it.
minEdgeVertexSeparation
S1Angle minEdgeVertexSeparation()

For S2CellId snapping, the minimum separation between edges and non-incident vertices depends on level() and snap_radius(). It can be as low as 0.219 * snap_radius(), but is typically 0.5 * snap_radius() or more.

minVertexSeparation
S1Angle minVertexSeparation()

For S2CellId snapping, the minimum separation between vertices depends on level() and snap_radius(). It can vary between 0.5 * snap_radius() and snap_radius().

setLevel
void setLevel(int level)

Snaps vertices to S2Cell centers at the given level. As a side effect, this method also resets "snap_radius" to the minimum value allowed at this level:

setSnapRadius
void setSnapRadius(S1Angle snap_radius)

Defines the snap radius to be used (see s2builder.h). The snap radius must be at least the minimum value for the current level(), but larger values can also be used (e.g., to simplify the geometry).

snapPoint
S2Point snapPoint(S2Point point)
Undocumented in source. Be warned that the author may not have intended to support it.
snapRadius
S1Angle snapRadius()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

levelForMaxSnapRadius
int levelForMaxSnapRadius(S1Angle snap_radius)

Returns the minimum S2Cell level (i.e., largest S2Cells) such that vertices will not move by more than "snap_radius". This can be useful when choosing an appropriate level to snap to. The return value is always a valid level (out of range values are silently clamped).

minSnapRadiusForLevel
S1Angle minSnapRadiusForLevel(int level)

Returns the minimum allowable snap radius for the given S2Cell level (approximately equal to half of the maximum cell diagonal length).

Inherited Members

From SnapFunction

snapRadius
S1Angle snapRadius()

The maximum distance that vertices can move when snapped.

kMaxSnapRadius
S1Angle kMaxSnapRadius()

The maximum snap radius is just large enough to support snapping to S2CellId level 0. It is equivalent to 7800km on the Earth's surface.

maxEdgeDeviation
S1Angle maxEdgeDeviation()

The maximum distance that the center of an edge can move when snapped. This is slightly larger than "snap_radius" because when a geodesic edge is snapped, the center of the edge moves further than its endpoints.

minVertexSeparation
S1Angle minVertexSeparation()

The guaranteed minimum distance between vertices in the output. This is generally some fraction of "snap_radius".

minEdgeVertexSeparation
S1Angle minEdgeVertexSeparation()

The guaranteed minimum spacing between edges and non-incident vertices in the output. This is generally some fraction of "snap_radius".

snapPoint
S2Point snapPoint(S2Point point)

Returns a candidate snap site for the given point. The final vertex locations are a subset of the snap sites returned by this function (spaced at least "min_vertex_separation" apart).

clone
SnapFunction clone()
Undocumented in source.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta