IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
range.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
4from ids_peak_common.datatypes.interval import Interval
5from ids_peak_common.exceptions import InvalidParameterException
6
7
9 """!
10 @brief
11 Represents a numeric range with defined boundaries and a fixed increment.
12
13 A Range models a continuous sequence of values starting from a minimum value,
14 ending at a maximum value, and progressing in steps defined by an increment.
15 It supports integers and floating-point numbers.
16
17 This class ensures that the increment does not exceed the total span between
18 the minimum and maximum bounds. The range is inclusive of its boundary values.
19 """
20
21 def __init__(self, minimum: Union[int, float], maximum: Union[int, float], increment: Union[int, float]):
22 """!
23 @brief
24 Creates a range with specified minimum, maximum, and increment values.
25
26 @exception InvalidParameterException: If minimum is greater than maximum,
27 or if increment exceeds the total range span.
28
29 @param minimum: The inclusive starting (lower) boundary of the range.
30 @param maximum: The inclusive ending (upper) boundary of the range.
31 @param increment: The step size or increment between values within the range.
32 """
33 super().__init__(minimum, maximum)
34
35 validate_parameter_types(minimum, maximum, increment, accepted_types=(int, float))
36
37 if increment > self.maximum - self.minimumminimum:
38 raise InvalidParameterException("The given increment is larger than the total range!")
39 self._increment = increment
40
41 def __eq__(self, other: Any) -> bool:
42 if isinstance(other, Range):
43 return super().__eq__(other) and is_equal(other.increment, self.incrementincrement)
44 if isinstance(other, list) or isinstance(other, tuple):
45 if len(other) != 3:
46 return False
47 return super().__eq__((other[0], other[1])) and is_equal(self._increment, other[2])
48 else:
49 return False
50
51 @property
52 def increment(self) -> Union[int, float]:
53 """!
54 @brief
55 Retrieves the increment value associated with this range.
56 """
57 return self._increment
58
59 def __str__(self) -> str:
60 """!
61 @brief
62 Returns a string representation of the Range object.
63
64 @return String representation of the Range object.
65 """
66 return f"(minimum={self.minimum}, maximum={self.maximum}, increment={self.increment})"
67
68 def __repr__(self) -> str:
69 """!
70 @brief
71 Return an unambiguous string of the Range object.
72 """
73 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
Represents a numeric range with defined boundaries and a fixed increment.
Definition range.py:8
__init__(self, Union[int, float] minimum, Union[int, float] maximum, Union[int, float] increment)
Creates a range with specified minimum, maximum, and increment values.
Definition range.py:21
str __str__(self)
Returns a string representation of the Range object.
Definition range.py:59
str __repr__(self)
Return an unambiguous string of the Range object.
Definition range.py:68
bool __eq__(self, Any other)
Check if two intervals are equal.
Definition range.py:41
Union[int, float] increment(self)
Retrieves the increment value associated with this range.
Definition range.py:52
Thrown when a function receives an invalid parameter.
Definition exceptions.py:13