From 90ab0b70bfff65c22727cdf00f9070dbe7833b7d Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Fri, 29 Aug 2014 13:57:36 -0400 Subject: [PATCH] Polyfill for Math.sign(). Chrome 38 will come with it and Firefox already implemented it. --- examples/js/Mirror.js | 6 ++---- src/Three.js | 13 +++++++++++++ src/extras/geometries/ExtrudeGeometry.js | 3 +-- src/math/Math.js | 6 ------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/js/Mirror.js b/examples/js/Mirror.js index 63ebb18ba4..fbe893485c 100644 --- a/examples/js/Mirror.js +++ b/examples/js/Mirror.js @@ -171,8 +171,6 @@ THREE.Mirror.prototype.renderWithMirror = function ( otherMirror ) { THREE.Mirror.prototype.updateTextureMatrix = function () { - var sign = THREE.Math.sign; - this.updateMatrixWorld(); this.camera.updateMatrixWorld(); @@ -228,8 +226,8 @@ THREE.Mirror.prototype.updateTextureMatrix = function () { var q = new THREE.Vector4(); var projectionMatrix = this.mirrorCamera.projectionMatrix; - q.x = ( sign(this.clipPlane.x) + projectionMatrix.elements[8] ) / projectionMatrix.elements[0]; - q.y = ( sign(this.clipPlane.y) + projectionMatrix.elements[9] ) / projectionMatrix.elements[5]; + q.x = ( Math.sign(this.clipPlane.x) + projectionMatrix.elements[8] ) / projectionMatrix.elements[0]; + q.y = ( Math.sign(this.clipPlane.y) + projectionMatrix.elements[9] ) / projectionMatrix.elements[5]; q.z = - 1.0; q.w = ( 1.0 + projectionMatrix.elements[10] ) / projectionMatrix.elements[14]; diff --git a/src/Three.js b/src/Three.js index 841e4ca545..ae33897343 100644 --- a/src/Three.js +++ b/src/Three.js @@ -5,12 +5,25 @@ var THREE = { REVISION: '69dev' }; // browserify support + if ( typeof module === 'object' ) { module.exports = THREE; } +// polyfills + +if ( Math.sign === undefined ) { + + Math.sign = function ( x ) { + + return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : 0; + + }; + +} + // GL STATE CONSTANTS THREE.CullFaceNone = 0; diff --git a/src/extras/geometries/ExtrudeGeometry.js b/src/extras/geometries/ExtrudeGeometry.js index d36ce187cb..bb0419574d 100644 --- a/src/extras/geometries/ExtrudeGeometry.js +++ b/src/extras/geometries/ExtrudeGeometry.js @@ -193,7 +193,6 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) { function getBevelVec( inPt, inPrev, inNext ) { var EPSILON = 0.0000000001; - var sign = THREE.Math.sign; // computes for inPt the corresponding point inPt' on a new contour // shiftet by 1 unit (length of normalized vector) to the left @@ -259,7 +258,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) { if ( v_prev_x < - EPSILON ) { if ( v_next_x < - EPSILON ) { direction_eq = true; } } else { - if ( sign(v_prev_y) == sign(v_next_y) ) { direction_eq = true; } + if ( Math.sign(v_prev_y) == Math.sign(v_next_y) ) { direction_eq = true; } } } diff --git a/src/math/Math.js b/src/math/Math.js index fbbaf63311..ef7af15371 100644 --- a/src/math/Math.js +++ b/src/math/Math.js @@ -122,12 +122,6 @@ THREE.Math = { }, - sign: function ( x ) { - - return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : 0; - - }, - degToRad: function () { var degreeToRadiansFactor = Math.PI / 180; -- GitLab