Skip to content

Commit

Permalink
Merge pull request #211 from ssciwr/missing_cursor_vertex
Browse files Browse the repository at this point in the history
Refactor cursor path, fixes gap between to_target and to_center curso…
  • Loading branch information
lkeegan authored Jun 7, 2023
2 parents 344cee0 + c7a79a2 commit a8ffb0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/vstt/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Iterable
from typing import List
from typing import Optional
from typing import Tuple
from typing import Union

import numpy as np
Expand Down Expand Up @@ -87,16 +88,21 @@ def __init__(self, win: Window, trial: Dict[str, Any], rng: np.random.Generator)
self.joystick_point_updater = JoystickPointUpdater(
trial["cursor_rotation_degrees"], trial["joystick_max_speed"], win.size
)
self.cursor_path = ShapeStim(
win, vertices=[(0, 0)], lineColor="white", closeShape=False
)
self.prev_cursor_path = ShapeStim(
win, vertices=[(0, 0)], lineColor="white", closeShape=False
self._cursor_path = ShapeStim(
win, vertices=[(0.0, 0.0)], lineColor="white", closeShape=False
)
self._cursor_path_vertices: List[Tuple[float, float]] = []
self.clock = Clock()
if trial["show_cursor_path"]:
self.drawables.append(self.cursor_path)
self.drawables.append(self.prev_cursor_path)
self.drawables.append(self._cursor_path)

def cursor_path_add_vertex(
self, vertex: Tuple[float, float], clear_existing: bool = False
) -> None:
if clear_existing:
self._cursor_path_vertices = []
self._cursor_path_vertices.append(vertex)
self._cursor_path.vertices = self._cursor_path_vertices


def _contains_mixed_length_numpy_arrays(items: Iterable) -> bool:
Expand Down Expand Up @@ -228,16 +234,12 @@ def _do_target(self, trial: Dict[str, Any], index: int, tm: TrialManager) -> Non
is_central_target = target_index == trial["num_targets"]
mouse_times = []
mouse_positions = []
if is_central_target:
tm.prev_cursor_path.vertices = tm.cursor_path.vertices
tm.cursor_path.vertices = [tm.cursor_path.vertices[-1]]
else:
if not is_central_target:
if trial["automove_cursor_to_center"]:
mouse_pos = np.array([0.0, 0.0])
self.mouse.setPos(mouse_pos)
tm.cursor.setPos(mouse_pos)
tm.cursor_path.vertices = [mouse_pos]
tm.prev_cursor_path.vertices = [(0, 0)]
tm.cursor_path_add_vertex(mouse_pos, clear_existing=True)
if not trial["fixed_target_intervals"]:
stop_waiting_time = t0 + trial["inter_target_duration"]
if stop_waiting_time > t0:
Expand Down Expand Up @@ -267,7 +269,7 @@ def _do_target(self, trial: Dict[str, Any], index: int, tm: TrialManager) -> Non
if trial["show_cursor"]:
tm.cursor.setPos(mouse_pos)
if trial["show_cursor_path"]:
tm.cursor_path.vertices = mouse_positions
tm.cursor_path_add_vertex(mouse_pos)
should_continue_waiting = (
tm.clock.getTime() + minimum_window_for_flip
< stop_waiting_time
Expand Down Expand Up @@ -309,7 +311,7 @@ def _do_target(self, trial: Dict[str, Any], index: int, tm: TrialManager) -> Non
mouse_times.append(tm.clock.getTime())
mouse_positions.append(mouse_pos)
if trial["show_cursor_path"]:
tm.cursor_path.vertices = mouse_positions
tm.cursor_path_add_vertex(mouse_pos)
dist_correct, dist_any = to_target_dists(
mouse_pos,
tm.targets.xys,
Expand Down
1 change: 1 addition & 0 deletions src/vstt/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def _make_stats_drawables(
# paths to center
if (
display_options["to_center_paths"]
and conditions["add_central_target"]
and not conditions["automove_cursor_to_center"]
):
for _, row in stats_df.iterrows():
Expand Down

0 comments on commit a8ffb0d

Please sign in to comment.