|
| 1 | +Grid / Table Cell Addressing |
| 2 | +============================ |
| 3 | + |
| 4 | +``anchor_locator`` does pairwise spatial relations (target *near* / *below* an |
| 5 | +anchor) but nothing addresses a 2-D grid — "the cell at row 3, column 2" of a |
| 6 | +table. Given the bounding boxes of the cells (from an image or OCR enumeration, |
| 7 | +e.g. ``locate_all_image`` / ``find_text_matches``), this clusters them into rows |
| 8 | +and columns and returns the requested cell's centre. |
| 9 | + |
| 10 | +The clustering and lookup are pure (boxes in, grid / cell out) and fully |
| 11 | +unit-testable; the box enumeration stays the caller's job, so nothing here needs a |
| 12 | +real screen. Imports no ``PySide6``. |
| 13 | + |
| 14 | +Headless API |
| 15 | +------------ |
| 16 | + |
| 17 | +.. code-block:: python |
| 18 | +
|
| 19 | + from je_auto_control import cluster_grid, locate_cell |
| 20 | +
|
| 21 | + boxes = [(10, 100, 20, 10), (110, 100, 20, 10), (210, 100, 20, 10), |
| 22 | + (10, 200, 20, 10), (110, 200, 20, 10), (210, 200, 20, 10)] |
| 23 | +
|
| 24 | + locate_cell(boxes, row=1, col=2) |
| 25 | + # {'found': True, 'center': [220, 205], 'box': [210, 200, 20, 10], |
| 26 | + # 'row': 1, 'col': 2, 'rows': 2, 'cols': 3} |
| 27 | +
|
| 28 | + cluster_grid(boxes) # rows top-to-bottom, cells left-to-right |
| 29 | +
|
| 30 | +``cluster_grid`` sorts the boxes by centre-y, starts a new row when the gap |
| 31 | +exceeds ``row_tolerance``, and orders each row's cells by centre-x. |
| 32 | +``locate_cell`` returns the centre (ready to click) of the 0-based ``(row, col)`` |
| 33 | +cell, or ``{found: False, reason}`` when the index is out of range. |
| 34 | + |
| 35 | +Executor commands |
| 36 | +----------------- |
| 37 | + |
| 38 | +``AC_grid_cell`` takes ``boxes`` (a JSON ``[[x, y, w, h], ...]`` list, e.g. from a |
| 39 | +prior ``AC_locate_all_image`` step) plus ``row`` / ``col`` / ``row_tolerance`` and |
| 40 | +returns the cell dict. It is exposed as the MCP tool ``ac_grid_cell`` and as a |
| 41 | +Script Builder command under **Mouse**. |
0 commit comments