-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoreFuncs.py
40 lines (23 loc) · 962 Bytes
/
CoreFuncs.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
import json
# ---------------------------------------- Data Loading/Parsing ----------------------------------------
# for managing json files
class Json:
# reads/opens a json file
def LoadFile(file: str) -> dict:
return json.load(open(file))
# writes to a json file
def WriteFile(file: str, info: dict) -> None:
jsonObj = json.dumps(info, indent=4) # getting the object form of the dict
# Writing to the file
with open(file, "w") as out:
out.write(jsonObj)
# ---------------------------------------- Math Functions ----------------------------------------
# checks if a value is in a range of values
def Range(v: int, l: int, r: int) -> bool:
return v >= l and v <= r
# linear interpalation
def Lerp(l: int, r: int, m: int) -> float:
return l * (1 - m) + r * m
# clamps a value between two bounds
def Clamp(v: float, l: float, r: float) -> int:
return min(max(v, l), r)