提交 8ed08e98 编写于 作者: M Mr.doob

Replaced EPSILONS with Number.EPSILON.

上级 95b294db
......@@ -98,7 +98,7 @@ THREE.CSS3DRenderer = function () {
var epsilon = function ( value ) {
return Math.abs( value ) < 0.000001 ? 0 : value;
return Math.abs( value ) < Number.EPSILON ? 0 : value;
};
......
......@@ -145,7 +145,7 @@ THREE.CSS3DStereoRenderer = function () {
var epsilon = function ( value ) {
return Math.abs( value ) < 0.000001 ? 0 : value;
return Math.abs( value ) < Number.EPSILON ? 0 : value;
};
......
......@@ -90,6 +90,16 @@ if ( self.performance.now === undefined ) {
}
//
if ( Number.EPSILON === undefined ) {
Number.EPSILON = Math.pow( 2, -52 );
}
//
if ( Math.sign === undefined ) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
......
......@@ -285,8 +285,6 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
( function ( namespace ) {
var EPSILON = 0.0000000001;
// takes in an contour array and returns
function process( contour, indices ) {
......@@ -417,7 +415,7 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
cx = contour[ verts[ w ] ].x;
cy = contour[ verts[ w ] ].y;
if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
var aX, aY, bX, bY, cX, cY;
var apx, apy, bpx, bpy, cpx, cpy;
......@@ -446,7 +444,7 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
cCROSSap = cX * apy - cY * apx;
bCROSScp = bX * cpy - bY * cpx;
if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
}
......
......@@ -39,8 +39,6 @@ THREE.ShapeUtils = {
function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
var EPSILON = 0.0000000001;
var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
......@@ -50,7 +48,7 @@ THREE.ShapeUtils = {
var limit = seg1dy * seg2dx - seg1dx * seg2dy;
var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
if ( Math.abs( limit ) > EPSILON ) {
if ( Math.abs( limit ) > Number.EPSILON ) {
// not parallel
......@@ -216,8 +214,6 @@ THREE.ShapeUtils = {
// The order of legs is important
var EPSILON = 0.0000000001;
// translation of all points, so that Vertex is at (0,0)
var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
......@@ -227,7 +223,7 @@ THREE.ShapeUtils = {
var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
if ( Math.abs( from2toAngle ) > EPSILON ) {
if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
// angle != 180 deg.
......
......@@ -425,9 +425,8 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
// Normalize to remove the closing point by default.
var lastPoint = points[ points.length - 1 ];
var EPSILON = 0.0000000001;
if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
points.splice( points.length - 1, 1 );
if ( closedPath ) {
......@@ -515,8 +514,6 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
function isPointInsidePolygon( inPt, inPolygon ) {
var EPSILON = 0.0000000001;
var polyLen = inPolygon.length;
// inPt on polygon contour => immediate success or
......@@ -532,7 +529,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
var edgeDx = edgeHighPt.x - edgeLowPt.x;
var edgeDy = edgeHighPt.y - edgeLowPt.y;
if ( Math.abs( edgeDy ) > EPSILON ) {
if ( Math.abs( edgeDy ) > Number.EPSILON ) {
// not parallel
if ( edgeDy < 0 ) {
......
......@@ -193,8 +193,6 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
function getBevelVec( inPt, inPrev, inNext ) {
var EPSILON = 0.0000000001;
// computes for inPt the corresponding point inPt' on a new contour
// shifted by 1 unit (length of normalized vector) to the left
// if we walk along contour clockwise, this new contour is outside the old one
......@@ -215,7 +213,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
// check for collinear edges
var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
if ( Math.abs( collinear0 ) > EPSILON ) {
if ( Math.abs( collinear0 ) > Number.EPSILON ) {
// not collinear
......@@ -261,9 +259,9 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
// handle special case of collinear edges
var direction_eq = false; // assumes: opposite
if ( v_prev_x > EPSILON ) {
if ( v_prev_x > Number.EPSILON ) {
if ( v_next_x > EPSILON ) {
if ( v_next_x > Number.EPSILON ) {
direction_eq = true;
......@@ -271,9 +269,9 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
} else {
if ( v_prev_x < - EPSILON ) {
if ( v_prev_x < - Number.EPSILON ) {
if ( v_next_x < - EPSILON ) {
if ( v_next_x < - Number.EPSILON ) {
direction_eq = true;
......
......@@ -174,7 +174,6 @@ THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
numpoints = segments + 1,
theta,
epsilon = 0.0001,
smallest,
tx, ty, tz,
......@@ -273,7 +272,7 @@ THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
if ( vec.length() > epsilon ) {
if ( vec.length() > Number.EPSILON ) {
vec.normalize();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册