feat: Added new module-specific functions

+ Added exception handling inside python scripts
+ Changed some G2O functions to accept python objects as arguments
This commit is contained in:
AURUMVORXX
2025-03-30 16:30:54 +03:00
parent c093bd2f81
commit a00e601a14
12 changed files with 485 additions and 26 deletions

View File

@@ -1,7 +1,18 @@
import sqg2o
from g2o.exception import handle_exception
def getDistance2d(x1 : float, y1: float, x2 : float, y2 : float) -> float:
@handle_exception
def getDistance2d(
x1: float = 0,
y1: float = 0,
x2: float = 0,
y2 : float = 0,
first: dict[str, float] = None,
second: dict[str, float] = None
) -> float:
"""
!!! note
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
This function will get the 2d distance between two points.
Original: [getDistance2d](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/math/getDistance2d/)
@@ -15,13 +26,31 @@ def getDistance2d(x1 : float, y1: float, x2 : float, y2 : float) -> float:
* `float` **y1**: the position on Y axis of the first point.
* `float` **x2**: the position on X axis of the second point.
* `float` **y2**: the position on Y axis of the second point.
**OR**
* `dict[str, float]` **first**: the poistion on XY axis of the first point.
* `dict[str, float]` **second**: the position of XY axis of the second point.
## Returns
`float`: Returns the calculated 2d distance between two points as floating point number.
"""
return sqg2o.getDistance2d(x1, y1, x2, y2)
if first is not None and second is not None:
return sqg2o.getDistance2d(first['x'], first['y'], second['x'], second['y'])
else:
return sqg2o.getDistance2d(x1, y1, x2, y2)
def getDistance3d(x1 : float, y1: float, z1 : float, x2 : float, y2 : float, z2 : float) -> float:
@handle_exception
def getDistance3d(
x1 : float = 0,
y1: float = 0,
z1 : float = 0,
x2 : float = 0,
y2 : float = 0,
z2 : float = 0,
first: dict[str, float] = None,
second: dict[str, float] = None
) -> float:
"""
!!! note
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
This function will get the 3d distance between two points.
Original: [getDistance3d](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/math/getDistance3d/)
@@ -37,13 +66,29 @@ def getDistance3d(x1 : float, y1: float, z1 : float, x2 : float, y2 : float, z2
* `float` **x2**: the position on X axis of the second point.
* `float` **y2**: the position on Y axis of the second point.
* `float` **z2**: the position on Z axis of the second point.
**OR**
* `dict[str, float]` **first**: the position on XYZ axis of the first point.
* `dict[str, float]` **second**: the position on XYZ axic of the second point.
## Returns
`float`: Returns the calculated 3d distance between two points as floating point number.
"""
return sqg2o.getDistance3d(x1, y1, z1, x2, y2, z2)
if first is not None and second is not None:
return sqg2o.getDistance3d(first['x'], first['y'], first['z'], second['x'], second['y'], second['z'])
else:
return sqg2o.getDistance3d(x1, y1, z1, x2, y2, z2)
def getVectorAngle(x1 : float, y1: float, x2 : float, y2 : float) -> float:
@handle_exception
def getVectorAngle(
x1: float = 0,
y1: float = 0,
x2: float = 0,
y2 : float = 0,
first: dict[str, float] = None,
second: dict[str, float] = None
) -> float:
"""
!!! note
This functions supports ``pass_exception: bool`` optional argument for manual handling exceptions.
This function will get angle on Y axis directed towards the second point.
Original: [getVectorAngle](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/shared-functions/math/getVectorAngle/)
@@ -57,7 +102,13 @@ def getVectorAngle(x1 : float, y1: float, x2 : float, y2 : float) -> float:
* `float` **y1**: the position on Y axis of the first point.
* `float` **x2**: the position on X axis of the second point.
* `float` **y2**: the position on Y axis of the second point.
**OR**
* `dict[str, float]` **first**: the poistion on XY axis of the first point.
* `dict[str, float]` **second**: the position of XY axis of the second point.
## Returns
`float`: Returns the angle on Y axis directed towards the second point.
"""
return sqg2o.getVectorAngle(x1, y1, x2, y2)
if first is not None and second is not None:
return sqg2o.getVectorAngle(first['x'], first['y'], second['x'], second['y'])
else:
return sqg2o.getVectorAngle(x1, y1, x2, y2)