Skip to content

Commit 8ed08e9

Browse files
committed
Replaced EPSILONS with Number.EPSILON.
1 parent 95b294d commit 8ed08e9

File tree

8 files changed

+25
-27
lines changed

8 files changed

+25
-27
lines changed

examples/js/renderers/CSS3DRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ THREE.CSS3DRenderer = function () {
9898

9999
var epsilon = function ( value ) {
100100

101-
return Math.abs( value ) < 0.000001 ? 0 : value;
101+
return Math.abs( value ) < Number.EPSILON ? 0 : value;
102102

103103
};
104104

examples/js/renderers/CSS3DStereoRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ THREE.CSS3DStereoRenderer = function () {
145145

146146
var epsilon = function ( value ) {
147147

148-
return Math.abs( value ) < 0.000001 ? 0 : value;
148+
return Math.abs( value ) < Number.EPSILON ? 0 : value;
149149

150150
};
151151

src/Three.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ if ( self.performance.now === undefined ) {
9090

9191
}
9292

93+
//
94+
95+
if ( Number.EPSILON === undefined ) {
96+
97+
Number.EPSILON = Math.pow( 2, -52 );
98+
99+
}
100+
101+
//
102+
93103
if ( Math.sign === undefined ) {
94104

95105
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign

src/extras/FontUtils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
285285

286286
( function ( namespace ) {
287287

288-
var EPSILON = 0.0000000001;
289-
290288
// takes in an contour array and returns
291289

292290
function process( contour, indices ) {
@@ -417,7 +415,7 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
417415
cx = contour[ verts[ w ] ].x;
418416
cy = contour[ verts[ w ] ].y;
419417

420-
if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
418+
if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
421419

422420
var aX, aY, bX, bY, cX, cY;
423421
var apx, apy, bpx, bpy, cpx, cpy;
@@ -446,7 +444,7 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
446444
cCROSSap = cX * apy - cY * apx;
447445
bCROSScp = bX * cpy - bY * cpx;
448446

449-
if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
447+
if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
450448

451449
}
452450

src/extras/ShapeUtils.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ THREE.ShapeUtils = {
3939

4040
function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
4141

42-
var EPSILON = 0.0000000001;
43-
4442
var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
4543
var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
4644

@@ -50,7 +48,7 @@ THREE.ShapeUtils = {
5048
var limit = seg1dy * seg2dx - seg1dx * seg2dy;
5149
var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
5250

53-
if ( Math.abs( limit ) > EPSILON ) {
51+
if ( Math.abs( limit ) > Number.EPSILON ) {
5452

5553
// not parallel
5654

@@ -216,8 +214,6 @@ THREE.ShapeUtils = {
216214

217215
// The order of legs is important
218216

219-
var EPSILON = 0.0000000001;
220-
221217
// translation of all points, so that Vertex is at (0,0)
222218
var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
223219
var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
@@ -227,7 +223,7 @@ THREE.ShapeUtils = {
227223
var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
228224
var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
229225

230-
if ( Math.abs( from2toAngle ) > EPSILON ) {
226+
if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
231227

232228
// angle != 180 deg.
233229

src/extras/core/Path.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
425425

426426
// Normalize to remove the closing point by default.
427427
var lastPoint = points[ points.length - 1 ];
428-
var EPSILON = 0.0000000001;
429-
if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
430-
Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
428+
if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
429+
Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
431430
points.splice( points.length - 1, 1 );
432431
if ( closedPath ) {
433432

@@ -515,8 +514,6 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
515514

516515
function isPointInsidePolygon( inPt, inPolygon ) {
517516

518-
var EPSILON = 0.0000000001;
519-
520517
var polyLen = inPolygon.length;
521518

522519
// inPt on polygon contour => immediate success or
@@ -532,7 +529,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
532529
var edgeDx = edgeHighPt.x - edgeLowPt.x;
533530
var edgeDy = edgeHighPt.y - edgeLowPt.y;
534531

535-
if ( Math.abs( edgeDy ) > EPSILON ) {
532+
if ( Math.abs( edgeDy ) > Number.EPSILON ) {
536533

537534
// not parallel
538535
if ( edgeDy < 0 ) {

src/extras/geometries/ExtrudeGeometry.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
193193

194194
function getBevelVec( inPt, inPrev, inNext ) {
195195

196-
var EPSILON = 0.0000000001;
197-
198196
// computes for inPt the corresponding point inPt' on a new contour
199197
// shifted by 1 unit (length of normalized vector) to the left
200198
// 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 ) {
215213
// check for collinear edges
216214
var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
217215

218-
if ( Math.abs( collinear0 ) > EPSILON ) {
216+
if ( Math.abs( collinear0 ) > Number.EPSILON ) {
219217

220218
// not collinear
221219

@@ -261,19 +259,19 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
261259
// handle special case of collinear edges
262260

263261
var direction_eq = false; // assumes: opposite
264-
if ( v_prev_x > EPSILON ) {
262+
if ( v_prev_x > Number.EPSILON ) {
265263

266-
if ( v_next_x > EPSILON ) {
264+
if ( v_next_x > Number.EPSILON ) {
267265

268266
direction_eq = true;
269267

270268
}
271269

272270
} else {
273271

274-
if ( v_prev_x < - EPSILON ) {
272+
if ( v_prev_x < - Number.EPSILON ) {
275273

276-
if ( v_next_x < - EPSILON ) {
274+
if ( v_next_x < - Number.EPSILON ) {
277275

278276
direction_eq = true;
279277

src/extras/geometries/TubeGeometry.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
174174

175175
numpoints = segments + 1,
176176
theta,
177-
epsilon = 0.0001,
178177
smallest,
179178

180179
tx, ty, tz,
@@ -273,7 +272,7 @@ THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
273272

274273
vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
275274

276-
if ( vec.length() > epsilon ) {
275+
if ( vec.length() > Number.EPSILON ) {
277276

278277
vec.normalize();
279278

0 commit comments

Comments
 (0)