math

Classes

goog.math.AffineTransform
Creates a 2D affine transform. An affine transform performs a linear mapping from 2D coordinates to other 2D coordinates that preserves the "straightness" and "parallelness" of lines. Such a coordinate transformation can be represented by a 3 row by 3 column matrix with an implied last row of [ 0 0 1 ]. This matrix transforms source coordinates (x,y) into destination coordinates (x',y') by considering them to be a column vector and multiplying the coordinate vector by the matrix according to the following process:
     [ x']   [  m00  m01  m02  ] [ x ]   [ m00x + m01y + m02 ]
     [ y'] = [  m10  m11  m12  ] [ y ] = [ m10x + m11y + m12 ]
     [ 1 ]   [   0    0    1   ] [ 1 ]   [         1         ]
This class is optimized for speed and minimizes calculations based on its knowledge of the underlying matrix (as opposed to say simply performing matrix multiplication).
goog.math.Bezier
Object representing a cubic bezier curve.
goog.math.Box
Class for representing a box. A box is specified as a top, right, bottom, and left. A box is useful for representing margins and padding.
goog.math.Coordinate
Class for representing coordinates and positions.
goog.math.Coordinate3
Class for representing coordinates and positions in 3 dimensions.
goog.math.Integer
Constructs a two's-complement integer an array containing bits of the integer in 32-bit (signed) pieces, given in little-endian order (i.e., lowest-order bits in the first piece), and the sign of -1 or 0. See the from* functions below for other convenient ways of constructing Integers. The internal representation of an integer is an array of 32-bit signed pieces, along with a sign (0 or -1) that indicates the contents of all the other 32-bit pieces out to infinity. We use 32-bit pieces because these are the size of integers on which Javascript performs bit-operations. For operations like addition and multiplication, we split each number into 16-bit pieces, which can easily be multiplied within Javascript's floating-point representation without overflow or change in sign.
goog.math.Line
Object representing a line.
goog.math.Long
Constructs a 64-bit two's-complement integer, given its low and high 32-bit values as *signed* integers. See the from* functions below for more convenient ways of constructing Longs. The internal representation of a long is the two given signed, 32-bit values. We use 32-bit pieces because these are the size of integers on which Javascript performs bit-operations. For operations like addition and multiplication, we split each number into 16-bit pieces, which can easily be multiplied within Javascript's floating-point representation without overflow or change in sign. In the algorithms below, we frequently reduce the negative case to the positive case by negating the input(s) and then post-processing the result. Note that we must ALWAYS check specially whether those values are MIN_VALUE (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as a positive number, it overflows back into a negative). Not handling this case would often result in infinite recursion.
goog.math.Matrix
Class for representing and manipulating matrices. The entry that lies in the i-th row and the j-th column of a matrix is typically referred to as the i,j entry of the matrix. The m-by-n matrix A would have its entries referred to as: [ a0,0 a0,1 a0,2 ... a0,j ... a0,n ] [ a1,0 a1,1 a1,2 ... a1,j ... a1,n ] [ a2,0 a2,1 a2,2 ... a2,j ... a2,n ] [ . . . . . ] [ . . . . . ] [ . . . . . ] [ ai,0 ai,1 ai,2 ... ai,j ... ai,n ] [ . . . . . ] [ . . . . . ] [ . . . . . ] [ am,0 am,1 am,2 ... am,j ... am,n ]
goog.math.Path
Creates a path object. A path is a sequence of segments and may be open or closed. Path uses the EVEN-ODD fill rule for determining the interior of the path. A path must start with a moveTo command. A "simple" path does not contain any arcs and may be transformed using the transform method.
goog.math.Range
A number range.
goog.math.RangeSet
Constructs a new RangeSet, which can store numeric ranges. Ranges are treated as half-closed: that is, they are exclusive of their end value [start, end). New ranges added to the set which overlap the values in one or more existing ranges will be merged.
goog.math.Rect
Class for representing rectangular regions.
goog.math.Size
Class for representing sizes consisting of a width and height. Undefined width and height support is deprecated and results in compiler warning.
goog.math.Vec2
Class for a two-dimensional vector object and assorted functions useful for manipulating points.
goog.math.Vec3
Class for a three-dimensional vector object and assorted functions useful for manipulation. Inherits from goog.math.Coordinate3 so that a Vec3 may be passed in to any function that requires a Coordinate.

Public Protected Private

Global Functions

goog.math.angle(x1y1x2y2) number
Computes the angle between two points (x1,y1) and (x2,y2). Angle zero points in the +X direction, 90 degrees points in the +Y direction (down) and from there we grow clockwise towards 360 degrees.
Arguments:
x1 : number
x of first point.
y1 : number
y of first point.
x2 : number
x of second point.
y2 : number
y of second point.
Returns: number  Standardized angle in degrees of the vector from x1,y1 to x2,y2.
code »
goog.math.angleDifference(startAngleendAngle) number
Computes the difference between startAngle and endAngle (angles in degrees).
Arguments:
startAngle : number
Start angle in degrees.
endAngle : number
End angle in degrees.
Returns: number  The number of degrees that when added to startAngle will result in endAngle. Positive numbers mean that the direction is clockwise. Negative numbers indicate a counter-clockwise direction. The shortest route (clockwise vs counter-clockwise) between the angles is used. When the difference is 180 degrees, the function returns 180 (not -180) angleDifference(30, 40) is 10, and angleDifference(40, 30) is -10. angleDifference(350, 10) is 20, and angleDifference(10, 350) is -20.
code »
goog.math.angleDx(degreesradius) number
For a given angle and radius, finds the X portion of the offset.
Arguments:
degrees : number
Angle in degrees (zero points in +X direction).
radius : number
Radius.
Returns: number  The x-distance for the angle and radius.
code »
goog.math.angleDy(degreesradius) number
For a given angle and radius, finds the Y portion of the offset.
Arguments:
degrees : number
Angle in degrees (zero points in +X direction).
radius : number
Radius.
Returns: number  The y-distance for the angle and radius.
code »
goog.math.average(var_args) number
Returns the arithmetic mean of the arguments.
Arguments:
var_args : ...number
Numbers to average.
Returns: number  The average of the arguments ( NaN if no arguments were provided or any of the arguments is not a valid number).
code »
goog.math.clamp(valueminmax) number
Takes a number and clamps it to within the provided bounds.
Arguments:
value : number
The input number.
min : number
The minimum value to return.
max : number
The maximum value to return.
Returns: number  The input number if it is within bounds, or the nearest number within the bounds.
code »
goog.math.isFiniteNumber(num) boolean
Returns whether the supplied number is finite and not NaN.
Arguments:
num : number
The number to test.
Returns: boolean  Whether num is a finite number.
code »
goog.math.isInt(num) boolean
Returns whether the supplied number represents an integer, i.e. that is has no fractional component. No range-checking is performed on the number.
Arguments:
num : number
The number to test.
Returns: boolean  Whether num is an integer.
code »
goog.math.lerp(abx) number
Performs linear interpolation between values a and b. Returns the value between a and b proportional to x (when x is between 0 and 1. When x is outside this range, the return value is a linear extrapolation).
Arguments:
a : number
A number.
b : number
A number.
x : number
The proportion between a and b.
Returns: number  The interpolated value between a and b.
code »
goog.math.log10Floor(num) number
Returns the precise value of floor(log10(num)). Simpler implementations didn't work because of floating point rounding errors. For example
  • Math.floor(Math.log(num) / Math.LN10) is off by one for num == 1e+3.
  • Math.floor(Math.log(num) * Math.LOG10E) is off by one for num == 1e+15.
  • Math.floor(Math.log10(num)) is off by one for num == 1e+15 - 1.
Arguments:
num : number
A floating point number.
Returns: number  Its logarithm to base 10 rounded down to the nearest integer if num > 0. -Infinity if num == 0. NaN if num < 0.
code »
goog.math.longestCommonSubsequence(array1array2opt_compareFnopt_collectorFn) !Array.<Object>
JavaScript implementation of Longest Common Subsequence problem. http://en.wikipedia.org/wiki/Longest_common_subsequence Returns the longest possible array that is subarray of both of given arrays.
Arguments:
array1 : Array.<Object>
First array of objects.
array2 : Array.<Object>
Second array of objects.
opt_compareFn : Function=
Function that acts as a custom comparator for the array ojects. Function should return true if objects are equal, otherwise false.
opt_collectorFn : Function=
Function used to decide what to return as a result subsequence. It accepts 2 arguments: index of common element in the first array and index in the second. The default function returns element from the first array.
Returns: !Array.<Object>  A list of objects that are common to both arrays such that there is no common subsequence with size greater than the length of the list.
code »
goog.math.modulo(ab) number
The % operator in JavaScript returns the remainder of a / b, but differs from some other languages in that the result will have the same sign as the dividend. For example, -1 % 8 == -1, whereas in some other languages (such as Python) the result would be 7. This function emulates the more correct modulo behavior, which is useful for certain applications such as calculating an offset index in a circular list.
Arguments:
a : number
The dividend.
b : number
The divisor.
Returns: number  a % b where the result is between 0 and b (either 0 <= x < b or b < x <= 0, depending on the sign of b).
code »
goog.math.nearlyEquals(abopt_tolerance) boolean
Tests whether the two values are equal to each other, within a certain tolerance to adjust for floating point errors.
Arguments:
a : number
A number.
b : number
A number.
opt_tolerance : number=
Optional tolerance range. Defaults to 0.000001. If specified, should be greater than 0.
Returns: boolean  Whether a and b are nearly equal.
code »
goog.math.randomInt(a) number
Returns a random integer greater than or equal to 0 and less than a.
Arguments:
a : number
The upper bound for the random integer (exclusive).
Returns: number  A random integer N such that 0 <= N < a.
code »
goog.math.safeCeil(numopt_epsilon) number
A tweaked variant of Math.ceil. See goog.math.safeFloor for details.
Arguments:
num : number
A number.
opt_epsilon : number=
An infinitesimally small positive number, the rounding error to tolerate.
Returns: number  The smallest integer greater than or equal to num.
code »
goog.math.safeFloor(numopt_epsilon) number
A tweaked variant of Math.floor which tolerates if the passed number is infinitesimally smaller than the closest integer. It often happens with the results of floating point calculations because of the finite precision of the intermediate results. For example Math.floor(Math.log(1000) / Math.LN10) == 2, not 3 as one would expect.
Arguments:
num : number
A number.
opt_epsilon : number=
An infinitesimally small positive number, the rounding error to tolerate.
Returns: number  The largest integer less than or equal to num.
code »
goog.math.sampleVariance(var_args) number
Returns the unbiased sample variance of the arguments. For a definition, see e.g. http://en.wikipedia.org/wiki/Variance
Arguments:
var_args : ...number
Number samples to analyze.
Returns: number  The unbiased sample variance of the arguments (0 if fewer than two samples were provided, or NaN if any of the samples is not a valid number).
code »
goog.math.sign(x) number
Returns the sign of a number as per the "sign" or "signum" function.
Arguments:
x : number
The number to take the sign of.
Returns: number  -1 when negative, 1 when positive, 0 when 0.
code »
goog.math.standardAngle(angle) number
Normalizes an angle to be in range [0-360). Angles outside this range will be normalized to be the equivalent angle with that range.
Arguments:
angle : number
Angle in degrees.
Returns: number  Standardized angle.
code »
goog.math.standardAngleInRadians(angle) number
Normalizes an angle to be in range [0-2*PI). Angles outside this range will be normalized to be the equivalent angle with that range.
Arguments:
angle : number
Angle in radians.
Returns: number  Standardized angle.
code »
goog.math.standardDeviation(var_args) number
Returns the sample standard deviation of the arguments. For a definition of sample standard deviation, see e.g. http://en.wikipedia.org/wiki/Standard_deviation
Arguments:
var_args : ...number
Number samples to analyze.
Returns: number  The sample standard deviation of the arguments (0 if fewer than two samples were provided, or NaN if any of the samples is not a valid number).
code »
goog.math.sum(var_args) number
Returns the sum of the arguments.
Arguments:
var_args : ...number
Numbers to add.
Returns: number  The sum of the arguments (0 if no arguments were provided, NaN if any of the arguments is not a valid number).
code »
goog.math.toDegrees(angleRadians) number
Converts radians to degrees.
Arguments:
angleRadians : number
Angle in radians.
Returns: number  Angle in degrees.
code »
goog.math.toRadians(angleDegrees) number
Converts degrees to radians.
Arguments:
angleDegrees : number
Angle in degrees.
Returns: number  Angle in radians.
code »
goog.math.uniformRandom(ab) number
Returns a random number greater than or equal to a and less than b.
Arguments:
a : number
The lower bound for the random number (inclusive).
b : number
The upper bound for the random number (exclusive).
Returns: number  A random number N such that a <= N < b.
code »

Global Properties

goog.math.AffineTransformTest :
No description.
Code »
goog.math.BezierTest :
No description.
Code »
goog.math.BoxTest :
No description.
Code »
goog.math.Coordinate3Test :
No description.
Code »
goog.math.CoordinateTest :
No description.
Code »
goog.math.ExponentialBackoffTest :
No description.
Code »
goog.math.IntegerTest :
No description.
Code »
goog.math.LineTest :
No description.
Code »
goog.math.LongTest :
No description.
Code »
goog.math.MatrixTest :
No description.
Code »
goog.math.PathTest :
No description.
Code »
goog.math.RangeSetTest :
No description.
Code »
goog.math.RangeTest :
No description.
Code »
goog.math.RectTest :
No description.
Code »
goog.math.SizeTest :
No description.
Code »
goog.math.Vec2Test :
No description.
Code »
goog.math.Vec3Test :
No description.
Code »
goog.math.interpolator :
No description.
Code »
goog.math.paths :
No description.
Code »
goog.math.pathsTest :
No description.
Code »
goog.math.tdma :
No description.
Code »
goog.math.tdmaTest :
No description.
Code »

Package math

Package Reference