Class ZoomSnapMath
- Namespace
- LansMap.Core.Interaction
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
-
objectZoomSnapMath
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
zoomdoubleZoom in Web Mercator zoom units.
snapdoubleGrid granularity.
<= 0or NaN disables snapping (returnszoomunchanged).
Returns
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
zoomdoubleZoom at fling launch, in Web Mercator zoom units.
velocitydoubleNatural (already direction/cap-clamped) fling velocity, zoom units per second.
durationSecondsdoubleFling duration in seconds. Non-positive returns
velocityunchanged.snapdoubleGrid granularity.
<= 0or NaN disables snapping (returnsvelocityunchanged).
Returns
- double
The rescaled velocity. Zero when the natural endpoint is already on the grid (no fling needed); its sign can flip relative to
velocitywhen the nearest grid point lies on the opposite side ofzoomfrom the natural endpoint - that reversed value IS the settle back to the nearest grid point, by design.