IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
point.py
Go to the documentation of this file.
1from typing import Union, Any
2
3from ids_peak_common._internal.utils import is_equal, validate_parameter_types
4
5
6class Point:
7 """!
8 @brief
9 Represents a point in 2D space with x and y coordinates.
10
11 @ingroup ids_peak_common_python_types_geometry
12 """
13
14 def __init__(self, x: Union[int, float], y: Union[int, float]):
15 """!
16 @brief
17 Initializes a Point instance.
18
19 @param x: x coordinate
20 @param y: y coordinate
21 """
22 validate_parameter_types(x, y, accepted_types=(int, float))
23 self._x: Union[int, float] = x
24 self._y: Union[int, float] = y
25
26 def __eq__(self, other: Any) -> bool:
27 """!
28 @brief
29 Determines if this point is equal to another point or coordinate pair.
30
31 @param other: Another Point object OR List of coordinates [x,y] OR Tuple of coordinates (x,y)
32
33 @return True if points are equal, False otherwise
34 """
35 if isinstance(other, Point):
36 return is_equal(self.xx, other.x) and is_equal(self.yy, other.y)
37 if isinstance(other, (list, tuple)):
38 if len(other) != 2:
39 return False
40 return is_equal(self.xx, other[0]) and is_equal(self.yy, other[1])
41 return False
42
43 def __ne__(self, other: Any) -> bool:
44 """!
45 @brief
46 Determines if this point is not equal to another point or coordinate pair.
47
48 @param other: Another Point instance, or a list/tuple with two numeric elements [x, y] or (x, y).
49
50 @return True if points are not equal, False otherwise
51 """
52 return not self.__eq__(other)
53
54 def __str__(self) -> str:
55 """!
56 @brief
57 Returns a string representation of the Point.
58
59 A string in the format "(x: <x_value>, y: <y_value>)".
60 """
61 return f"(x={self.x}, y={self.y})"
62
63 def __repr__(self) -> str:
64 """!
65 @brief
66 Return an unambiguous string of the Point object.
67 """
68 return f"{self.__class__.__name__}{str(self)}"
69
70 @property
71 def x(self) -> Union[int, float]:
72 return self._x
73
74 @property
75 def y(self) -> Union[int, float]:
76 return self._y
77
78
79Vector = Point
Represents a point in 2D space with x and y coordinates.
Definition point.py:6
__init__(self, Union[int, float] x, Union[int, float] y)
Initializes a Point instance.
Definition point.py:14
bool __ne__(self, Any other)
Determines if this point is not equal to another point or coordinate pair.
Definition point.py:43
str __str__(self)
Returns a string representation of the Point.
Definition point.py:54
str __repr__(self)
Return an unambiguous string of the Point object.
Definition point.py:63
bool __eq__(self, Any other)
Determines if this point is equal to another point or coordinate pair.
Definition point.py:26