Class: Math

Math

new Math()

Math utility.
Source:

Methods

<static> distance(x0, y0, x1, y1) → {number}

Euclidean distance between two points P(x0, y0) and P(x1, y1).
Parameters:
Name Type Description
x0 number Horizontal coordinate of P0.
y0 number Vertical coordinate of P0.
x1 number Horizontal coordinate of P1.
y1 number Vertical coordinate of P1.
Source:
Returns:
The euclidean distance.
Type
number

<static> hammingWeight(i) → {number}

Calculates the Hamming weight of a string, which is the number of symbols that are different from the zero-symbol of the alphabet used. It is thus equivalent to the Hamming distance from the all-zero string of the same length. For the most typical case, a string of bits, this is the number of 1's in the string. Example:
 Binary string     Hamming weight
  11101                 4
  11101010              5
Parameters:
Name Type Description
i number Number that holds the binary string to extract the hamming weight.
Source:
Returns:
The hamming weight.
Type
number

<static> intersectRect(x0, y0, x1, y1, x2, y2, x3, y3) → {boolean}

Tests if a rectangle intersects with another.
 x0y0 --------       x2y2 --------
     |       |           |       |
     -------- x1y1       -------- x3y3
Parameters:
Name Type Description
x0 number Horizontal coordinate of P0.
y0 number Vertical coordinate of P0.
x1 number Horizontal coordinate of P1.
y1 number Vertical coordinate of P1.
x2 number Horizontal coordinate of P2.
y2 number Vertical coordinate of P2.
x3 number Horizontal coordinate of P3.
y3 number Vertical coordinate of P3.
Source:
Returns:
Type
boolean

<static> uniformRandom(a, b) → {number}

Generates a random number between [a, b] interval.
Parameters:
Name Type Description
a number
b number
Source:
Returns:
Type
number