feat: add gesture sequences and calibrated pixel drags
This commit is contained in:
1 parent
2a3bbaa3fb
commit
479a185192
31 files changed
+2440
-44
No files matched your search
@@ -417,8 +417,10 @@ def normalize_step_actions(step_dict: dict[str, Any]) -> dict[str, Any]:
|
||||
act_name = str(item.get("action") or item.get("name") or "").lower()
|
||||
|
||||
if (
|
||||
"swipe" in act_name or "scroll" in act_name or "drag" in act_name
|
||||
) and "normalized_coordinates" not in item:
|
||||
("swipe" in act_name or "scroll" in act_name or "drag" in act_name)
|
||||
and "normalized_coordinates" not in item
|
||||
and item.get("coordinate_space") != "pixel"
|
||||
):
|
||||
kind, target, _ = parse_swipe_parameters(item)
|
||||
if kind == "coords" and isinstance(target, list) and len(target) == 4:
|
||||
item["normalized_coordinates"] = target
|
||||
@@ -445,22 +447,32 @@ def normalize_step_actions(step_dict: dict[str, Any]) -> dict[str, Any]:
|
||||
coords = item.get("coordinates")
|
||||
if coords and isinstance(coords, list) and "normalized_coordinates" not in item:
|
||||
# If coordinates look physical (e.g., target_bounds present or > 1000), normalize using width/height
|
||||
if item.get("target_bounds") or any(
|
||||
isinstance(c, (int, float)) and c > 1000 for c in coords
|
||||
if (
|
||||
item.get("coordinate_space") == "pixel"
|
||||
or item.get("target_bounds")
|
||||
or any(isinstance(c, (int, float)) and c > 1000 for c in coords)
|
||||
):
|
||||
size = item.get("screen_size")
|
||||
if not (
|
||||
isinstance(size, (list, tuple))
|
||||
and len(size) == 2
|
||||
and all(isinstance(v, (int, float)) and v > 0 for v in size)
|
||||
):
|
||||
size = [width, height]
|
||||
item_width, item_height = size
|
||||
if len(coords) == 2 and all(isinstance(c, (int, float)) for c in coords):
|
||||
item["normalized_coordinates"] = [
|
||||
int(round(coords[0] * 1000.0 / width)),
|
||||
int(round(coords[1] * 1000.0 / height)),
|
||||
int(round(coords[0] * 1000.0 / item_width)),
|
||||
int(round(coords[1] * 1000.0 / item_height)),
|
||||
]
|
||||
elif len(coords) == 4 and all(isinstance(c, (int, float)) for c in coords):
|
||||
nx1, ny1 = (
|
||||
int(round(coords[0] * 1000.0 / width)),
|
||||
int(round(coords[1] * 1000.0 / height)),
|
||||
int(round(coords[0] * 1000.0 / item_width)),
|
||||
int(round(coords[1] * 1000.0 / item_height)),
|
||||
)
|
||||
nx2, ny2 = (
|
||||
int(round(coords[2] * 1000.0 / width)),
|
||||
int(round(coords[3] * 1000.0 / height)),
|
||||
int(round(coords[2] * 1000.0 / item_width)),
|
||||
int(round(coords[3] * 1000.0 / item_height)),
|
||||
)
|
||||
item["normalized_coordinates"] = [nx1, ny1, nx2, ny2]
|
||||
item["normalized_start_coordinates"] = [nx1, ny1]
|
||||
|
||||
Reference in new issue
Block a user