Skip to content

Tag: Clamp

Clamping numbers in Swift

Clamping a value is an operation of moving the value to a range of allowed values. It can be achieved by comparing the value with allowed minimum and maximum values. For example I was deforming SKWarpGeometryGrid from the direction of a point outside the grid and needed to constrain angles between grid points and the contact point. Maximum and minimum allowed angles were related to the angle between the contact point and the grid’s center point. The solution I propose extends FloatingPoint and BinaryInteger protocols and gives a very readable… Read more Clamping numbers in Swift