Module mathutil

Various mathematical functions.

Functions

cantor_pairing (a, b) Uses the Cantor Pairing function on the two given values and returns a unique integer for the given numbers.
clamp (value, min, max) Clamps one value to the given minimum/maximum values.
distance (a, b) Gets the distance between the two given points or objects.
direction (source_pos, target_pos) Returns a vector indicating the general direction from a to b.
distance2d (a, b) Gets the distance between two given points in the x/z plane.
in_range (value, min, max) Tests if the given value is within the given range.
intersects (min_a, max_a, min_b, max_b) Checks if the given first two values intersect with the other given values.
intersects3d (min_a, max_a, min_b, max_b) Checks if the given first two positions intersect with the other given positions.
next_lower_prime (number) Gets the next lower prime from the given number.
round (value, decimal_places) Rounds to the nearest number with the given decimal places.
sign (number) Gets the sign of the given number.

Fields

SIGNED_8BIT_MAX The maximum value a signed 8bit integer can have.
SIGNED_8BIT_MIN The minimum value a signed 8bit integer can have.
SIGNED_16BIT_MAX The maximum value a signed 16bit integer can have.
SIGNED_16BIT_MIN The minimum value a signed 16bit integer can have.
SIGNED_32BIT_MAX The maximum value a signed 32bit integer can have.
SIGNED_32BIT_MIN The minimum value a signed 32bit integer can have.
UNSIGNED_8BIT_MAX The maximum value an unsigned 8bit integer can have.
UNSIGNED_8BIT_MIN The minimum value an unsigned 8bit integer can have.
UNSIGNED_16BIT_MAX The maximum value an unsigned 16bit integer can have.
UNSIGNED_16BIT_MIN The minimum value an unsigned 16bit integer can have.
UNSIGNED_32BIT_MAX The maximum value an unsigned 32bit integer can have.
UNSIGNED_32BIT_MIN The minimum value an unsigned 32bit integer can have.


Functions

cantor_pairing (a, b)
Uses the Cantor Pairing function on the two given values and returns a unique integer for the given numbers.

Parameters:

  • a The first value.
  • b The second value.

Returns:

    A unique value for the two given values.
clamp (value, min, max)
Clamps one value to the given minimum/maximum values. Defaults to 0 to 1 if min/max are omitted.

Parameters:

  • value The value to clamp.
  • min Optional. The minimum value, defaults to 0.
  • max Optional. The masximum value, defaults to 1.

Returns:

    The value clamped to the given range.
distance (a, b)
Gets the distance between the two given points or objects.

Parameters:

  • a The first object. Either a position or an ObjectRef.
  • b The second object. Either a position or an ObjectRef.

Returns:

    The distance between the two given points or objects.
direction (source_pos, target_pos)
Returns a vector indicating the general direction from a to b.

Parameters:

  • source_pos The source point, a vector.
  • target_pos The target point, a vector.

Returns:

    The vector containing the direction, either 1 for the positive direction or -1 for the negative one.
distance2d (a, b)
Gets the distance between two given points in the x/z plane.

Parameters:

  • a The first object. Either a position or an ObjectRef.
  • b The first object. Either a position or an ObjectRef.

Returns:

    The distance between the two given points or objects in the x/z plane.
in_range (value, min, max)
Tests if the given value is within the given range.

Parameters:

  • value The value to test.
  • min The minimum value. It can also be a table with either two values, the first being the minimum and the second being the maximum, or with two named values, min and max.
  • max The maximum value. Not used if min is a table.
intersects (min_a, max_a, min_b, max_b)
Checks if the given first two values intersect with the other given values.

Parameters:

  • min_a The first minimum value.
  • max_a The first maximum value.
  • min_b The second minimum value.
  • max_b The second maximum value.

Returns:

    true if the first values intersect with the second.
intersects3d (min_a, max_a, min_b, max_b)
Checks if the given first two positions intersect with the other given positions.

Parameters:

  • min_a The first minimum value.
  • max_a The first maximum value.
  • min_b The second minimum value.
  • max_b The second maximum value.

Returns:

    true if the first positions intersect with the second.
next_lower_prime (number)
Gets the next lower prime from the given number.

Parameters:

  • number The number.

Returns:

    The next lower prime.
round (value, decimal_places)
Rounds to the nearest number with the given decimal places.

Parameters:

  • value The value to round.
  • decimal_places Optional. The number of decimal places to round to, defaults to 0.

Returns:

    The rounded value.
sign (number)
Gets the sign of the given number.

Parameters:

  • number The number of which to get the sign.

Returns:

    1 for a positive number, -1 for a negative one. Zero is considered a positive number for this function, there for returns 1.

Fields

SIGNED_8BIT_MAX
The maximum value a signed 8bit integer can have.
SIGNED_8BIT_MIN
The minimum value a signed 8bit integer can have.
SIGNED_16BIT_MAX
The maximum value a signed 16bit integer can have.
SIGNED_16BIT_MIN
The minimum value a signed 16bit integer can have.
SIGNED_32BIT_MAX
The maximum value a signed 32bit integer can have.
SIGNED_32BIT_MIN
The minimum value a signed 32bit integer can have.
UNSIGNED_8BIT_MAX
The maximum value an unsigned 8bit integer can have.
UNSIGNED_8BIT_MIN
The minimum value an unsigned 8bit integer can have.
UNSIGNED_16BIT_MAX
The maximum value an unsigned 16bit integer can have.
UNSIGNED_16BIT_MIN
The minimum value an unsigned 16bit integer can have.
UNSIGNED_32BIT_MAX
The maximum value an unsigned 32bit integer can have.
UNSIGNED_32BIT_MIN
The minimum value an unsigned 32bit integer can have.
generated by LDoc 1.4.2