-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
48 lines (36 loc) · 1.01 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from math import sqrt
import os
import sys
def resource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller
Args:
relative_path (str): Relative path to resource
Returns:
str: Absolute path to resource
"""
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def dist(p1, p2):
"""Calculate distance between two points
Args:
p1 (tuple): Point 1
p2 (tuple): Point 2
Returns:
float: Distance between points
"""
dy = p1[0] - p2[0]
dx = p1[1] - p2[1]
return sqrt( dy*dy + dx*dx )
def midpoint(p1, p2):
"""Get midpoint coordinate between two points
Args:
p1 (tuple): Point 1
p2 (tuple): Point 2
Returns:
tuple: Midpoint coordinate
"""
return [int((p1[0] + p2[0])/2), int((p1[1] + p2[1])/2)]