utils module

TrajTracker - movement package - public utilities

@author: Dror Dotan @copyright: Copyright (c) 2017, Dror Dotan

This file is part of TrajTracker.

TrajTracker is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

TrajTracker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with TrajTracker. If not, see <http://www.gnu.org/licenses/>.

trajtracker.utils.get_angle(xy1, xy2, as_degrees=False)

Get the direction of finger movement, in radians. 0 = upwards.

Parameters:
  • xy1 – Coordinates in time point #1
  • xy2 – Coordinates in a later time point
  • as_degrees (bool) – Whether the angle should be returned as degrees or radians
trajtracker.utils.color_rgb_to_num(rgb)

Convert an RGB color (3 integers, each 0-255) to a single int value (between 0 and 0xFFFFFF)

trajtracker.utils.color_num_to_rgb(value)

Convert an int value (between 0 and 0xFFFFFF) to RGB color (3 integers, each 0-255)

trajtracker.utils.is_rgb(rgb)

Check if the given value is a valid RGB color (3 integers, each 0-255)

trajtracker.utils.is_coord(value, allow_float=False)

Check whether the given value is valid as (x,y) coordinates :param allow_float:

trajtracker.utils.rotate_coord(coord, angle, origin=(0, 0), is_radians=False)

Rotate the given coordinate about the origin

Parameters:
  • coord – The x,y coordinate to rotate
  • angle – The rotation angle (positive = clockwise)
  • origin – The point to rotate around (default=0,0)
  • is_radians – whether angle is provided as radians (True) or degrees (False)
Returns:

The new x,y coordinates

trajtracker.utils.get_time()

Get the current time (in seconds). This is a wrapper to Expyriment’s get_time function :return: float

trajtracker.utils.get_font_height_to_size_ratio(font_name)

Find the ratio between a font size and the corresponding textbox height in pixels. The returned ratio is height/size

trajtracker.utils.round(x)

Round deicmal numbers to the nearest integer. This is different from Python’s numpy.round() in two ways:

  • Python rounds halves to the nearest even number (2.5 rounds to 2, and 3.5 rounds to 4). This method rounds halves to the higher integer, as done in most programming languages: round(2.5) == 3, round(3.5) == 4, round(-2.5) == -3
  • Python’s round() method returns a float, this method returns an int