Skip to content

Commit

Permalink
fixed guidance arrow bug resulting from nan positions, see dicelab-rh…
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedictWilkins committed Aug 13, 2024
1 parent 3f8ce71 commit d7a1329
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions icua/agent/actuator_guidance.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Module containing the abstract base class `GuidanceActuator` and some concrete implementations: `ArrowGuidanceActuator` and `BoxGuidanceActuator` both provide convenient attempt methods for display visual guidance to a user."""

from math import isfinite
from abc import abstractmethod
from typing import Literal, Any
from star_ray.agent import Actuator, attempt
from star_ray.agent import Agent, Actuator, attempt
from star_ray.event import Action
from icua.event import MouseMotionEvent, EyeMotionEvent
from star_ray.agent.agent import Agent

from ..event.event_guidance import (
from ..utils import LOGGER
from ..event import (
MouseMotionEvent, EyeMotionEvent,
DrawArrowAction,
DrawBoxOnElementAction,
ShowElementAction,
Expand Down Expand Up @@ -191,14 +191,17 @@ def __attempt__(self): # noqa
if self._guidance_on is None:
return []
elif self._arrow_mode == "gaze":
if self._gaze_position: # TODO check that this doesnt continuously hold...?
# eyetracking positions can be nan, dont update the position if they are?
if isfinite(self._gaze_position[0]) and isfinite(self._gaze_position[1]):
attrs = dict(
id=self._guidance_arrow_id,
x=self._gaze_position[0] + self._arrow_offset[0],
y=self._gaze_position[1] + self._arrow_offset[0],
point_to=self._guidance_on,
)
return [DrawArrowAction(xpath="/svg:svg", data=attrs)]
else:
LOGGER.warning("Ignoring NaN arrow position.")
return []
elif self._arrow_mode == "mouse":
if self._mouse_position:
Expand Down
2 changes: 1 addition & 1 deletion icua/event/event_guidance.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def get_element_center(state: XMLState, xpath: str):
if not result:
raise ValueError(f"Element at xpath: {xpath} doesn't exist")
values = result[0]
x, y = (values["x"], values["y"])
x, y = (float(values["x"]), float(values["y"]))
scale, _, _ = parse_transform(values["transform"])
width, height = (values["width"] * scale[0], values["height"] * scale[1])
return x + width / 2, y + height / 2
Expand Down

0 comments on commit d7a1329

Please sign in to comment.