IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
size.py
Go to the documentation of this file.
1from __future__ import annotations
2
3from typing import Union, Any
4
5from ids_peak_common import exceptions
6from ids_peak_common._internal.utils import is_equal, validate_parameter_types
7
8
9class Size:
10 """!
11 @brief
12 A size consists of width and height where width and height have to be greater than or equal to zero.
13
14 @ingroup ids_peak_common_python_types_geometry
15 """
16
17 def __init__(self, width: Union[int, float], height: Union[int, float]):
18 """!
19 @brief
20 Size constructor from width and height.
21
22 @param width: Width of the size.
23 @param height: Height of the size.
24
25 @exception OutOfRangeException: If width or height is less than zero.
26 """
27 validate_parameter_types(width, height, accepted_types=(int, float))
28 if width < 0:
29 raise exceptions.OutOfRangeException("Parameter width has to be greater or equal to zero.")
30 if height < 0:
31 raise exceptions.OutOfRangeException("Parameter height has to be greater or equal to zero.")
32
33 self._width = width
34 self._height = height
35
36 def __eq__(self, other: Any) -> bool:
37 """!
38 @brief
39 Check if two Size objects are equal.
40
41 @param other: Another Size object OR List of width and height [width, height] OR Tuple of width and height (width, height)
42
43 @return True if both objects are equal, False otherwise.
44 """
45 if isinstance(other, Size):
46 return is_equal(self.widthwidth, other.width) and is_equal(self.heightheight, other.height)
47 if isinstance(other, (list, tuple)):
48 if len(other) != 2:
49 return False
50 return is_equal(self.widthwidth, other[0]) and is_equal(self.heightheight, other[1])
51
52 return False
53
54 def __ne__(self, other: Any) -> bool:
55 """!
56 @brief
57 Check if two Size objects are not equal.
58
59 @param other: Another Size object OR List/Tuple with width and height.
60
61 @return True if both objects are not equal, False otherwise.
62 """
63 return not self == other
64
65 def __str__(self) -> str:
66 """!
67 @brief
68 Returns a string representation of the Size object.
69
70 @return String representation of the Size object.
71 """
72 return f"(width={self.width}, height={self.height})"
73
74 def __repr__(self) -> str:
75 """!
76 @brief
77 Return an unambiguous string of the Size object.
78 """
79 return f"{self.__class__.__name__}{str(self)}"
80
81 @property
82 def width(self) -> Union[int, float]:
83 """!
84 @brief
85 Get the width of the size.
86
87 @return The width value.
88 """
89 return self._width
90
91 @property
92 def height(self) -> Union[int, float]:
93 """!
94 @brief
95 Get the height of the size.
96
97 @return The height value.
98 """
99 return self._height
100
101 def transposed(self) -> Size:
102 return Size(self.heightheight, self.widthwidth)
A size consists of width and height where width and height have to be greater than or equal to zero.
Definition size.py:9
__init__(self, Union[int, float] width, Union[int, float] height)
Size constructor from width and height.
Definition size.py:17
Union[int, float] height(self)
Get the height of the size.
Definition size.py:92
bool __ne__(self, Any other)
Check if two Size objects are not equal.
Definition size.py:54
Union[int, float] width(self)
Get the width of the size.
Definition size.py:82
str __str__(self)
Returns a string representation of the Size object.
Definition size.py:65
str __repr__(self)
Return an unambiguous string of the Size object.
Definition size.py:74
bool __eq__(self, Any other)
Check if two Size objects are equal.
Definition size.py:36
Thrown when a parameter is outside the valid range.
Definition exceptions.py:79