Clamp a measurement within the specified range. Args: min_width (int): Minimum desired width, or ``None`` for no minimum. Defaults to None. max_width (int): Maximum desired width, or ``None`` for no maximum. Defaults to None. Returns: Measurement
(
self, min_width: Optional[int] = None, max_width: Optional[int] = None
)
| 57 | return Measurement(max(minimum, width), max(maximum, width)) |
| 58 | |
| 59 | def clamp( |
| 60 | self, min_width: Optional[int] = None, max_width: Optional[int] = None |
| 61 | ) -> "Measurement": |
| 62 | """Clamp a measurement within the specified range. |
| 63 | |
| 64 | Args: |
| 65 | min_width (int): Minimum desired width, or ``None`` for no minimum. Defaults to None. |
| 66 | max_width (int): Maximum desired width, or ``None`` for no maximum. Defaults to None. |
| 67 | |
| 68 | Returns: |
| 69 | Measurement: New Measurement object. |
| 70 | """ |
| 71 | measurement = self |
| 72 | if min_width is not None: |
| 73 | measurement = measurement.with_minimum(min_width) |
| 74 | if max_width is not None: |
| 75 | measurement = measurement.with_maximum(max_width) |
| 76 | return measurement |
| 77 | |
| 78 | @classmethod |
| 79 | def get( |