pub fn clamp_viewport(viewport: DataRect, data_extent: &DataRect) -> DataRectExpand description
Clamp a candidate viewport top-left so the viewport stays consistent with the data extent on drag.
Faithful to _DraggableRectItem.itemChange (RadarView.py:82-110): the
constraint rectangle is the data extent [xMin, xMax] × [yMin, yMax].
Per axis, given the candidate position pos and the viewport extent
size:
- when the viewport is no larger than the data (
size <= xMax - xMin), the viewport is kept inside the data:posis clamped to[xMin, xMax - size]; - when the viewport is larger than the data, the data is kept inside
the viewport:
posis clamped to[xMax - size, xMin](note the reversed bounds).
viewport.width / viewport.height are preserved; only left / top
move. Returns the clamped viewport.