Repository: godotengine/godot
File: editor/scene/sprite_frames_editor_plugin.cpp (C++)

Code before:
void SpriteFramesEditor::_sheet_zoom_out() {
	sheet_zoom_fitted = false;
	_sheet_zoom_on_position(1 / scale_ratio, Vector2());
}

void SpriteFramesEditor::_sheet_zoom_reset() {
	sheet_zoom_fitted = false;
	// Default the zoom to match the editor scale, but don't dezoom on editor scales below 100% to prevent pixel art from looking bad.
	sheet_zoom = MAX(1.0f, EDSCALE);
	Size2 texture_size = split_sheet_preview->get_texture()->get_size();
	split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom);
}

void SpriteFramesEditor::_sheet_zoom_fit() {
	sheet_zoom_fitted = true;

	const float margin_percentage = 0.1f;
	const Size2 max_margin = Vector2(64.0f, 64.0f);
	const Size2 margin = (margin_percentage * split_sheet_scroll->get_size()).min(max_margin);
	const Size2 display_area_size = split_sheet_scroll->get_size() - margin;
	const Size2 texture_size = split_sheet_preview->get_texture()->get_size();
	const Vector2 texture_ratio = display_area_size / texture_size;
	const float texture_fit_zoom = MIN(texture_ratio.x, texture_ratio.y);

	const Size2 min_frame_size = Size2(64.0, 64.0);
	const Size2 frame_size = _get_frame_size().max(Size2i(1, 1));
	const Size2 frame_ratio = min_frame_size / frame_size;
	const float frame_fit_zoom = MAX(frame_ratio.x, frame_ratio.y);

	// Zoom in to fit the texture or to ensure minimum frame render size.
	// Zoom is floored to avoid subpixel rendering issues.
	const float fit_zoom = Math::floor(MAX(texture_fit_zoom, frame_fit_zoom));

	// Default the zoom to match the editor scale
	// and don't dezoom below 100% to prevent pixels merging.
	sheet_zoom = MAX(MAX(fit_zoom, 1.0f), EDSCALE);
	split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom);
}

void SpriteFramesEditor::_sheet_order_selected(int p_option) {
	frames_need_sort = true;
	split_sheet_preview->queue_redraw();
}

void SpriteFramesEditor::_sheet_select_all_frames() {
	for (int i = 0; i < split_sheet_h->get_value() * split_sheet_v->get_value(); i++) {
		if (!frames_selected.has(i)) {
			frames_selected.insert(i, selected_count);
			selected_count++;
			frames_need_sort = true;
		}

Review comment (suggestion):
```suggestion
	const Size2 frame_size = _get_frame_size().maxi(1);
```
Unless it is a `Size2`, then it should be
```suggestion
	const Size2 frame_size = _get_frame_size().maxf(1.0);
```

Code after:
	sheet_zoom = CLAMP(sheet_zoom * p_zoom, min_sheet_zoom, max_sheet_zoom);

	const Size2 texture_size = split_sheet_preview->get_texture()->get_size();
	split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom);

	Vector2 offset = Vector2(split_sheet_scroll->get_h_scroll(), split_sheet_scroll->get_v_scroll());
	offset = (offset + p_position) / old_zoom * sheet_zoom - p_position;
	split_sheet_scroll->set_h_scroll(offset.x);
	split_sheet_scroll->set_v_scroll(offset.y);

	_sheet_update_zoom_label();
}

void SpriteFramesEditor::_sheet_zoom_in() {
	_sheet_zoom_on_position(scale_ratio, Vector2());
}

void SpriteFramesEditor::_sheet_zoom_out() {
	_sheet_zoom_on_position(1 / scale_ratio, Vector2());
}

void SpriteFramesEditor::_sheet_zoom_reset() {
	// Default the zoom to match the editor scale, but don't dezoom on editor scales below 100% to prevent pixel art from looking bad.
	sheet_zoom = MAX(1.0f, EDSCALE);
	Size2 texture_size = split_sheet_preview->get_texture()->get_size();
	split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom);

	_sheet_update_zoom_label();
}

void SpriteFramesEditor::_sheet_zoom_fit() {
	const float margin_percentage = 0.1f;
	const float max_margin = 64.0f;
	const Size2 margin = (margin_percentage * split_sheet_scroll->get_size()).minf(max_margin);
	const Size2 display_area_size = split_sheet_scroll->get_size() - margin;
	const Size2 texture_size = split_sheet_preview->get_texture()->get_size();
	const Vector2 texture_ratio = display_area_size / texture_size;
	float texture_fit_zoom = MIN(texture_ratio.x, texture_ratio.y);

	// Quantize the zoom level to avoid subpixel rendering
	if (texture_fit_zoom > 1.0) {
		texture_fit_zoom = Math::floor(texture_fit_zoom);
	} else if (!Math::is_zero_approx(texture_fit_zoom)) {
		texture_fit_zoom = 1.0f / Math::ceil(1.0f / texture_fit_zoom);
	}

	sheet_zoom = CLAMP(texture_fit_zoom, min_sheet_zoom, max_sheet_zoom);
	split_sheet_preview->set_custom_minimum_size(texture_size * sheet_zoom);

	_sheet_update_zoom_label();
}