<commit_before>
package com.badlogic.gdx.utils.viewport;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.utils.Scaling;

/** A viewport that defines minimum and maximum dimensions.
 * <p>
 * When snap is enabled, it will pick the closest dimensions to the screen aspect ratio and use {@link Scaling#fit}. This will
 * result in black bars (letterboxing) if the screen doesn't exactly match any of the two supported ratios.
 * <p>
 * When snap is disabled and the screen aspect ratio falls within the supported range, it will keep it and scale the image.
 * Otherwise, it will pick the closest supported aspect ratio and use {@link Scaling#fit}, which will result in black bars
 * (letterboxing).
 * @author <NAME> */
public class MinMaxViewport extends ScalingViewport {
	private final float minWorldWidth, minWorldHeight;
	private final float maxWorldWidth, maxWorldHeight;
	private final float minAspectRatio, maxAspectRatio;
	private final boolean snap;

	public MinMaxViewport (float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight, boolean snap,
		Camera camera) {
		super(Scaling.fit, minWorldWidth, minWorldHeight, camera);

		this.minWorldWidth = minWorldWidth;
		this.minWorldHeight = minWorldHeight;
		this.maxWorldWidth = maxWorldWidth;
		this.maxWorldHeight = maxWorldHeight;
		this.snap = snap;
		minAspectRatio = minWorldWidth / minWorldHeight;
		maxAspectRatio = maxWorldWidth / maxWorldHeight;

		if (minAspectRatio > maxAspectRatio) {
			throw new IllegalArgumentException("Minimum aspect ratio has to be smaller than maximum aspect ratio: " + minAspectRatio
				+ " < " + maxAspectRatio);
		}
	}

	@Override
	public void update (int screenWidth, int screenHeight, boolean centerCamera) {
		float screenAspectRatio = (float)screenWidth / (float)screenHeight;

		if (snap) {
			if (Math.abs(screenAspectRatio - minAspectRatio) < Math.abs(screenAspectRatio - maxAspectRatio)) {
				setScaling(Scaling.fit);
				setWorldSize(minWorldWidth, minWorldHeight);
			} else {
				setWorldSize(maxWorldWidth, maxWorldHeight);
			}
		} else {
			if (screenAspectRatio < minAspectRatio) {
				setScaling(Scaling.fit);
				setWorldSize(minWorldWidth, minWorldHeight);
			} else if (screenAspectRatio > maxAspectRatio) {
				setScaling(Scaling.fit);
				setWorldSize(maxWorldWidth, maxWorldHeight);
			} else if (screenWidth > maxWorldWidth || screenHeight > maxWorldHeight) {
				setScaling(Scaling.fit);
				setWorldSize(maxWorldWidth, maxWorldWidth / screenAspectRatio);
			} else if (screenWidth < minWorldWidth || screenHeight < minWorldHeight) {
				setScaling(Scaling.fit);
				setWorldSize(minWorldWidth, minWorldWidth / screenAspectRatio);
			} else {
				setScaling(Scaling.fill);
				setWorldSize(screenWidth, screenHeight);
			}
		}

		super.update(screenWidth, screenHeight, centerCamera);
	}
}
<commit_msg>Fixes non snapped in range MinMaxViewport (doh)<commit_after>
package com.badlogic.gdx.utils.viewport;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.utils.Scaling;

/** A viewport that defines minimum and maximum dimensions.
 * <p>
 * When snap is enabled, it will pick the closest dimensions to the screen aspect ratio and use {@link Scaling#fit}. This will
 * result in black bars (letterboxing) if the screen doesn't exactly match any of the two supported ratios.
 * <p>
 * When snap is disabled and the screen aspect ratio falls within the supported range, it will keep it and scale the image.
 * Otherwise, it will pick the closest supported aspect ratio and use {@link Scaling#fit}, which will result in black bars
 * (letterboxing).
 * @author <NAME> */
public class MinMaxViewport extends ScalingViewport {
	private final float minWorldWidth, minWorldHeight;
	private final float maxWorldWidth, maxWorldHeight;
	private final float minAspectRatio, maxAspectRatio;
	private final boolean snap;

	public MinMaxViewport (float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight, boolean snap,
		Camera camera) {
		super(Scaling.fit, minWorldWidth, minWorldHeight, camera);

		this.minWorldWidth = minWorldWidth;
		this.minWorldHeight = minWorldHeight;
		this.maxWorldWidth = maxWorldWidth;
		this.maxWorldHeight = maxWorldHeight;
		this.snap = snap;
		minAspectRatio = minWorldWidth / minWorldHeight;
		maxAspectRatio = maxWorldWidth / maxWorldHeight;

		if (minAspectRatio > maxAspectRatio) {
			throw new IllegalArgumentException("Minimum aspect ratio has to be smaller than maximum aspect ratio: " + minAspectRatio
				+ " < " + maxAspectRatio);
		}
	}

	@Override
	public void update (int screenWidth, int screenHeight, boolean centerCamera) {
		float screenAspectRatio = (float)screenWidth / (float)screenHeight;

		if (snap) {
			if (Math.abs(screenAspectRatio - minAspectRatio) < Math.abs(screenAspectRatio - maxAspectRatio)) {
				setScaling(Scaling.fit);
				setWorldSize(minWorldWidth, minWorldHeight);
			} else {
				setWorldSize(maxWorldWidth, maxWorldHeight);
			}
		} else {
			if (screenAspectRatio < minAspectRatio) {
				setScaling(Scaling.fit);
				setWorldSize(minWorldWidth, minWorldHeight);
			} else if (screenAspectRatio > maxAspectRatio) {
				setScaling(Scaling.fit);
				setWorldSize(maxWorldWidth, maxWorldHeight);
			} else {
				setScaling(Scaling.fill);
				setWorldSize(maxWorldWidth, maxWorldWidth / screenAspectRatio);
			}
		}

		super.update(screenWidth, screenHeight, centerCamera);
	}
}

{'fraction_non_alphanumeric': 0.08460267939071389, 'fraction_numerical': 0.0, 'mean_word_length': 4.785562632696391, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6612235', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1585, 'n_words': 473}