Skip to main content

clamp_viewport

Function clamp_viewport 

Source
pub fn clamp_viewport(viewport: DataRect, data_extent: &DataRect) -> DataRect
Expand 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: pos is clamped to [xMin, xMax - size];
  • when the viewport is larger than the data, the data is kept inside the viewport: pos is clamped to [xMax - size, xMin] (note the reversed bounds).

viewport.width / viewport.height are preserved; only left / top move. Returns the clamped viewport.