package com.foxx.androidcast.ui;

/*********************************************************************
 * PlaybackTextureTransformTest.java
 * Created at: Sat 16 May 2026 18:50:36 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class PlaybackTextureTransformTest
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (3 commits, 48 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	3419ff2e4f168b9cc12f2324e03cf8c922006fd70656f38ee713610dd1426562
**********************************************************************/
import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class PlaybackTextureTransformTest {
    @Test
    public void wideVideoOnWideViewIsUnityScale() {
        float[] scales = scalesFor(1920, 1080, 960, 540);
        assertEquals(1f, scales[0], 0.01f);
        assertEquals(1f, scales[1], 0.01f);
    }

    @Test
    public void tallVideoOnWideViewLetterboxesHorizontally() {
        float[] scales = scalesFor(1920, 1080, 540, 960);
        assertEquals(0.316f, scales[0], 0.02f);
        assertEquals(1f, scales[1], 0.01f);
    }

    @Test
    public void calibrationChartOnTabletLetterboxes() {
        float[] scales = scalesFor(1920, 1200, 500, 400);
        assertEquals(0.78f, scales[0], 0.02f);
        assertEquals(1f, scales[1], 0.01f);
    }

    private static float[] scalesFor(int viewW, int viewH, int videoW, int videoH) {
        float videoAspect = (float) videoW / videoH;
        float viewAspect = (float) viewW / viewH;
        float scaleX = 1f;
        float scaleY = 1f;
        if (videoAspect > viewAspect) {
            scaleY = viewAspect / videoAspect;
        } else {
            scaleX = videoAspect / viewAspect;
        }
        return new float[] {scaleX, scaleY};
    }
}
