Small World Engine API Reference - v0.76.20
    Preparing search index...

    Class MathUtils

    Utility class for mathematical operations and constants.

    Index
    DEG2RAD: number = ...

    Constant to convert degrees to radians.

    HALF_PI: number = ...

    Mathematical constant PI / 2.

    PI: number = Math.PI

    Mathematical constant PI.

    QUARTER_PI: number = ...

    Mathematical constant PI / 4.

    RAD2DEG: number = ...

    Constant to convert radians to degrees.

    TWO_PI: number = ...

    Mathematical constant 2 * PI.

    • Reads an element from a fixed-size array whose bounds are guaranteed correct by construction (e.g. Float32Array components of a Matrix4/ Quaternion, or a small fixed axis list) — centralizes the noUncheckedIndexedAccess trust boundary in one place instead of a raw non-null assertion at every call site.

      Type Parameters

      • T

      Parameters

      • arr: ArrayLike<T>

        The array-like to read from.

      • index: number

        The index to read.

      Returns T

      The element at the given index.

    • Clamps a value between a minimum and maximum.

      Parameters

      • val: number

        The value to clamp.

      • min: number

        The minimum value.

      • max: number

        The maximum value.

      Returns number

      The clamped value.

    • Converts degrees to radians.

      Parameters

      • degrees: number

        The angle in degrees.

      Returns number

      The angle in radians.

    • Returns the cosine of the given angle in radians using a lookup table.

      Parameters

      • rad: number

        The angle in radians.

      Returns number

      The cosine of the angle.

    • Returns the sine of the given angle in radians using a lookup table.

      Parameters

      • rad: number

        The angle in radians.

      Returns number

      The sine of the angle.

    • Generates a unique identifier (UUID v4). Uses crypto.randomUUID() if available.

      Returns string

      A string representation of a UUID.

    • Initializes the sine and cosine lookup tables for fast lookup.

      Returns void

    • Linearly interpolates between two numbers by a factor t.

      Parameters

      • a: number

        The start value (returned when t = 0).

      • b: number

        The end value (returned when t = 1).

      • t: number

        The interpolation factor, typically in [0, 1].

      Returns number

      The interpolated value.

    • Converts radians to degrees.

      Parameters

      • radians: number

        The angle in radians.

      Returns number

      The angle in degrees.