Simplify limits on [minimum] layer/path number

Just a few calls to min() or max() do the trick, rather than if statements.
I consider this more semantic, because we just intend to clamp values here, and min() and max() are commonly used to do that.
It should also be slightly faster because it's less Python and more internal in CPython, but considering that this happens at best like 60 times per second the performance impact of this will be practically nil.
This commit is contained in:
Ghostkeeper 2021-03-06 14:15:48 +01:00
parent 3ef01ecbd8
commit e9d3ba9b74
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -249,52 +249,32 @@ class SimulationView(CuraView):
def setLayer(self, value: int) -> None:
if self._current_layer_num != value:
self._current_layer_num = value
if self._current_layer_num < 0:
self._current_layer_num = 0
if self._current_layer_num > self._max_layers:
self._current_layer_num = self._max_layers
if self._current_layer_num < self._minimum_layer_num:
self._minimum_layer_num = self._current_layer_num
self._current_layer_num = min(max(value, 0), self._max_layers)
self._minimum_layer_num = min(self._current_layer_num, self._minimum_layer_num)
self._startUpdateTopLayers()
self.currentLayerNumChanged.emit()
def setMinimumLayer(self, value: int) -> None:
if self._minimum_layer_num != value:
self._minimum_layer_num = value
if self._minimum_layer_num < 0:
self._minimum_layer_num = 0
if self._minimum_layer_num > self._max_layers:
self._minimum_layer_num = self._max_layers
if self._minimum_layer_num > self._current_layer_num:
self._current_layer_num = self._minimum_layer_num
self._minimum_layer_num = min(max(value, 0), self._max_layers)
self._current_layer_num = max(self._current_layer_num, self._minimum_layer_num)
self._startUpdateTopLayers()
self.currentLayerNumChanged.emit()
def setPath(self, value: int) -> None:
if self._current_path_num != value:
self._current_path_num = value
if self._current_path_num < 0:
self._current_path_num = 0
if self._current_path_num > self._max_paths:
self._current_path_num = self._max_paths
if self._current_path_num < self._minimum_path_num:
self._minimum_path_num = self._current_path_num
self._current_path_num = min(max(value, 0), self._max_paths)
self._minimum_path_num = min(self._minimum_path_num, self._current_path_num)
self._startUpdateTopLayers()
self.currentPathNumChanged.emit()
def setMinimumPath(self, value: int) -> None:
if self._minimum_path_num != value:
self._minimum_path_num = value
if self._minimum_path_num < 0:
self._minimum_path_num = 0
if self._minimum_path_num > self._max_paths:
self._minimum_path_num = self._max_paths
if self._minimum_path_num > self._current_path_num:
self._current_path_num = self._minimum_path_num
self._minimum_path_num = min(max(value, 0), self._max_paths)
self._current_path_num = max(self._current_path_num, self._minimum_path_num)
self._startUpdateTopLayers()
self.currentPathNumChanged.emit()