# Pure functions make image zoom geometry testable

[Journal](/journal/)

August 1, 2026 · [guides](/journal/#guides)



Contain fit, focal zoom, pan limits, and snap-back become exact claims when gesture code delegates geometry to pure functions.

![A fitted landscape frame expands around a verdigris focal pin within measured rails, with a mechanical spring ready to return it.](/_astro/pure-function-image-zoom-math.B6_7MKFw_20c65I.avif)

An image viewer can prove its geometry without claiming that a pinch feels good. Muniment Mobile separates those claims with 69 lines of dependency-free math.

The pure functions calculate fitted size, scale, translation, and bounds. A focused math suite checks those values without asking a native gesture recognizer to cooperate.

## Scale starts from a fitted image

At scale 1, the image uses a contain fit. The function compares the viewport and image aspect ratios, then fits the whole image inside the viewport.

Contain fit can leave unused space on one axis. It never crops the image to fill that space.

Every requested zoom passes through a 1× to 6× clamp. Values below 1× become 1×, and values above 6× become 6×.

A double tap toggles between 1× and 2.5×. This fixed target makes the toggle deterministic while the clamp keeps every path inside the same scale range.

## The touched point anchors focal zoom

Zooming around the center would make an off-center detail slide away from the fingers. Focal zoom instead keeps the touched point stationary as scale changes.

For each axis, the function applies `offset-(offset-currentTranslation)*ratio`. The offset marks the focal point, and the ratio compares the next scale with the current scale.

The resulting translation preserves that point before bounds apply. This is geometry the suite can check with exact inputs and expected outputs.

## Overflow sets the pan limits

Panning only has somewhere to go when a scaled image exceeds its viewport. Each axis gets a bound equal to half its scaled overflow.

The translation clamps between the negative and positive bound. An axis with no overflow gets a zero bound, so the image stays centered there.

These bounds depend on the fitted dimensions and current scale. They do not depend on momentum, touch velocity, or a rendering loop.

## Snap-back closes the low end

At or below scale 1, the functions return the fitted transform. Scale returns to 1×, and both translations return to zero.

That snap-back rule prevents a smaller image or stale pan offset from surviving the gesture. It also gives tests one canonical resting state.

The focused math suite covers the geometry. A component test also drives simulated pinch, pan, and double-tap events through the viewer.

This evidence comes from our Muniment Mobile note pinned to commit `903dbc1186859e22ad4517b629027710dfff1d21`.

The evidence measures no frame rate, physical-device gesture recognition, or interaction feel. Those require device work beyond deterministic geometry and simulated component events.
