Table of Contents

Class ZoomSnapMath

Pure zoom-snap math for the rest-zoom integer snap feature: the nearest grid target for a settle animation, and the fling-velocity retarget that lands a zoom fling exactly on that grid instead of its natural (unsnapped) endpoint.

public static class ZoomSnapMath
Inheritance
object
ZoomSnapMath

Remarks

No engine dependency, no allocation. Snap granularity 0 (or negative, or NaN) means the feature is off: both functions return their input unchanged.

Methods

Snap(double, double)

Nearest multiple of snap to zoom, on a grid anchored at 0.

public static double Snap(double zoom, double snap)

Parameters

zoom double

Zoom in Web Mercator zoom units.

snap double

Grid granularity. <= 0 or NaN disables snapping (returns zoom unchanged).

Returns

double

SnappedFlingVelocity(double, double, double, double)

Rescales a zoom fling's velocity so its linear decay over durationSeconds lands exactly on the snapped grid point nearest the fling's natural (unsnapped) endpoint, instead of that natural endpoint.

public static double SnappedFlingVelocity(double zoom, double velocity, double durationSeconds, double snap)

Parameters

zoom double

Zoom at fling launch, in Web Mercator zoom units.

velocity double

Natural (already direction/cap-clamped) fling velocity, zoom units per second.

durationSeconds double

Fling duration in seconds. Non-positive returns velocity unchanged.

snap double

Grid granularity. <= 0 or NaN disables snapping (returns velocity unchanged).

Returns

double

The rescaled velocity. Zero when the natural endpoint is already on the grid (no fling needed); its sign can flip relative to velocity when the nearest grid point lies on the opposite side of zoom from the natural endpoint - that reversed value IS the settle back to the nearest grid point, by design.