Math

The math module provides a few simple functions that provide common but important operations:

marsutils.math.signed_square(value)[source]

A tiny function that returns the square of value but with the same sign.

>>> signed_square(-2)
-4
>>> signed_square(2)
2
marsutils.math.two_way_clamp(lower, upper, value)[source]

A function that accepts a lower and upper bound and a value and will return the value if it is between the bounds, or it will return the clamped value.

>>> two_way_clamp(100, 500, 250)
250
>>> two_way_clamp(100, 500, -40)
100
>>> two_way_clamp(-100, -500, 0)
-100