IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
interval.py
Go to the documentation of this file.
1from typing import Union, Any
2
3from ids_peak_common import exceptions
4from ids_peak_common._internal.utils import is_equal, validate_parameter_types
5
6
7class Interval:
8 """!
9 @brief
10 Represents an interval with lower and upper boundaries.
11
12 @ingroup ids_peak_common_python_types
13 """
14
15 def __init__(self, minimum: Union[int, float], maximum: Union[int, float]):
16 """!
17 @brief
18 Creates an interval.
19
20 @param minimum: The lower boundary.
21 @param maximum: The upper boundary.
22
23 @exception OutOfRangeException: If maximum is less than minimum.
24 """
25 validate_parameter_types(minimum, maximum, accepted_types=(int, float))
26 if maximum < minimum:
28 "Maximum value has to be bigger than or equal to the minimum value"
29 )
30
31 self._minimum = minimum
32 self._maximum = maximum
33
34 def __eq__(self, other: Any) -> bool:
35 """!
36 @brief
37 Check if two intervals are equal.
38
39 @param other: Another Interval object OR List of boundaries [minimum, maximum] OR Tuple of boundaries (minimum, maximum)
40
41 @return True if intervals are equal, False otherwise
42 """
43 if isinstance(other, Interval):
44 return is_equal(self._minimum, other._minimum) and is_equal(self._maximum, other._maximum)
45 if isinstance(other, (list, tuple)):
46 if len(other) != 2:
47 return False
48 return is_equal(self._minimum, other[0]) and is_equal(self._maximum, other[1])
49 return False
50
51 def __ne__(self, other: Any) -> bool:
52 """!
53 @brief
54 Check if two intervals are not equal.
55
56 @param other: Another Interval object OR List of boundaries [minimum, maximum] OR Tuple of boundaries (minimum, maximum)
57
58 @return True if intervals are not equal, False otherwise
59 """
60 return not self.__eq__(other)
61
62 def _is_negative(self) -> bool:
63 return self._minimum < 0 or self._maximum < 0
64
65 @property
66 def minimum(self) -> Union[int, float]:
67 """!
68 @brief
69 Returns the lower boundary of the interval.
70 """
71 return self._minimum
72
73 @property
74 def maximum(self) -> Union[int, float]:
75 """!
76 @brief
77 Returns the upper boundary of the interval.
78 """
79 return self._maximum
80
81 def __str__(self) -> str:
82 """!
83 @brief
84 Returns a string representation of the Interval object.
85
86 @return String representation of the Interval object.
87 """
88 return f"(minimum={self.minimum}, maximum={self.maximum})"
89
90 def __repr__(self) -> str:
91 """!
92 @brief
93 Return an unambiguous string of the Interval object.
94 """
95 return f"{self.__class__.__name__}{str(self)}"
Represents an interval with lower and upper boundaries.
Definition interval.py:7
Union[int, float] maximum(self)
Returns the upper boundary of the interval.
Definition interval.py:74
Union[int, float] minimum(self)
Returns the lower boundary of the interval.
Definition interval.py:66
__init__(self, Union[int, float] minimum, Union[int, float] maximum)
Creates an interval.
Definition interval.py:15
bool __ne__(self, Any other)
Check if two intervals are not equal.
Definition interval.py:51
str __str__(self)
Returns a string representation of the Interval object.
Definition interval.py:81
str __repr__(self)
Return an unambiguous string of the Interval object.
Definition interval.py:90
bool __eq__(self, Any other)
Check if two intervals are equal.
Definition interval.py:34
Thrown when a parameter is outside the valid range.
Definition exceptions.py:79