# The space-time formula (st.py) against brute force (brute.py): several lattices (A, B, C)/N, spatial filters
# (Starlock's pass, its lite pass, the identity with the pass off) and eye models (one frame, boxes, decays),
# for what the eye keeps and for the shimmer. Prints out/check.txt.
import numpy as np
import filters as F, st, brute

def canvas(N):
    return N * max(1, int(np.ceil(24 / N)))

CASES = [('Starlock full', F.kuwahara(5), [(54, 11, 0, 56), (54, 11, 28, 56), (5, 1, 7, 24), (7, 3, 5, 16)]),
         ('Starlock lite', F.kuwahara(2), [(2, 1, 3, 10), (3, 5, 4, 13)]),
         ('paint off', [(0, 0, 1.0)], [(0, 0, 1, 2), (1, 2, 3, 8), (3, 1, 5, 11)])]
EYES = [st.still(), st.box(2), st.box(4), st.decay(40), st.decay(80)]
for name, taps, lats in CASES:
    for A, B, C, N in lats:
        n = canvas(N); T = N  # the block repeats every N frames at most
        u = brute.lattice_block(A, B, C, N, n, T)
        for G in EYES:
            f = np.sqrt(st.J(A, B, C, N, taps, G)); b = np.sqrt(brute.rms(u, taps, G, levels=512))
            # brute force averages 512 levels, the formula integrates: the in-cell term 1/(12 N^2) differs by
            # O(1/levels^2); allow 3e-4
            print(f'{name:14s} ({A},{B},{C})/{N:<3d} {G.name:12s} formula {f:.5f}  brute force {b:.5f}  {"agree" if abs(f - b) < 3e-4 else "DISAGREE"}')
        W = st.shimmer_band(20)
        f = np.sqrt(st.Fl(A, B, C, N, taps, W)); b = np.sqrt(brute.rms(u, taps, None, levels=512, W=W))
        print(f'{name:14s} ({A},{B},{C})/{N:<3d} {"shimmer<20Hz":12s} formula {f:.5f}  brute force {b:.5f}  {"agree" if abs(f - b) < 3e-4 else "DISAGREE"}')
