22 * Common utilities
33 * @module glMatrix
44 */
5+
56// Configuration Constants
67export var EPSILON = 0.000001 ;
78export var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array ;
89export var RANDOM = Math . random ;
910export var ANGLE_ORDER = "zyx" ;
11+
12+ /**
13+ * Symmetric round
14+ * see https://www.npmjs.com/package/round-half-up-symmetric#user-content-detailed-background
15+ *
16+ * @param {Number } a value to round
17+ */
18+ export function round ( a ) {
19+ if ( a >= 0 ) return Math . round ( a ) ;
20+ return a % 0.5 === 0 ? Math . floor ( a ) : Math . round ( a ) ;
21+ }
22+
1023/**
1124 * Sets the type of array used when creating new vectors and matrices
1225 *
1326 * @param {Float32ArrayConstructor | ArrayConstructor } type Array type, such as Float32Array or Array
1427 */
15-
1628export function setMatrixArrayType ( type ) {
1729 ARRAY_TYPE = type ;
1830}
1931var degree = Math . PI / 180 ;
32+ var radian = 180 / Math . PI ;
33+
2034/**
2135 * Convert Degree To Radian
2236 *
2337 * @param {Number } a Angle in Degrees
2438 */
25-
2639export function toRadian ( a ) {
2740 return a * degree ;
2841}
42+
43+ /**
44+ * Convert Radian To Degree
45+ *
46+ * @param {Number } a Angle in Radians
47+ */
48+ export function toDegree ( a ) {
49+ return a * radian ;
50+ }
51+
2952/**
3053 * Tests whether or not the arguments have approximately the same value, within an absolute
3154 * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less
3255 * than or equal to 1.0, and a relative tolerance is used for larger values)
3356 *
34- * @param {Number } a The first number to test.
35- * @param {Number } b The second number to test.
57+ * @param {Number } a The first number to test.
58+ * @param {Number } b The second number to test.
59+ * @param {Number } tolerance Absolute or relative tolerance (default glMatrix.EPSILON)
3660 * @returns {Boolean } True if the numbers are approximately equal, false otherwise.
3761 */
38-
3962export function equals ( a , b ) {
40- return Math . abs ( a - b ) <= EPSILON * Math . max ( 1.0 , Math . abs ( a ) , Math . abs ( b ) ) ;
41- }
42- if ( ! Math . hypot ) Math . hypot = function ( ) {
43- var y = 0 ,
44- i = arguments . length ;
45-
46- while ( i -- ) {
47- y += arguments [ i ] * arguments [ i ] ;
48- }
49-
50- return Math . sqrt ( y ) ;
51- } ;
63+ var tolerance = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : EPSILON ;
64+ return Math . abs ( a - b ) <= tolerance * Math . max ( 1 , Math . abs ( a ) , Math . abs ( b ) ) ;
65+ }
0 commit comments