def clamp(self, size): """ Returns a new point enforced to be in the rectangle between the origin and the point ``size``. """ sx, sy = size return Point(clamp(self._x, 0, sx), clamp(self._y, 0, sy))
def test_clamp_below(self): """ Test for clamp when the value is below the minimum value """ assert mathutil.clamp(-5, 0, 10) == 0
def test_clamp_above(self): """ Test for clamp when the value is above the maximum value """ assert mathutil.clamp(15, 0, 10) == 10
def test_clamp_wrong_range(self): """ Test for clamp when the maximum value is less than the minimum """ with pytest.raises(ValueError): mathutil.clamp(5, 10, 0)
def test_clamp_between(self): """ Test for clamp when the value is between the maximum and minimum values """ assert mathutil.clamp(5, 0, 10) == 5