UFMath implements methods supporting numbers.

Accessors

Methods

  • Calculates the angle between two points

    Parameters

    • aX1: number

      First X coordinate of point

    • aY1: number

      First Y coordinate of point

    • aX2: number

      Second X coordinate of point

    • aY2: number

      Second Y coordinate of point

    Returns number

    Angle in degrees (0..360)

  • Calculates distance between two points.

    Parameters

    • aX1: number

      First X coordinate of point

    • aY1: number

      First Y coordinate of point

    • aX2: number

      Second X coordinate of point

    • aY2: number

      Second Y coordinate of point

    Returns number

    Distance between two points

  • Convert angle from radians to unit as specified by m_angleUnit

    Parameters

    • anAngle: number

      Angle to convert

    Returns number

    Converted angle.

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

    Parameters

    • aValue: any

      Value to check

    • aDefault: 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

    • aX0: number

      Left of first rectangle

    • aY0: number

      Left of first rectangle

    • aWidth0: number

      Left of first rectangle

    • anHeight0: number

      Left of first rectangle

    • aX1: number

      Left of second rectangle

    • aY1: number

      Left of second rectangle

    • aWidth1: number

      Left of second rectangle

    • anHeight1: number

      Left of second rectangle

    Returns boolean

    True if two rectangles overlap

  • Makes sure a value is within a range.

    Parameters

    • aMin: number

      Minimum value

    • aMax: number

      Maximum value

    • aValue: 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

    • aTarget: number

      Target to move to

    • aStart: number

      Starting position moving from

    • aCurrentTime: number

      Current time

    • aTotalTime: 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

    • aTarget: number

      Value to reach

    • aCurrent: number

      Current value

    • aStepSize: 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

    • aMinOrMax: number

      Minimal or maximum value (if aMax is not specified)

    • Optional aMax: number

      Maximal value

    Returns number

    random integer between aMin and aMax (inclusive)

  • Rotates a 2D coordinate around a certain point.

    Parameters

    • anAngle: number

      Angle

    • aX: number

      X coordinate of point to rotate

    • aY: number

      Y coordinate of point to rotate

    • anOriginX: number = 0

      X coordinate of point to rotate around

    • anOriginY: 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

    • anAngle: number

      Angle to convert

    Returns number

    Converted angle.

  • Performs a logical xor on two values.

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

    Parameters

    • aValue0: any

      First value

    • aValue1: 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.