utils.py 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # main imports
  2. import sys, math
  3. # modules imports
  4. sys.path.insert(0, '') # trick to enable import of main folder module
  5. import custom_config as cfg
  6. min_x = 100
  7. min_y = 100
  8. # utils variables
  9. zone_width, zone_height = cfg.image_zone_size
  10. scene_width, scene_height = cfg.image_scene_size
  11. nb_x_parts = math.floor(scene_width / zone_width)
  12. def get_zone_index(p_x, p_y):
  13. zone_index = math.floor(p_x / zone_width) + math.floor(p_y / zone_height) * nb_x_parts
  14. return zone_index
  15. def check_coordinates(p_x, p_y):
  16. if p_x < min_x or p_y < min_y:
  17. return False
  18. if p_x >= min_x + scene_width or p_y >= min_y + scene_height:
  19. return False
  20. return True
  21. def extract_click_coordinate(line):
  22. data = line.split(' : ')[1].split(',')
  23. p_x, p_y = (int(data[0]), int(data[1]))
  24. return (p_x, p_y)