fit method
Fit contentSize inside viewportSize (contain), centered.
Implementation
void fit(Size contentSize, Size viewportSize) {
if (contentSize.width <= 0 || contentSize.height <= 0) return;
if (viewportSize.width <= 0 || viewportSize.height <= 0) return;
final sx = viewportSize.width / contentSize.width;
final sy = viewportSize.height / contentSize.height;
final desired = [sx, sy, maxScale].reduce((a, b) => a < b ? a : b);
final clamped = desired.clamp(minScale, maxScale).toDouble();
final newOffset = Offset(
(viewportSize.width - contentSize.width * clamped) / 2.0,
(viewportSize.height - contentSize.height * clamped) / 2.0,
);
_state = ViewportState(scale: clamped, offset: newOffset);
notifyListeners();
}