package dev.photosync.core.capture;

/**
 * Where a screenshot would be taken from, and which way it would be looking.
 *
 * <p>Five plain numbers rather than anything belonging to the game, so that the
 * automatic-capture timer can tell whether the view has changed without this
 * module knowing what a camera is. The platform fills it in from whatever entity
 * the camera is attached to, which is the player except in spectator mode.
 */
public record CameraPose(double x, double y, double z, float yaw, float pitch) {

    /**
     * A player standing still is not perfectly still -- riding a boat, bobbing in
     * water or resting on a slime block all jitter the last decimals -- so
     * "moved" needs a floor. Five centimetres and half a degree sit well below
     * anything a player does on purpose: one sneaking tick covers 0.065 blocks,
     * and a single pixel of mouse movement turns the view by more than half a
     * degree at default sensitivity.
     */
    private static final double POSITION_EPSILON = 0.05;
    private static final float ROTATION_EPSILON = 0.5f;

    /**
     * Whether this is a different enough view from {@code other} to count as the
     * player having moved -- walked, or looked somewhere else.
     *
     * <p>Callers compare against the last pose that differed rather than against
     * the previous tick, so movement slower than the epsilon per tick still
     * registers once it has accumulated.
     */
    public boolean movedFrom(CameraPose other) {
        return Math.abs(x - other.x) > POSITION_EPSILON
                || Math.abs(y - other.y) > POSITION_EPSILON
                || Math.abs(z - other.z) > POSITION_EPSILON
                || Math.abs(yaw - other.yaw) > ROTATION_EPSILON
                || Math.abs(pitch - other.pitch) > ROTATION_EPSILON;
    }
}
