main
Colby Knox AI Flow 0.2.62: fixes #190 #191 #188 #189 #186 #187 and the #177 remote-model remainder 01b74f9
"""Issue #188, offline: the reading axis of a two-line, near-square mark ("BMI" over "270") comes from the glyphs'
own shape (taller than wide), not from the spread of their centres, which a 3 x 2 grid cannot settle.
Run: python3 -m unittest -v test_reading_axis   (from tools/laser-etch)"""
import os, sys, unittest

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import mark_geom as MG


def glyph(cx, cy, w, h):
    return dict(bbox=[cx - w / 2, cy - h / 2, 0, cx + w / 2, cy + h / 2, 0.01], c=[cx, cy, 0.005])


def bbox(faces):
    return [min(f["bbox"][0] for f in faces), min(f["bbox"][1] for f in faces), 0, max(f["bbox"][3] for f in faces), max(f["bbox"][4] for f in faces), 0.01]


def grid(along):
    """Two lines of three glyphs, 0.5 wide and 0.77 tall, 0.6 pitch, lines 1.0 apart (the spread across the lines just beats the spread along them), reading along x or y."""
    out = []
    for row, off in ((0, 0.5), (1, -0.5)):
        for i in range(3):
            u = -0.6 + 0.6 * i
            out.append(glyph(u, off, 0.5, 0.77) if along == "x" else glyph(off, u, 0.77, 0.5))
    return out


class ReadingAxis(unittest.TestCase):
    def test_a_near_square_two_line_mark_reads_along_its_lines(self):
        for along in ("x", "y"):
            f = grid(along)
            self.assertEqual(MG.reading_axis(f, bbox(f)), along)

    def test_a_long_single_line_keeps_the_spread(self):
        f = [glyph(-1.2 + 0.6 * i, 0, 0.5, 0.77) for i in range(5)]
        self.assertEqual(MG.reading_axis(f, bbox(f)), "x")


if __name__ == "__main__":
    unittest.main()