-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosition.py
More file actions
71 lines (57 loc) · 1.88 KB
/
Copy pathPosition.py
File metadata and controls
71 lines (57 loc) · 1.88 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from dataclasses import dataclass
# Position Struct
from typing import Tuple
@dataclass
class Position:
"""
A class representing a position in 3D space.
Attributes:
-----------
x : float
The x-coordinate of the position.
y : float
The y-coordinate of the position.
theta : float
The angle of the position in radians.
Methods:
--------
__repr__() -> str
Returns a string representation of the position in the format
"x,y,theta".
to_tuple() -> Tuple
Returns a tuple representation of the position in the format
(x, y, theta).
"""
x: float
y: float
theta: float
def __repr__(self) -> str:
return f"({self.x},{self.y},{self.theta})"
def to_tuple(self) -> Tuple:
"""
Returns a tuple representation of the Position object.
Returns:
Tuple: A tuple containing the x, y, and theta values of the Position
object.
"""
return (self.x, self.y, self.theta)
def __hash__(self) -> int:
"""
Returns a unique hash value for the Position object based on its x and
y coordinates.
Returns:
int: A unique hash value for the Position object.
"""
return hash((self.x, self.y))
def __eq__(self, other) -> bool:
return int(0.5 + self.x) == int(0.5 + other.x) and int(0.5 + self.y) == int(0.5 + other.y)
def location(self) -> Tuple[int, int]:
"""
Returns a tuple representation of the location of the Position object.
Returns:
Tuple: A tuple containing the x and y values of the Position
object.
"""
assert isinstance(self.x, float) or isinstance(self.x, int), f"{self} is weird"
assert isinstance(self.y, float) or isinstance(self.y, int), f"{self} is weird"
return (int(self.x + 0.5), int(self.y + 0.5))