UFMath implements methods supporting numbers.

Accessors

Methods

  • Calculates the angle between two points

    Parameters

    • x1: number

      First X coordinate of point

    • y1: number

      First Y coordinate of point

    • x2: number

      Second X coordinate of point

    • y2: number

      Second Y coordinate of point

    Returns number

    Angle in degrees (0..360)

  • Calculates distance between two points.

    Parameters

    • x1: number

      First X coordinate of point

    • y1: number

      First Y coordinate of point

    • x2: number

      Second X coordinate of point

    • y2: number

      Second Y coordinate of point

    Returns number

    Distance between two points

  • Convert angle from radians to unit as specified by m_angleUnit

    Parameters

    • angle: number

      Angle to convert

    Returns number

    Converted angle.

  • Checks if a value is a valid number, if not return a default value instead.

    Parameters

    • value: any

      Value to check

    • defaultNumber: number

      Default value to use if aValue is not a valid number

    Returns number

    either aValue as a number or aDefault

  • Checks if two rectangles overlap.

    Parameters

    • x0: number

      Left of first rectangle

    • y0: number

      Left of first rectangle

    • width0: number

      Left of first rectangle

    • height0: number

      Left of first rectangle

    • x1: number

      Left of second rectangle

    • y1: number

      Left of second rectangle

    • width1: number

      Left of second rectangle

    • height1: number

      Left of second rectangle

    Returns boolean

    True if two rectangles overlap

  • Makes sure a value is within a range.

    Parameters

    • minValue: number

      Minimum value

    • maxValue: number

      Maximum value

    • value: number

      Value to test

    Returns number

    aValue if it is within range or aMin or aMax

  • Calculates a position based on movement over time. The method makes sure the returned value is between the specified target and starting values.

    Parameters

    • target: number

      Target to move to

    • start: number

      Starting position moving from

    • currentTime: number

      Current time

    • totalTime: number

      Total time movement should take place

    Returns number

    value between aStart and aTarget (both inclusive)

  • Increases or decreases value, so it gets nearer to a target value.

    Parameters

    • target: number

      Value to reach

    • current: number

      Current value

    • stepSize: number

      Value to move with

    Returns number

    aCurrent +/- aStep or aTarget if aCurrent was closer to aTarget then aStep distance

  • Returns a random integer.

    Parameters

    • minOrMaxValue: number

      Minimal or maximum value (if aMax is not specified)

    • Optional maxValue: number

      Maximal value

    Returns number

    random integer between aMin and aMax (inclusive)

  • Rotates a 2D coordinate around a certain point.

    Parameters

    • angle: number

      Angle

    • x: number

      X coordinate of point to rotate

    • y: number

      Y coordinate of point to rotate

    • originX: number = 0

      X coordinate of point to rotate around

    • originY: number = 0

      Y coordinate of point to rotate around

    Returns {
        x: number;
        y: number;
    }

    An object with x and y property.

    • x: number
    • y: number
  • Convert angle to radians, use angleUnit to determine unit of input parameter.

    Parameters

    • angle: number

      Angle to convert

    Returns number

    Converted angle.

  • Performs a logical xor on two values.

    Reference: http://www.howtocreate.co.uk/xor.html

    Parameters

    • value0: any

      First value

    • value1: any

      Second value

    Returns boolean

    True if either aValue0 or aValue1 evaluates to a truthy but not both; otherwise false if both values evaluate to a truthy or falsy.