package dev.photosync.core.capture;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * The thresholds decide whether a player is "still", which decides whether their
 * screenshots folder fills up while they are away from the keyboard. Both
 * mistakes are visible: too tight and a boat's bobbing counts as sightseeing,
 * too loose and a step to one side does not.
 */
class CameraPoseTest {

    private static final CameraPose RESTING = new CameraPose(100.0, 64.0, -20.0, 45.0f, 10.0f);

    @Test
    @DisplayName("an identical pose has not moved")
    void identical() {
        assertFalse(RESTING.movedFrom(RESTING));
    }

    @Test
    @DisplayName("jitter below the thresholds is not movement")
    void jitter() {
        CameraPose bobbing = new CameraPose(100.02, 63.98, -20.01, 45.2f, 10.3f);

        assertFalse(bobbing.movedFrom(RESTING));
    }

    @Test
    @DisplayName("one sneaking tick is movement")
    void walked() {
        // A sneaking player covers 0.065 blocks per tick -- the slowest way to
        // travel, and the closest a deliberate move comes to the threshold.
        CameraPose crept = new CameraPose(100.065, 64.0, -20.0, 45.0f, 10.0f);

        assertTrue(crept.movedFrom(RESTING));
    }

    @Test
    @DisplayName("looking somewhere else is movement, without leaving the spot")
    void lookedAround() {
        assertTrue(new CameraPose(100.0, 64.0, -20.0, 46.0f, 10.0f).movedFrom(RESTING), "yaw");
        assertTrue(new CameraPose(100.0, 64.0, -20.0, 45.0f, 11.0f).movedFrom(RESTING), "pitch");
    }

    @Test
    @DisplayName("each axis is judged on its own")
    void everyAxis() {
        assertTrue(new CameraPose(101.0, 64.0, -20.0, 45.0f, 10.0f).movedFrom(RESTING), "x");
        assertTrue(new CameraPose(100.0, 65.0, -20.0, 45.0f, 10.0f).movedFrom(RESTING), "y");
        assertTrue(new CameraPose(100.0, 64.0, -21.0, 45.0f, 10.0f).movedFrom(RESTING), "z");
    }
}
