diff --git a/Gruntfile.js b/Gruntfile.js index 6686a98..24bc067 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,10 +17,10 @@ module.exports = function( grunt ) { 'use strict'; grunt.registerTask( 'doc-dot', 'Generates Documentation', function() { - var indexHTML = ''; - var contentHTML = ''; + let indexHTML = ''; + let contentHTML = ''; - var localTypeIds = { + const localTypeIds = { BinPacker: 'binPacker', Bin: 'binPacker-bin', Bounds2: 'bounds2', @@ -54,21 +54,21 @@ module.exports = function( grunt ) { Vector4: 'vector4' }; - var externalTypeURLs = { + const externalTypeURLs = { Events: '../../axon/doc#events', Shape: '../../kite/doc#shape' }; function docFile( file, baseName, typeNames ) { - var codeFile = fs.readFileSync( file, 'utf8' ); - var program = esprima.parse( codeFile, { + const codeFile = fs.readFileSync( file, 'utf8' ); + const program = esprima.parse( codeFile, { attachComment: true } ); - var doc = extractDocumentation( program ); + const doc = extractDocumentation( program ); if ( baseName === 'ConvexHull2' ) { // for testing // console.log( JSON.stringify( doc, null, 2 ) ); } - var htmlDoc = documentationToHTML( doc, baseName, typeNames, localTypeIds, externalTypeURLs ); + const htmlDoc = documentationToHTML( doc, baseName, typeNames, localTypeIds, externalTypeURLs ); indexHTML += htmlDoc.indexHTML; contentHTML += htmlDoc.contentHTML; @@ -87,9 +87,9 @@ module.exports = function( grunt ) { docFile( 'js/Vector3.js', 'Vector3', [ 'Vector3' ] ); docFile( 'js/Vector4.js', 'Vector4', [ 'Vector4' ] ); - var template = fs.readFileSync( 'doc/template.html', 'utf8' ); + const template = fs.readFileSync( 'doc/template.html', 'utf8' ); - var html = template.replace( '{{API_INDEX}}', indexHTML ).replace( '{{API_CONTENT}}', contentHTML ); + let html = template.replace( '{{API_INDEX}}', indexHTML ).replace( '{{API_CONTENT}}', contentHTML ); html = beautify_html( html, { indent_size: 2 } ); diff --git a/js/BinPacker.js b/js/BinPacker.js index b451217..86f978c 100644 --- a/js/BinPacker.js +++ b/js/BinPacker.js @@ -60,11 +60,11 @@ define( require => { */ allocate: function( width, height ) { // find a leaf bin that has available room (or null) - var bin = this.rootBin.findAvailableBin( width, height ); + const bin = this.rootBin.findAvailableBin( width, height ); if ( bin ) { // split it into a sized sub-bin for our purpose that we will use, and other bins for future allocations - var sizedBin = bin.split( width, height ); + const sizedBin = bin.split( width, height ); // mark our bin as used sizedBin.use(); @@ -91,9 +91,9 @@ define( require => { * @returns {string} */ toString: function() { - var result = ''; + let result = ''; - var padding = ''; + let padding = ''; function binTree( bin ) { result += padding + bin.toString() + '\n'; @@ -155,8 +155,8 @@ define( require => { } // If we have been split, check our children else if ( this.isSplit ) { - for ( var i = 0; i < this.children.length; i++ ) { - var result = this.children[ i ].findAvailableBin( width, height ); + for ( let i = 0; i < this.children.length; i++ ) { + const result = this.children[ i ].findAvailableBin( width, height ); if ( result ) { return result; } @@ -193,8 +193,8 @@ define( require => { this.isSplit = true; // locations of the split - var splitX = this.bounds.minX + width; - var splitY = this.bounds.minY + height; + const splitX = this.bounds.minX + width; + const splitY = this.bounds.minY + height; /* * How an area is split (for now). In the future, splitting more after determining what we need to fit next would @@ -212,11 +212,11 @@ define( require => { * * * * ************************************ */ - var mainBounds = new Bounds2( this.bounds.minX, this.bounds.minY, splitX, splitY ); - var rightBounds = new Bounds2( splitX, this.bounds.minY, this.bounds.maxX, splitY ); - var bottomBounds = new Bounds2( this.bounds.minX, splitY, this.bounds.maxX, this.bounds.maxY ); + const mainBounds = new Bounds2( this.bounds.minX, this.bounds.minY, splitX, splitY ); + const rightBounds = new Bounds2( splitX, this.bounds.minY, this.bounds.maxX, splitY ); + const bottomBounds = new Bounds2( this.bounds.minX, splitY, this.bounds.maxX, this.bounds.maxY ); - var mainBin = new dot.BinPacker.Bin( mainBounds, this ); + const mainBin = new dot.BinPacker.Bin( mainBounds, this ); this.children.push( mainBin ); // only add right/bottom if they take up area @@ -264,8 +264,8 @@ define( require => { // Bail out if a single child isn't able to be collapsed. If it is not split or used, it won't have any children // or needs. - for ( var i = 0; i < this.children.length; i++ ) { - var child = this.children[ i ]; + for ( let i = 0; i < this.children.length; i++ ) { + const child = this.children[ i ]; if ( child.isSplit || child.isUsed ) { return; diff --git a/js/BinPackerTests.js b/js/BinPackerTests.js index 2be0276..6666aec 100644 --- a/js/BinPackerTests.js +++ b/js/BinPackerTests.js @@ -15,18 +15,18 @@ define( require => { QUnit.module( 'BinPacker' ); QUnit.test( 'Entire BinPacker allocation', function( assert ) { - var p = new BinPacker( new Bounds2( 0, 0, 1, 1 ) ); - var bin = p.allocate( 1, 1 ); + const p = new BinPacker( new Bounds2( 0, 0, 1, 1 ) ); + const bin = p.allocate( 1, 1 ); assert.ok( bin, 'Should have a bin' ); assert.ok( !p.allocate( 1, 1 ), 'Should not be able to fit another bin' ); } ); QUnit.test( 'Many bins', function( assert ) { function checkNoOverlappingBins( array, containingBounds ) { - for ( var i = 0; i < array.length; i++ ) { + for ( let i = 0; i < array.length; i++ ) { if ( array[ i ] ) { assert.ok( array[ i ].bounds.intersection( containingBounds ).equals( array[ i ].bounds ), 'Bin containment in packer' ); - for ( var j = 0; j < array.length; j++ ) { + for ( let j = 0; j < array.length; j++ ) { if ( array[ i ] && array[ j ] ) { assert.ok( !array[ i ].bounds.intersection( array[ j ] ).hasNonzeroArea(), 'Bin intersection' ); } @@ -35,11 +35,11 @@ define( require => { } } - var bounds = new Bounds2( 0, 0, 1, 1 ); + const bounds = new Bounds2( 0, 0, 1, 1 ); // manual selection - var p = new BinPacker( bounds ); - var bins = []; + let p = new BinPacker( bounds ); + let bins = []; bins.push( p.allocate( 0.5, 0.5 ) ); bins.push( p.allocate( 0.7, 0.5 ) ); bins.push( p.allocate( 0.25, 0.25 ) ); @@ -160,7 +160,7 @@ define( require => { } // once empty, ensure we can allocate the full thing - var fullBin = p.allocate( 1, 1 ); + const fullBin = p.allocate( 1, 1 ); assert.ok( fullBin, 'Allocation of full bin' ); } ); } ); \ No newline at end of file diff --git a/js/Bounds2.js b/js/Bounds2.js index 5f41e49..2eb6ba1 100644 --- a/js/Bounds2.js +++ b/js/Bounds2.js @@ -22,7 +22,7 @@ define( require => { const Vector2 = require( 'DOT/Vector2' ); // Temporary instances to be used in the transform method. - var scratchVector2 = new dot.Vector2( 0, 0 ); + const scratchVector2 = new dot.Vector2( 0, 0 ); /** * Creates a 2-dimensional bounds (bounding box). @@ -327,8 +327,8 @@ define( require => { return location; } else { - var xConstrained = Math.max( Math.min( location.x, this.maxX ), this.x ); - var yConstrained = Math.max( Math.min( location.y, this.maxY ), this.y ); + const xConstrained = Math.max( Math.min( location.x, this.maxX ), this.x ); + const yConstrained = Math.max( Math.min( location.y, this.maxY ), this.y ); return new Vector2( xConstrained, yConstrained ); } }, @@ -376,10 +376,10 @@ define( require => { * @returns {boolean} */ intersectsBounds: function( bounds ) { - var minX = Math.max( this.minX, bounds.minX ); - var minY = Math.max( this.minY, bounds.minY ); - var maxX = Math.min( this.maxX, bounds.maxX ); - var maxY = Math.min( this.maxY, bounds.maxY ); + const minX = Math.max( this.minX, bounds.minX ); + const minY = Math.max( this.minY, bounds.minY ); + const maxX = Math.min( this.maxX, bounds.maxX ); + const maxY = Math.min( this.maxY, bounds.maxY ); return ( maxX - minX ) >= 0 && ( maxY - minY >= 0 ); }, @@ -391,9 +391,9 @@ define( require => { * @returns {number} */ minimumDistanceToPointSquared: function( point ) { - var closeX = point.x < this.minX ? this.minX : ( point.x > this.maxX ? this.maxX : null ); - var closeY = point.y < this.minY ? this.minY : ( point.y > this.maxY ? this.maxY : null ); - var d; + const closeX = point.x < this.minX ? this.minX : ( point.x > this.maxX ? this.maxX : null ); + const closeY = point.y < this.minY ? this.minY : ( point.y > this.maxY ? this.maxY : null ); + let d; if ( closeX === null && closeY === null ) { // inside, or on the boundary return 0; @@ -410,8 +410,8 @@ define( require => { } else { // corner case - var dx = closeX - point.x; - var dy = closeY - point.y; + const dx = closeX - point.x; + const dy = closeY - point.y; return dx * dx + dy * dy; } }, @@ -424,8 +424,8 @@ define( require => { * @returns {number} */ maximumDistanceToPointSquared: function( point ) { - var x = point.x > this.getCenterX() ? this.minX : this.maxX; - var y = point.y > this.getCenterY() ? this.minY : this.maxY; + let x = point.x > this.getCenterX() ? this.minX : this.maxX; + let y = point.y > this.getCenterY() ? this.minY : this.maxY; x -= point.x; y -= point.y; return x * x + y * y; @@ -463,8 +463,8 @@ define( require => { */ equalsEpsilon: function( other, epsilon ) { epsilon = epsilon !== undefined ? epsilon : 0; - var thisFinite = this.isFinite(); - var otherFinite = other.isFinite(); + const thisFinite = this.isFinite(); + const otherFinite = other.isFinite(); if ( thisFinite && otherFinite ) { // both are finite, so we can use Math.abs() - it would fail with non-finite values like Infinity return Math.abs( this.minX - other.minX ) < epsilon && @@ -904,7 +904,7 @@ define( require => { * amount of each. */ blend: function( bounds, ratio ) { - var t = 1 - ratio; + const t = 1 - ratio; return new Bounds2( t * this.minX + ratio * bounds.minX, t * this.minY + ratio * bounds.minY, @@ -1182,10 +1182,10 @@ define( require => { return this; } - var minX = this.minX; - var minY = this.minY; - var maxX = this.maxX; - var maxY = this.maxY; + const minX = this.minX; + const minY = this.minY; + const maxX = this.maxX; + const maxY = this.maxY; this.set( dot.Bounds2.NOTHING ); // using mutable vector so we don't create excessive instances of Vector2 during this @@ -1415,7 +1415,7 @@ define( require => { */ point: function( x, y ) { if ( x instanceof dot.Vector2 ) { - var p = x; + const p = x; return new Bounds2( p.x, p.y, p.x, p.y ); } else { diff --git a/js/Bounds2Tests.js b/js/Bounds2Tests.js index d18ecd7..e5a7432 100644 --- a/js/Bounds2Tests.js +++ b/js/Bounds2Tests.js @@ -17,7 +17,7 @@ define( require => { QUnit.module( 'Bounds2' ); - var epsilon = 0.00000001; + const epsilon = 0.00000001; function approximateBoundsEquals( assert, a, b, msg ) { assert.ok( Math.abs( a.minX - b.minX ) < epsilon, msg + ' minX: expected: ' + b.minX + ', result: ' + a.minX ); @@ -31,7 +31,7 @@ define( require => { } ); QUnit.test( 'Basic', function( assert ) { - var bounds = new Bounds2( 1, 2, 3, 4 ); + const bounds = new Bounds2( 1, 2, 3, 4 ); assert.ok( bounds.minX === 1, 'minX' ); assert.ok( bounds.minY === 2, 'minY' ); assert.ok( bounds.maxX === 3, 'maxX' ); @@ -45,7 +45,7 @@ define( require => { } ); QUnit.test( 'Coordinates', function( assert ) { - var bounds = new Bounds2( 1, 2, 3, 4 ); + const bounds = new Bounds2( 1, 2, 3, 4 ); assert.ok( !bounds.isEmpty(), 'isEmpty' ); assert.ok( !bounds.containsCoordinates( 0, 0 ), 'coordinates #1' ); @@ -88,7 +88,7 @@ define( require => { approximateBoundsEquals( assert, C().roundedOut(), C().roundOut(), 'roundedOut / roundOut' ); approximateBoundsEquals( assert, C().roundedIn(), C().roundIn(), 'roundedIn / roundIn' ); - var matrix = Matrix3.rotation2( Math.PI / 4 ).timesMatrix( Matrix3.translation( 11, -13 ) ).timesMatrix( Matrix3.scale( 2, 3.5 ) ); + const matrix = Matrix3.rotation2( Math.PI / 4 ).timesMatrix( Matrix3.translation( 11, -13 ) ).timesMatrix( Matrix3.scale( 2, 3.5 ) ); approximateBoundsEquals( assert, A().transformed( matrix ), A().transform( matrix ), 'transformed / transform' ); approximateBoundsEquals( assert, A().dilated( 1.5 ), A().dilate( 1.5 ), 'dilated / dilate' ); diff --git a/js/Bounds3.js b/js/Bounds3.js index d6c0415..40e73d8 100644 --- a/js/Bounds3.js +++ b/js/Bounds3.js @@ -389,8 +389,8 @@ define( require => { */ equalsEpsilon: function( other, epsilon ) { epsilon = epsilon !== undefined ? epsilon : 0; - var thisFinite = this.isFinite(); - var otherFinite = other.isFinite(); + const thisFinite = this.isFinite(); + const otherFinite = other.isFinite(); if ( thisFinite && otherFinite ) { // both are finite, so we can use Math.abs() - it would fail with non-finite values like Infinity return Math.abs( this.minX - other.minX ) < epsilon && @@ -1141,16 +1141,16 @@ define( require => { return this; } - var minX = Number.POSITIVE_INFINITY; - var minY = Number.POSITIVE_INFINITY; - var minZ = Number.POSITIVE_INFINITY; - var maxX = Number.NEGATIVE_INFINITY; - var maxY = Number.NEGATIVE_INFINITY; - var maxZ = Number.NEGATIVE_INFINITY; + let minX = Number.POSITIVE_INFINITY; + let minY = Number.POSITIVE_INFINITY; + let minZ = Number.POSITIVE_INFINITY; + let maxX = Number.NEGATIVE_INFINITY; + let maxY = Number.NEGATIVE_INFINITY; + let maxZ = Number.NEGATIVE_INFINITY; // using mutable vector so we don't create excessive instances of Vector2 during this // make sure all 4 corners are inside this transformed bounding box - var vector = new dot.Vector3( 0, 0, 0 ); + const vector = new dot.Vector3( 0, 0, 0 ); function withIt( vector ) { minX = Math.min( minX, vector.x ); diff --git a/js/Complex.js b/js/Complex.js index b2a3ac3..ab4d4f8 100644 --- a/js/Complex.js +++ b/js/Complex.js @@ -167,7 +167,7 @@ define( require => { * @returns {Complex} */ dividedBy: function( c ) { - var cMag = c.magnitudeSquared; + const cMag = c.magnitudeSquared; return new Complex( ( this.real * c.real + this.imaginary * c.imaginary ) / cMag, ( this.imaginary * c.real - this.real * c.imaginary ) / cMag @@ -182,7 +182,7 @@ define( require => { * @returns {Complex} */ sqrtOf: function() { - var mag = this.magnitude; + const mag = this.magnitude; return new Complex( Math.sqrt( ( mag + this.real ) / 2 ), ( this.imaginary >= 0 ? 1 : -1 ) * Math.sqrt( ( mag - this.real ) / 2 ) ); }, @@ -363,7 +363,7 @@ define( require => { * @returns {Complex} */ divide: function( c ) { - var cMag = c.magnitudeSquared; + const cMag = c.magnitudeSquared; return this.setRealImaginary( ( this.real * c.real + this.imaginary * c.imaginary ) / cMag, ( this.imaginary * c.real - this.real * c.imaginary ) / cMag @@ -400,7 +400,7 @@ define( require => { * @returns {Complex} */ sqrt: function() { - var mag = this.magnitude; + const mag = this.magnitude; return this.setRealImaginary( Math.sqrt( ( mag + this.real ) / 2 ), ( this.imaginary >= 0 ? 1 : -1 ) * Math.sqrt( ( mag - this.real ) / 2 ) ); }, diff --git a/js/ComplexTests.js b/js/ComplexTests.js index a640f6f..7b71ffb 100644 --- a/js/ComplexTests.js +++ b/js/ComplexTests.js @@ -15,12 +15,12 @@ define( require => { QUnit.module( 'Complex' ); function approximateComplexEquals( assert, a, b, msg ) { - var epsilon = 0.00001; + const epsilon = 0.00001; assert.ok( a.equalsEpsilon( b, epsilon ), msg + ' expected: ' + b.toString() + ', result: ' + a.toString() ); } QUnit.test( 'Basic', function( assert ) { - var c = new Complex( 2, 3 ); + const c = new Complex( 2, 3 ); assert.equal( c.real, 2, 'real' ); assert.equal( c.imaginary, 3, 'imaginary' ); assert.equal( c.conjugated().real, 2, 'real conjugated' ); @@ -36,8 +36,8 @@ define( require => { } ); QUnit.test( 'Canceling', function( assert ) { - var a = new Complex( 2, -3 ); - var b = new Complex( 7, 13 ); + const a = new Complex( 2, -3 ); + const b = new Complex( 7, 13 ); approximateComplexEquals( assert, a.times( b ).dividedBy( b ), a, 'Canceling' ); } ); @@ -45,10 +45,10 @@ define( require => { approximateComplexEquals( assert, new Complex( 3, 4 ).sqrtOf(), new Complex( 2, 1 ), 'Division' ); approximateComplexEquals( assert, new Complex( 3, -4 ).sqrtOf(), new Complex( 2, -1 ), 'Division' ); - var c = new Complex( 2.5, -7.1 ); + const c = new Complex( 2.5, -7.1 ); approximateComplexEquals( assert, c.sqrtOf().times( c.sqrtOf() ), c ); - var cc = c.plus( c ); + const cc = c.plus( c ); new Complex( cc.x, cc.y ).sqrtOf(); // eslint-disable-line } ); @@ -57,14 +57,14 @@ define( require => { } ); QUnit.test( 'Cos of', function( assert ) { - var a = new Complex( 1, 1 ); - var b = new Complex( 0.8337300251311491, -0.9888977057628651 ); + const a = new Complex( 1, 1 ); + const b = new Complex( 0.8337300251311491, -0.9888977057628651 ); approximateComplexEquals( assert, a.cosOf(), b, 'Cos Of' ); } ); QUnit.test( 'Sin of', function( assert ) { - var a = new Complex( 1, 1 ); - var b = new Complex( 1.29845758, 0.634963914 ); + const a = new Complex( 1, 1 ); + const b = new Complex( 1.29845758, 0.634963914 ); approximateComplexEquals( assert, a.sinOf(), b, 'Sin Of' ); } ); } ); \ No newline at end of file diff --git a/js/ConvexHull2.js b/js/ConvexHull2.js index 5348bff..6ddf92b 100644 --- a/js/ConvexHull2.js +++ b/js/ConvexHull2.js @@ -50,7 +50,7 @@ define( require => { return p2.minus( p1 ).crossScalar( p3.minus( p1 ) ); } - var ConvexHull2 = { + const ConvexHull2 = { // TODO testing: all collinear, multiple ways of having same angle, etc. /** @@ -69,8 +69,8 @@ define( require => { } // find the point 'p' with the lowest y value - var minY = Number.POSITIVE_INFINITY; - var p = null; + let minY = Number.POSITIVE_INFINITY; + let p = null; _.each( points, function( point ) { if ( point.y <= minY ) { // if two points have the same y value, take the one with the lowest x @@ -95,7 +95,7 @@ define( require => { points.splice( _.indexOf( points, p ), 1 ); // our result array - var result = [ p ]; + const result = [ p ]; _.each( points, function( point ) { // ignore points equal to our starting point @@ -105,7 +105,7 @@ define( require => { if ( result.length < 2 ) { return false; } - var cross = ccw( result[ result.length - 2 ], result[ result.length - 1 ], point ); + const cross = ccw( result[ result.length - 2 ], result[ result.length - 1 ], point ); return includeCollinear ? ( cross < 0 ) : ( cross <= 0 ); } diff --git a/js/DampedHarmonic.js b/js/DampedHarmonic.js index 300cbfc..f24ecb7 100644 --- a/js/DampedHarmonic.js +++ b/js/DampedHarmonic.js @@ -96,7 +96,7 @@ define( require => { return ( this.c1 + this.c2 * t ) * Math.exp( -this.angularFrequency * t ); } else if ( this.solutionType === DampedHarmonic.UNDER_DAMPED ) { - var theta = this.frequency * t; + const theta = this.frequency * t; return Math.exp( -( this.dampingConstant / 2 ) * t ) * ( this.c1 * Math.cos( theta ) + this.c2 * Math.sin( theta ) ); } else if ( this.solutionType === DampedHarmonic.OVER_DAMPED ) { @@ -119,11 +119,11 @@ define( require => { return Math.exp( -this.angularFrequency * t ) * ( this.c2 - this.angularFrequency * ( this.c1 + this.c2 * t ) ); } else if ( this.solutionType === DampedHarmonic.UNDER_DAMPED ) { - var theta = this.frequency * t; - var cos = Math.cos( theta ); - var sin = Math.sin( theta ); - var term1 = this.frequency * ( this.c2 * cos - this.c1 * sin ); - var term2 = 0.5 * this.dampingConstant * ( this.c1 * cos + this.c2 * sin ); + const theta = this.frequency * t; + const cos = Math.cos( theta ); + const sin = Math.sin( theta ); + const term1 = this.frequency * ( this.c2 * cos - this.c1 * sin ); + const term2 = 0.5 * this.dampingConstant * ( this.c1 * cos + this.c2 * sin ); return Math.exp( -0.5 * this.dampingConstant * t ) * ( term1 - term2 ); } else if ( this.solutionType === DampedHarmonic.OVER_DAMPED ) { diff --git a/js/DampedHarmonicTests.js b/js/DampedHarmonicTests.js index 218ad15..1ba6fa0 100644 --- a/js/DampedHarmonicTests.js +++ b/js/DampedHarmonicTests.js @@ -23,7 +23,7 @@ define( require => { } function runHarmonic( a, b, c, initialValue, initialDerivative, assert ) { - var harmonic = new DampedHarmonic( a, b, c, initialValue, initialDerivative ); + const harmonic = new DampedHarmonic( a, b, c, initialValue, initialDerivative ); approxEquals( assert, harmonic.getValue( 0 ), initialValue, 'Initial value' ); approxEquals( assert, harmonic.getDerivative( 0 ), initialDerivative, 'Initial derivative' ); diff --git a/js/DelaunayTriangulation.js b/js/DelaunayTriangulation.js index b288145..abf7a44 100644 --- a/js/DelaunayTriangulation.js +++ b/js/DelaunayTriangulation.js @@ -37,7 +37,7 @@ define( require => { }, options ); - var i; + let i; // @public {Array.} this.points = points; @@ -66,9 +66,9 @@ define( require => { } ); for ( i = 0; i < this.constraints.length; i++ ) { - var constraint = this.constraints[ i ]; - var firstIndex = constraint[ 0 ]; - var secondIndex = constraint[ 1 ]; + const constraint = this.constraints[ i ]; + const firstIndex = constraint[ 0 ]; + const secondIndex = constraint[ 1 ]; assert && assert( typeof firstIndex === 'number' && isFinite( firstIndex ) && firstIndex % 1 === 0 && firstIndex >= 0 && firstIndex < points.length ); assert && assert( typeof secondIndex === 'number' && isFinite( secondIndex ) && secondIndex % 1 === 0 && secondIndex >= 0 && secondIndex < points.length ); assert && assert( firstIndex !== secondIndex ); @@ -79,10 +79,10 @@ define( require => { this.vertices.sort( DelaunayTriangulation.vertexComparison ); for ( i = 0; i < this.vertices.length; i++ ) { - var vertex = this.vertices[ i ]; + const vertex = this.vertices[ i ]; vertex.sortedIndex = i; - for ( var j = vertex.constrainedVertices.length - 1; j >= 0; j-- ) { - var otherVertex = vertex.constrainedVertices[ j ]; + for ( let j = vertex.constrainedVertices.length - 1; j >= 0; j-- ) { + const otherVertex = vertex.constrainedVertices[ j ]; // If the "other" vertex is later in the sweep-line order, it should have the reference to the earlier vertex, // not the other way around. @@ -99,12 +99,12 @@ define( require => { // @private {Array.} - Our initialization will handle our first vertex this.remainingVertices = this.vertices.slice( 1 ); - var bounds = Bounds2.NOTHING.copy(); + const bounds = Bounds2.NOTHING.copy(); for ( i = points.length - 1; i >= 0; i-- ) { bounds.addPoint( points[ i ] ); } - var alpha = 0.4; + const alpha = 0.4; // @private {Vertex} - Fake index -1 this.artificialMinVertex = new Vertex( new Vector2( bounds.minX - bounds.width * alpha, bounds.minY - bounds.height * alpha ), -1 ); // @private {Vertex} - Fake index -2 @@ -135,16 +135,16 @@ define( require => { */ step: function() { // TODO: reverse the array prior to this? - var vertex = this.remainingVertices.shift(); + const vertex = this.remainingVertices.shift(); - var x = vertex.point.x; + const x = vertex.point.x; - var frontEdge = this.firstFrontEdge; + let frontEdge = this.firstFrontEdge; while ( frontEdge ) { // TODO: epsilon needed here? if ( x > frontEdge.endVertex.point.x ) { - var edge1 = new Edge( frontEdge.startVertex, vertex ); - var edge2 = new Edge( vertex, frontEdge.endVertex ); + const edge1 = new Edge( frontEdge.startVertex, vertex ); + const edge2 = new Edge( vertex, frontEdge.endVertex ); edge1.connectAfter( edge2 ); this.edges.push( edge1 ); this.edges.push( edge2 ); @@ -157,17 +157,17 @@ define( require => { break; } else if ( x === frontEdge.endVertex.point.x ) { - var leftOldEdge = frontEdge.nextEdge; - var rightOldEdge = frontEdge; + const leftOldEdge = frontEdge.nextEdge; + const rightOldEdge = frontEdge; assert && assert( leftOldEdge !== null ); - var middleOldVertex = frontEdge.endVertex; - var leftVertex = leftOldEdge.endVertex; - var rightVertex = rightOldEdge.startVertex; + const middleOldVertex = frontEdge.endVertex; + const leftVertex = leftOldEdge.endVertex; + const rightVertex = rightOldEdge.startVertex; - var leftEdge = new Edge( vertex, leftVertex ); - var rightEdge = new Edge( rightVertex, vertex ); - var middleEdge = new Edge( middleOldVertex, vertex ); + const leftEdge = new Edge( vertex, leftVertex ); + const rightEdge = new Edge( rightVertex, vertex ); + const middleEdge = new Edge( middleOldVertex, vertex ); rightEdge.connectAfter( leftEdge ); this.edges.push( leftEdge ); this.edges.push( rightEdge ); @@ -215,7 +215,7 @@ define( require => { assert && assert( secondSideVertex === secondEdge.startVertex || secondSideVertex === secondEdge.endVertex, 'secondSideVertex should be in secondEdge' ); - var newEdge = new Edge( firstSideVertex, secondSideVertex ); + const newEdge = new Edge( firstSideVertex, secondSideVertex ); this.edges.push( newEdge ); this.triangles.push( new Triangle( secondSideVertex, middleVertex, firstSideVertex, firstEdge, newEdge, secondEdge ) ); @@ -242,8 +242,8 @@ define( require => { * @param {Edge} newLeftEdge */ reconnectFrontEdges: function( oldRightEdge, oldLeftEdge, newRightEdge, newLeftEdge ) { - var previousEdge = oldRightEdge.previousEdge; - var nextEdge = oldLeftEdge.nextEdge; + const previousEdge = oldRightEdge.previousEdge; + const nextEdge = oldLeftEdge.nextEdge; if ( previousEdge ) { previousEdge.disconnectAfter(); previousEdge.connectAfter( newRightEdge ); @@ -267,13 +267,13 @@ define( require => { addHalfPiHeuristic: function( rightFrontEdge, leftFrontEdge ) { assert && assert( rightFrontEdge.endVertex === leftFrontEdge.startVertex ); - var middleVertex = rightFrontEdge.endVertex; + const middleVertex = rightFrontEdge.endVertex; while ( rightFrontEdge.previousEdge && Util.triangleAreaSigned( middleVertex.point, rightFrontEdge.startVertex.point, rightFrontEdge.previousEdge.startVertex.point ) > 0 && ( middleVertex.point.minus( rightFrontEdge.startVertex.point ) ).angleBetween( rightFrontEdge.previousEdge.startVertex.point.minus( rightFrontEdge.startVertex.point ) ) < Math.PI / 2 ) { - var previousEdge = rightFrontEdge.previousEdge; - var newRightEdge = new Edge( previousEdge.startVertex, middleVertex ); + const previousEdge = rightFrontEdge.previousEdge; + const newRightEdge = new Edge( previousEdge.startVertex, middleVertex ); this.edges.push( newRightEdge ); this.triangles.push( new Triangle( middleVertex, rightFrontEdge.startVertex, previousEdge.startVertex, previousEdge, newRightEdge, rightFrontEdge ) ); @@ -287,8 +287,8 @@ define( require => { while ( leftFrontEdge.nextEdge && Util.triangleAreaSigned( middleVertex.point, leftFrontEdge.nextEdge.endVertex.point, leftFrontEdge.endVertex.point ) > 0 && ( middleVertex.point.minus( leftFrontEdge.endVertex.point ) ).angleBetween( leftFrontEdge.nextEdge.endVertex.point.minus( leftFrontEdge.endVertex.point ) ) < Math.PI / 2 ) { - var nextEdge = leftFrontEdge.nextEdge; - var newLeftEdge = new Edge( middleVertex, nextEdge.endVertex ); + const nextEdge = leftFrontEdge.nextEdge; + const newLeftEdge = new Edge( middleVertex, nextEdge.endVertex ); this.edges.push( newLeftEdge ); this.triangles.push( new Triangle( middleVertex, leftFrontEdge.nextEdge.endVertex, leftFrontEdge.endVertex, nextEdge, leftFrontEdge, newLeftEdge ) ); @@ -316,30 +316,30 @@ define( require => { assert && assert( vertex === rightFrontEdge.endVertex ); assert && assert( vertex === leftFrontEdge.startVertex ); - for ( var i = 0; i < vertex.constrainedVertices.length; i++ ) { - var bottomVertex = vertex.constrainedVertices[ i ]; + for ( let i = 0; i < vertex.constrainedVertices.length; i++ ) { + const bottomVertex = vertex.constrainedVertices[ i ]; // Check if it's one of our front edge vertices (if so, bail out, since the edge already exists) if ( bottomVertex === rightFrontEdge.startVertex || bottomVertex === leftFrontEdge.endVertex ) { break; } - var leftEdges = []; - var rightEdges = []; - var currentTriangle = null; - var currentEdge = null; - var trianglesToRemove = []; - var edgesToRemove = []; + const leftEdges = []; + const rightEdges = []; + let currentTriangle = null; + let currentEdge = null; + const trianglesToRemove = []; + const edgesToRemove = []; - var outsideRight = DelaunayTriangulation.vertexProduct( vertex, rightFrontEdge.startVertex, bottomVertex ) > 0; - var outsideLeft = DelaunayTriangulation.vertexProduct( vertex, leftFrontEdge.endVertex, bottomVertex ) < 0; + let outsideRight = DelaunayTriangulation.vertexProduct( vertex, rightFrontEdge.startVertex, bottomVertex ) > 0; + let outsideLeft = DelaunayTriangulation.vertexProduct( vertex, leftFrontEdge.endVertex, bottomVertex ) < 0; // If we start inside, we need to identify which triangle we're inside of. if ( !outsideRight && !outsideLeft ) { assert && assert( rightFrontEdge.triangles.length === 1 ); assert && assert( leftFrontEdge.triangles.length === 1 ); - var lastVertex = rightFrontEdge.startVertex; + let lastVertex = rightFrontEdge.startVertex; var nextVertex; currentTriangle = rightFrontEdge.triangles[ 0 ]; // TODO: Triangle operations to make this more readable @@ -373,7 +373,7 @@ define( require => { } else { if ( currentEdge.triangles.length > 1 ) { - var nextTriangle = currentEdge.getOtherTriangle( currentTriangle ); + const nextTriangle = currentEdge.getOtherTriangle( currentTriangle ); if ( nextTriangle.hasVertex( bottomVertex ) ) { // TODO: do things! @@ -423,7 +423,7 @@ define( require => { } for ( var j = 0; j < trianglesToRemove.length; j++ ) { - var triangleToRemove = trianglesToRemove[ j ]; + const triangleToRemove = trianglesToRemove[ j ]; arrayRemove( this.triangles, triangleToRemove ); triangleToRemove.remove(); } @@ -432,7 +432,7 @@ define( require => { arrayRemove( this.edges, edgesToRemove[ j ] ); } - var constraintEdge = new Edge( bottomVertex, vertex ); + const constraintEdge = new Edge( bottomVertex, vertex ); constraintEdge.isConstrained = true; this.edges.push( constraintEdge ); leftEdges.push( constraintEdge ); @@ -456,49 +456,49 @@ define( require => { triangulatePolygon: function( edges ) { // TODO: Something more efficient than ear clipping method below while ( edges.length > 3 ) { - for ( var k = 0; k < edges.length; k++ ) { - var kx = k < edges.length - 1 ? k + 1 : 0; + for ( let k = 0; k < edges.length; k++ ) { + const kx = k < edges.length - 1 ? k + 1 : 0; assert && assert( edges[ k ].getSharedVertex( edges[ kx ] ) ); } // Check if each triple of vertices is an ear (and if so, remove it) - for ( var i = 0; i < edges.length; i++ ) { + for ( let i = 0; i < edges.length; i++ ) { // Next index - var ix = i < edges.length - 1 ? i + 1 : 0; + const ix = i < edges.length - 1 ? i + 1 : 0; // Information about our potential ear - var edge = edges[ i ]; - var nextEdge = edges[ ix ]; - var sharedVertex = edge.getSharedVertex( nextEdge ); - var startVertex = edge.getOtherVertex( sharedVertex ); - var endVertex = nextEdge.getOtherVertex( sharedVertex ); + const edge = edges[ i ]; + const nextEdge = edges[ ix ]; + const sharedVertex = edge.getSharedVertex( nextEdge ); + const startVertex = edge.getOtherVertex( sharedVertex ); + const endVertex = nextEdge.getOtherVertex( sharedVertex ); if ( Util.triangleAreaSigned( startVertex.point, sharedVertex.point, endVertex.point ) <= 0 ) { continue; } // Variables for computing barycentric coordinates - var endDelta = endVertex.point.minus( sharedVertex.point ); - var startDelta = startVertex.point.minus( sharedVertex.point ); - var endMagnitudeSquared = endDelta.dot( endDelta ); - var startEndProduct = endDelta.dot( startDelta ); - var startMagnitudeSquared = startDelta.dot( startDelta ); - var x = endMagnitudeSquared * startMagnitudeSquared - startEndProduct * startEndProduct; + const endDelta = endVertex.point.minus( sharedVertex.point ); + const startDelta = startVertex.point.minus( sharedVertex.point ); + const endMagnitudeSquared = endDelta.dot( endDelta ); + const startEndProduct = endDelta.dot( startDelta ); + const startMagnitudeSquared = startDelta.dot( startDelta ); + const x = endMagnitudeSquared * startMagnitudeSquared - startEndProduct * startEndProduct; // See if there are other vertices in our triangle (it wouldn't be an ear if there is another in it) - var lastVertex = edges[ 0 ].getSharedVertex( edges[ edges.length - 1 ] ); - var hasInteriorVertex = false; - for ( var j = 0; j < edges.length; j++ ) { - var vertex = edges[ j ].getOtherVertex( lastVertex ); + let lastVertex = edges[ 0 ].getSharedVertex( edges[ edges.length - 1 ] ); + let hasInteriorVertex = false; + for ( let j = 0; j < edges.length; j++ ) { + const vertex = edges[ j ].getOtherVertex( lastVertex ); if ( vertex !== sharedVertex && vertex !== startVertex && vertex !== endVertex ) { - var pointDelta = vertex.point.minus( sharedVertex.point ); - var pointEndProduct = endDelta.dot( pointDelta ); - var pointStartProduct = startDelta.dot( pointDelta ); + const pointDelta = vertex.point.minus( sharedVertex.point ); + const pointEndProduct = endDelta.dot( pointDelta ); + const pointStartProduct = startDelta.dot( pointDelta ); // Compute barycentric coordinates - var u = ( startMagnitudeSquared * pointEndProduct - startEndProduct * pointStartProduct ) / x; - var v = ( endMagnitudeSquared * pointStartProduct - startEndProduct * pointEndProduct ) / x; + const u = ( startMagnitudeSquared * pointEndProduct - startEndProduct * pointStartProduct ) / x; + const v = ( endMagnitudeSquared * pointStartProduct - startEndProduct * pointEndProduct ) / x; // Test for whether the point is in our triangle if ( u >= -1e-10 && v >= -1e-10 && u + v < 1 + 1e-10 ) { @@ -512,7 +512,7 @@ define( require => { // If there is no interior vertex, then we reached an ear. if ( !hasInteriorVertex ) { - var newEdge = new Edge( startVertex, endVertex ); + const newEdge = new Edge( startVertex, endVertex ); this.edges.push( newEdge ); this.triangles.push( new Triangle( startVertex, sharedVertex, endVertex, nextEdge, newEdge, edge ) ); @@ -546,14 +546,14 @@ define( require => { */ finalize: function() { // Accumulate front edges, excluding the first and last. - var frontEdges = []; - var frontEdge = this.firstFrontEdge.nextEdge; + const frontEdges = []; + let frontEdge = this.firstFrontEdge.nextEdge; while ( frontEdge && frontEdge.nextEdge ) { frontEdges.push( frontEdge ); frontEdge = frontEdge.nextEdge; } - var firstFrontEdge = this.firstFrontEdge; - var lastFrontEdge = frontEdge; + const firstFrontEdge = this.firstFrontEdge; + const lastFrontEdge = frontEdge; assert && assert( this.firstFrontEdge.triangles.length === 1 ); assert && assert( lastFrontEdge.triangles.length === 1 ); @@ -576,15 +576,15 @@ define( require => { this.firstFrontEdge = null; // Accumulate back edges and items to get rid of - var backEdges = []; - var artificialEdges = [ firstFrontEdge ]; - var currentSplitEdge = firstFrontEdge; + const backEdges = []; + const artificialEdges = [ firstFrontEdge ]; + let currentSplitEdge = firstFrontEdge; while ( currentSplitEdge !== lastFrontEdge ) { - var nextTriangle = currentSplitEdge.triangles[ 0 ]; + const nextTriangle = currentSplitEdge.triangles[ 0 ]; nextTriangle.remove(); arrayRemove( this.triangles, nextTriangle ); - var edge = nextTriangle.getNonArtificialEdge(); + const edge = nextTriangle.getNonArtificialEdge(); if ( edge ) { backEdges.push( edge ); var sharedVertex = edge.getSharedVertex( currentSplitEdge ); @@ -616,8 +616,8 @@ define( require => { secondEdge = backEdges[ i ]; sharedVertex = firstEdge.getSharedVertex( secondEdge ); - var firstVertex = firstEdge.getOtherVertex( sharedVertex ); - var secondVertex = secondEdge.getOtherVertex( sharedVertex ); + const firstVertex = firstEdge.getOtherVertex( sharedVertex ); + const secondVertex = secondEdge.getOtherVertex( sharedVertex ); if ( Util.triangleAreaSigned( secondVertex.point, sharedVertex.point, firstVertex.point ) > 1e-10 ) { newEdge = this.fillBorderTriangle( firstEdge, secondEdge, firstVertex, sharedVertex, secondVertex ); backEdges.splice( i, 2, newEdge ); @@ -652,11 +652,11 @@ define( require => { return; } - var triangle1 = edge.triangles[ 0 ]; - var triangle2 = edge.triangles[ 1 ]; + const triangle1 = edge.triangles[ 0 ]; + const triangle2 = edge.triangles[ 1 ]; - var farVertex1 = triangle1.getVertexOppositeFromEdge( edge ); - var farVertex2 = triangle2.getVertexOppositeFromEdge( edge ); + const farVertex1 = triangle1.getVertexOppositeFromEdge( edge ); + const farVertex2 = triangle2.getVertexOppositeFromEdge( edge ); if ( Util.pointInCircleFromPoints( triangle1.aVertex.point, triangle1.bVertex.point, triangle1.cVertex.point, farVertex2.point ) || Util.pointInCircleFromPoints( triangle2.aVertex.point, triangle2.bVertex.point, triangle2.cVertex.point, farVertex1.point ) ) { @@ -667,13 +667,13 @@ define( require => { arrayRemove( this.triangles, triangle2 ); arrayRemove( this.edges, edge ); - var newEdge = new Edge( farVertex1, farVertex2 ); + const newEdge = new Edge( farVertex1, farVertex2 ); this.edges.push( newEdge ); - var triangle1Edge1 = triangle2.getEdgeOppositeFromVertex( triangle2.getVertexBefore( farVertex2 ) ); - var triangle1Edge2 = triangle1.getEdgeOppositeFromVertex( triangle1.getVertexAfter( farVertex1 ) ); - var triangle2Edge1 = triangle1.getEdgeOppositeFromVertex( triangle1.getVertexBefore( farVertex1 ) ); - var triangle2Edge2 = triangle2.getEdgeOppositeFromVertex( triangle2.getVertexAfter( farVertex2 ) ); + const triangle1Edge1 = triangle2.getEdgeOppositeFromVertex( triangle2.getVertexBefore( farVertex2 ) ); + const triangle1Edge2 = triangle1.getEdgeOppositeFromVertex( triangle1.getVertexAfter( farVertex1 ) ); + const triangle2Edge1 = triangle1.getEdgeOppositeFromVertex( triangle1.getVertexBefore( farVertex1 ) ); + const triangle2Edge2 = triangle2.getEdgeOppositeFromVertex( triangle2.getVertexAfter( farVertex2 ) ); // Construct the new triangles with the correct orientations this.triangles.push( new Triangle( farVertex1, farVertex2, triangle1.getVertexBefore( farVertex1 ), @@ -734,8 +734,8 @@ define( require => { * @returns {number} */ vertexProduct: function( sharedVertex, aVertex, bVertex ) { - var aDiff = aVertex.point.minus( sharedVertex.point ); - var bDiff = bVertex.point.minus( sharedVertex.point ); + const aDiff = aVertex.point.minus( sharedVertex.point ); + const bDiff = bVertex.point.minus( sharedVertex.point ); return aDiff.crossScalar( bDiff ); } } ); @@ -874,9 +874,9 @@ define( require => { getSharedTriangle: function( otherEdge ) { assert && assert( otherEdge instanceof Edge ); - for ( var i = 0; i < this.triangles.length; i++ ) { - var triangle = this.triangles[ i ]; - for ( var j = 0; j < otherEdge.triangles.length; j++ ) { + for ( let i = 0; i < this.triangles.length; i++ ) { + const triangle = this.triangles[ i ]; + for ( let j = 0; j < otherEdge.triangles.length; j++ ) { if ( otherEdge.triangles[ j ] === triangle ) { return triangle; } diff --git a/js/EigenvalueDecomposition.js b/js/EigenvalueDecomposition.js index 0bbda8f..9b20b14 100644 --- a/js/EigenvalueDecomposition.js +++ b/js/EigenvalueDecomposition.js @@ -26,7 +26,7 @@ define( require => { const dot = require( 'DOT/dot' ); - var ArrayType = window.Float64Array || Array; + const ArrayType = window.Float64Array || Array; // require( 'DOT/Matrix' ); // commented out so Require.js doesn't complain about the circular dependency @@ -36,12 +36,12 @@ define( require => { * @constructor */ function EigenvalueDecomposition( matrix ) { - var i; - var j; + let i; + let j; - var A = matrix.entries; + const A = matrix.entries; this.n = matrix.getColumnDimension(); // @private Row and column dimension (square matrix). - var n = this.n; + const n = this.n; this.V = new ArrayType( n * n ); // @private Array for internal storage of eigenvectors. // Arrays for internal storage of eigenvalues. @@ -125,14 +125,14 @@ define( require => { * @returns {Matrix} - a n * n matrix */ getD: function() { - var n = this.n; - var d = this.d; - var e = this.e; - - var X = new dot.Matrix( n, n ); - var D = X.entries; - for ( var i = 0; i < n; i++ ) { - for ( var j = 0; j < n; j++ ) { + const n = this.n; + const d = this.d; + const e = this.e; + + const X = new dot.Matrix( n, n ); + const D = X.entries; + for ( let i = 0; i < n; i++ ) { + for ( let j = 0; j < n; j++ ) { D[ i * this.n + j ] = 0.0; } D[ i * this.n + i ] = d[ i ]; @@ -151,16 +151,16 @@ define( require => { * @private */ tred2: function() { - var n = this.n; - var V = this.V; - var d = this.d; - var e = this.e; - var i; - var j; - var k; - var f; - var g; - var h; + const n = this.n; + const V = this.V; + const d = this.d; + const e = this.e; + let i; + let j; + let k; + let f; + let g; + let h; // This is derived from the Algol procedures tred2 by // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for @@ -177,7 +177,7 @@ define( require => { // Scale to avoid under/overflow. - var scale = 0.0; + let scale = 0.0; h = 0.0; for ( k = 0; k < i; k++ ) { scale = scale + Math.abs( d[ k ] ); @@ -227,7 +227,7 @@ define( require => { e[ j ] /= h; f += e[ j ] * d[ j ]; } - var hh = f / (h + h); + const hh = f / (h + h); for ( j = 0; j < i; j++ ) { e[ j ] -= hh * d[ j ]; } @@ -281,17 +281,17 @@ define( require => { * @private */ tql2: function() { - var n = this.n; - var V = this.V; - var d = this.d; - var e = this.e; - var i; - var j; - var k; - var l; - var g; - var p; - var iter; + const n = this.n; + const V = this.V; + const d = this.d; + const e = this.e; + let i; + let j; + let k; + let l; + let g; + let p; + let iter; // This is derived from the Algol procedures tql2, by // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for @@ -303,15 +303,15 @@ define( require => { } e[ n - 1 ] = 0.0; - var f = 0.0; - var tst1 = 0.0; - var eps = Math.pow( 2.0, -52.0 ); + let f = 0.0; + let tst1 = 0.0; + const eps = Math.pow( 2.0, -52.0 ); for ( l = 0; l < n; l++ ) { // Find small subdiagonal element tst1 = Math.max( tst1, Math.abs( d[ l ] ) + Math.abs( e[ l ] ) ); - var m = l; + let m = l; while ( m < n ) { if ( Math.abs( e[ m ] ) <= eps * tst1 ) { break; @@ -331,14 +331,14 @@ define( require => { g = d[ l ]; p = (d[ l + 1 ] - g) / (2.0 * e[ l ]); - var r = dot.Matrix.hypot( p, 1.0 ); + let r = dot.Matrix.hypot( p, 1.0 ); if ( p < 0 ) { r = -r; } d[ l ] = e[ l ] / (p + r); d[ l + 1 ] = e[ l ] * (p + r); - var dl1 = d[ l + 1 ]; - var h = g - d[ l ]; + const dl1 = d[ l + 1 ]; + let h = g - d[ l ]; for ( i = l + 2; i < n; i++ ) { d[ i ] -= h; } @@ -347,12 +347,12 @@ define( require => { // Implicit QL transformation. p = d[ m ]; - var c = 1.0; - var c2 = c; - var c3 = c; - var el1 = e[ l + 1 ]; - var s = 0.0; - var s2 = 0.0; + let c = 1.0; + let c2 = c; + let c3 = c; + const el1 = e[ l + 1 ]; + let s = 0.0; + let s2 = 0.0; for ( i = m - 1; i >= l; i-- ) { c3 = c2; c2 = c; @@ -414,29 +414,29 @@ define( require => { * @private */ orthes: function() { - var n = this.n; - var V = this.V; - var H = this.H; - var ort = this.ort; - var i; - var j; - var m; - var f; - var g; + const n = this.n; + const V = this.V; + const H = this.H; + const ort = this.ort; + let i; + let j; + let m; + let f; + let g; // This is derived from the Algol procedures orthes and ortran, // by Martin and Wilkinson, Handbook for Auto. Comp., // Vol.ii-Linear Algebra, and the corresponding // Fortran subroutines in EISPACK. - var low = 0; - var high = n - 1; + const low = 0; + const high = n - 1; for ( m = low + 1; m <= high - 1; m++ ) { // Scale column. - var scale = 0.0; + let scale = 0.0; for ( i = m; i <= high; i++ ) { scale = scale + Math.abs( H[ i * n + (m - 1) ] ); } @@ -444,7 +444,7 @@ define( require => { // Compute Householder transformation. - var h = 0.0; + let h = 0.0; for ( i = high; i >= m; i-- ) { ort[ i ] = H[ i * n + (m - 1) ] / scale; h += ort[ i ] * ort[ i ]; @@ -515,8 +515,8 @@ define( require => { // Complex scalar division. cdiv: function( xr, xi, yr, yi ) { - var r; - var d; + let r; + let d; if ( Math.abs( yr ) > Math.abs( yi ) ) { r = yi / yr; d = yr + r * yi; @@ -541,17 +541,17 @@ define( require => { * @private */ hqr2: function() { - var n; - var V = this.V; - var d = this.d; - var e = this.e; - var H = this.H; - var i; - var j; - var k; - var l; - var m; - var iter; + let n; + const V = this.V; + const d = this.d; + const e = this.e; + const H = this.H; + let i; + let j; + let k; + let l; + let m; + let iter; // This is derived from the Algol procedure hqr2, // by Martin and Wilkinson, Handbook for Auto. Comp., @@ -560,25 +560,25 @@ define( require => { // Initialize - var nn = this.n; + const nn = this.n; n = nn - 1; - var low = 0; - var high = nn - 1; - var eps = Math.pow( 2.0, -52.0 ); - var exshift = 0.0; - var p = 0; - var q = 0; - var r = 0; - var s = 0; - var z = 0; - var t; - var w; - var x; - var y; + const low = 0; + const high = nn - 1; + const eps = Math.pow( 2.0, -52.0 ); + let exshift = 0.0; + let p = 0; + let q = 0; + let r = 0; + let s = 0; + let z = 0; + let t; + let w; + let x; + let y; // Store roots isolated by balanc and compute matrix norm - var norm = 0.0; + let norm = 0.0; for ( i = 0; i < nn; i++ ) { if ( i < low || i > high ) { d[ i ] = H[ i * n + i ]; @@ -773,7 +773,7 @@ define( require => { // Double QR step involving rows l:n and columns m:n for ( k = m; k <= n - 1; k++ ) { - var notlast = (k !== n - 1); + const notlast = (k !== n - 1); if ( k !== m ) { p = H[ k * n + k - 1 ]; q = H[ (k + 1) * n + k - 1 ]; diff --git a/js/LUDecomposition.js b/js/LUDecomposition.js index 63db0ad..0dc017d 100644 --- a/js/LUDecomposition.js +++ b/js/LUDecomposition.js @@ -11,30 +11,30 @@ define( require => { const dot = require( 'DOT/dot' ); - var ArrayType = window.Float64Array || Array; + const ArrayType = window.Float64Array || Array; // require( 'DOT/Matrix' ); // commented out so Require.js doesn't complain about the circular dependency function LUDecomposition( matrix ) { - var i; - var j; - var k; + let i; + let j; + let k; this.matrix = matrix; // TODO: size! this.LU = matrix.getArrayCopy(); - var LU = this.LU; + const LU = this.LU; this.m = matrix.getRowDimension(); - var m = this.m; + const m = this.m; this.n = matrix.getColumnDimension(); - var n = this.n; + const n = this.n; this.piv = new Uint32Array( m ); for ( i = 0; i < m; i++ ) { this.piv[ i ] = i; } this.pivsign = 1; - var LUcolj = new ArrayType( m ); + const LUcolj = new ArrayType( m ); // Outer loop. @@ -49,10 +49,10 @@ define( require => { for ( i = 0; i < m; i++ ) { // Most of the time is spent in the following dot product. - var kmax = Math.min( i, j ); - var s = 0.0; + const kmax = Math.min( i, j ); + let s = 0.0; for ( k = 0; k < kmax; k++ ) { - var ik = matrix.index( i, k ); + const ik = matrix.index( i, k ); s += LU[ ik ] * LUcolj[ k ]; } @@ -62,7 +62,7 @@ define( require => { // Find pivot and exchange if necessary. - var p = j; + let p = j; for ( i = j + 1; i < m; i++ ) { if ( Math.abs( LUcolj[ i ] ) > Math.abs( LUcolj[ p ] ) ) { p = i; @@ -70,9 +70,9 @@ define( require => { } if ( p !== j ) { for ( k = 0; k < n; k++ ) { - var pk = matrix.index( p, k ); - var jk = matrix.index( j, k ); - var t = LU[ pk ]; + const pk = matrix.index( p, k ); + const jk = matrix.index( j, k ); + const t = LU[ pk ]; LU[ pk ] = LU[ jk ]; LU[ jk ] = t; } @@ -98,8 +98,8 @@ define( require => { constructor: LUDecomposition, isNonsingular: function() { - for ( var j = 0; j < this.n; j++ ) { - var index = this.matrix.index( j, j ); + for ( let j = 0; j < this.n; j++ ) { + const index = this.matrix.index( j, j ); if ( this.LU[ index ] === 0 ) { return false; } @@ -108,9 +108,9 @@ define( require => { }, getL: function() { - var result = new dot.Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + const result = new dot.Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { if ( i > j ) { result.entries[ result.index( i, j ) ] = this.LU[ this.matrix.index( i, j ) ]; } @@ -126,9 +126,9 @@ define( require => { }, getU: function() { - var result = new dot.Matrix( this.n, this.n ); - for ( var i = 0; i < this.n; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + const result = new dot.Matrix( this.n, this.n ); + for ( let i = 0; i < this.n; i++ ) { + for ( let j = 0; j < this.n; j++ ) { if ( i <= j ) { result.entries[ result.index( i, j ) ] = this.LU[ this.matrix.index( i, j ) ]; } @@ -141,16 +141,16 @@ define( require => { }, getPivot: function() { - var p = new Uint32Array( this.m ); - for ( var i = 0; i < this.m; i++ ) { + const p = new Uint32Array( this.m ); + for ( let i = 0; i < this.m; i++ ) { p[ i ] = this.piv[ i ]; } return p; }, getDoublePivot: function() { - var vals = new ArrayType( this.m ); - for ( var i = 0; i < this.m; i++ ) { + const vals = new ArrayType( this.m ); + for ( let i = 0; i < this.m; i++ ) { vals[ i ] = this.piv[ i ]; } return vals; @@ -160,17 +160,17 @@ define( require => { if ( this.m !== this.n ) { throw new Error( 'Matrix must be square.' ); } - var d = this.pivsign; - for ( var j = 0; j < this.n; j++ ) { + let d = this.pivsign; + for ( let j = 0; j < this.n; j++ ) { d *= this.LU[ this.matrix.index( j, j ) ]; } return d; }, solve: function( matrix ) { - var i; - var j; - var k; + let i; + let j; + let k; if ( matrix.getRowDimension() !== this.m ) { throw new Error( 'Matrix row dimensions must agree.' ); } @@ -179,8 +179,8 @@ define( require => { } // Copy right hand side with pivoting - var nx = matrix.getColumnDimension(); - var Xmat = matrix.getArrayRowMatrix( this.piv, 0, nx - 1 ); + const nx = matrix.getColumnDimension(); + const Xmat = matrix.getArrayRowMatrix( this.piv, 0, nx - 1 ); // Solve L*Y = B(piv,:) for ( k = 0; k < this.n; k++ ) { diff --git a/js/LinearFunction.js b/js/LinearFunction.js index ed258d6..fcf76d0 100644 --- a/js/LinearFunction.js +++ b/js/LinearFunction.js @@ -47,11 +47,11 @@ define( require => { * @param {boolean} clamp * @returns {number} */ - var map = function( a1, a2, b1, b2, a3, clamp ) { - var b3 = dot.Util.linear( a1, a2, b1, b2, a3 ); + const map = function( a1, a2, b1, b2, a3, clamp ) { + let b3 = dot.Util.linear( a1, a2, b1, b2, a3 ); if ( clamp ) { - var max = Math.max( b1, b2 ); - var min = Math.min( b1, b2 ); + const max = Math.max( b1, b2 ); + const min = Math.min( b1, b2 ); b3 = dot.Util.clamp( b3, min, max ); } return b3; @@ -64,7 +64,7 @@ define( require => { * @param {number} a3 * @returns {number} */ - var evaluate = function( a3 ) { + const evaluate = function( a3 ) { return map( a1, a2, b1, b2, a3, clamp ); }; diff --git a/js/LinearFunctionTests.js b/js/LinearFunctionTests.js index 122f8cb..94f114b 100644 --- a/js/LinearFunctionTests.js +++ b/js/LinearFunctionTests.js @@ -19,7 +19,7 @@ define( require => { } QUnit.test( 'LinearFunction', function( assert ) { - var f = new LinearFunction( 4, 8, 8, 0 ); // not clamped + const f = new LinearFunction( 4, 8, 8, 0 ); // not clamped approximateEquals( assert, f( 0 ), 16 ); approximateEquals( assert, f( 4 ), 8 ); @@ -30,7 +30,7 @@ define( require => { approximateEquals( assert, f.inverse( 0 ), 8 ); approximateEquals( assert, f.inverse( 4 ), 6 ); - var g = new LinearFunction( 4, 8, 8, 0, true ); // clamped + const g = new LinearFunction( 4, 8, 8, 0, true ); // clamped approximateEquals( assert, g( 0 ), 8 ); approximateEquals( assert, g( 4 ), 8 ); diff --git a/js/Matrix.js b/js/Matrix.js index 4000116..b851263 100644 --- a/js/Matrix.js +++ b/js/Matrix.js @@ -11,7 +11,7 @@ define( require => { const dot = require( 'DOT/dot' ); - var ArrayType = window.Float64Array || Array; + const ArrayType = window.Float64Array || Array; const isArray = require( 'PHET_CORE/isArray' ); @@ -35,9 +35,9 @@ define( require => { this.m = m; this.n = n; - var size = m * n; + const size = m * n; this.size = size; - var i; + let i; if ( fast ) { this.entries = filler; @@ -69,7 +69,7 @@ define( require => { /** sqrt(a^2 + b^2) without under/overflow. **/ Matrix.hypot = function hypot( a, b ) { - var r; + let r; if ( Math.abs( a ) > Math.abs( b ) ) { r = b / a; r = Math.abs( a ) * Math.sqrt( 1 + r * r ); @@ -88,8 +88,8 @@ define( require => { constructor: Matrix, copy: function() { - var result = new Matrix( this.m, this.n ); - for ( var i = 0; i < this.size; i++ ) { + const result = new Matrix( this.m, this.n ); + for ( let i = 0; i < this.size; i++ ) { result.entries[ i ] = this.entries[ i ]; } return result; @@ -139,9 +139,9 @@ define( require => { }, getMatrix: function( i0, i1, j0, j1 ) { - var result = new Matrix( i1 - i0 + 1, j1 - j0 + 1 ); - for ( var i = i0; i <= i1; i++ ) { - for ( var j = j0; j <= j1; j++ ) { + const result = new Matrix( i1 - i0 + 1, j1 - j0 + 1 ); + for ( let i = i0; i <= i1; i++ ) { + for ( let j = j0; j <= j1; j++ ) { result.entries[ result.index( i - i0, j - j0 ) ] = this.entries[ this.index( i, j ) ]; } } @@ -150,9 +150,9 @@ define( require => { // getMatrix (int[] r, int j0, int j1) getArrayRowMatrix: function( r, j0, j1 ) { - var result = new Matrix( r.length, j1 - j0 + 1 ); - for ( var i = 0; i < r.length; i++ ) { - for ( var j = j0; j <= j1; j++ ) { + const result = new Matrix( r.length, j1 - j0 + 1 ); + for ( let i = 0; i < r.length; i++ ) { + for ( let j = j0; j <= j1; j++ ) { result.entries[ result.index( i, j - j0 ) ] = this.entries[ this.index( r[ i ], j ) ]; } } @@ -164,8 +164,8 @@ define( require => { result = result || new Matrix( this.n, this.m ); assert && assert( result.m === this.n ); assert && assert( result.n === this.m ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { result.entries[ result.index( j, i ) ] = this.entries[ this.index( i, j ) ]; } } @@ -173,10 +173,10 @@ define( require => { }, norm1: function() { - var f = 0; - for ( var j = 0; j < this.n; j++ ) { - var s = 0; - for ( var i = 0; i < this.m; i++ ) { + let f = 0; + for ( let j = 0; j < this.n; j++ ) { + let s = 0; + for ( let i = 0; i < this.m; i++ ) { s += Math.abs( this.entries[ this.index( i, j ) ] ); } f = Math.max( f, s ); @@ -189,10 +189,10 @@ define( require => { }, normInf: function() { - var f = 0; - for ( var i = 0; i < this.m; i++ ) { - var s = 0; - for ( var j = 0; j < this.n; j++ ) { + let f = 0; + for ( let i = 0; i < this.m; i++ ) { + let s = 0; + for ( let j = 0; j < this.n; j++ ) { s += Math.abs( this.entries[ this.index( i, j ) ] ); } f = Math.max( f, s ); @@ -201,9 +201,9 @@ define( require => { }, normF: function() { - var f = 0; - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + let f = 0; + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { f = Matrix.hypot( f, this.entries[ this.index( i, j ) ] ); } } @@ -211,9 +211,9 @@ define( require => { }, uminus: function() { - var result = new Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + const result = new Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { result.entries[ result.index( i, j ) ] = -this.entries[ this.index( i, j ) ]; } } @@ -222,10 +222,10 @@ define( require => { plus: function( matrix ) { this.checkMatrixDimensions( matrix ); - var result = new Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = result.index( i, j ); + const result = new Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = result.index( i, j ); result.entries[ index ] = this.entries[ index ] + matrix.entries[ index ]; } } @@ -234,9 +234,9 @@ define( require => { plusEquals: function( matrix ) { this.checkMatrixDimensions( matrix ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); this.entries[ index ] = this.entries[ index ] + matrix.entries[ index ]; } } @@ -266,10 +266,10 @@ define( require => { minus: function( matrix ) { this.checkMatrixDimensions( matrix ); - var result = new Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + const result = new Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); result.entries[ index ] = this.entries[ index ] - matrix.entries[ index ]; } } @@ -278,9 +278,9 @@ define( require => { minusEquals: function( matrix ) { this.checkMatrixDimensions( matrix ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); this.entries[ index ] = this.entries[ index ] - matrix.entries[ index ]; } } @@ -289,10 +289,10 @@ define( require => { arrayTimes: function( matrix ) { this.checkMatrixDimensions( matrix ); - var result = new Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = result.index( i, j ); + const result = new Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = result.index( i, j ); result.entries[ index ] = this.entries[ index ] * matrix.entries[ index ]; } } @@ -301,9 +301,9 @@ define( require => { arrayTimesEquals: function( matrix ) { this.checkMatrixDimensions( matrix ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); this.entries[ index ] = this.entries[ index ] * matrix.entries[ index ]; } } @@ -312,10 +312,10 @@ define( require => { arrayRightDivide: function( matrix ) { this.checkMatrixDimensions( matrix ); - var result = new Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + const result = new Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); result.entries[ index ] = this.entries[ index ] / matrix.entries[ index ]; } } @@ -324,9 +324,9 @@ define( require => { arrayRightDivideEquals: function( matrix ) { this.checkMatrixDimensions( matrix ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); this.entries[ index ] = this.entries[ index ] / matrix.entries[ index ]; } } @@ -335,10 +335,10 @@ define( require => { arrayLeftDivide: function( matrix ) { this.checkMatrixDimensions( matrix ); - var result = new Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + const result = new Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); result.entries[ index ] = matrix.entries[ index ] / this.entries[ index ]; } } @@ -347,9 +347,9 @@ define( require => { arrayLeftDivideEquals: function( matrix ) { this.checkMatrixDimensions( matrix ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); this.entries[ index ] = matrix.entries[ index ] / this.entries[ index ]; } } @@ -357,19 +357,19 @@ define( require => { }, times: function( matrixOrScalar ) { - var result; - var i; - var j; - var k; - var s; - var matrix; + let result; + let i; + let j; + let k; + let s; + let matrix; if ( matrixOrScalar.isMatrix ) { matrix = matrixOrScalar; if ( matrix.m !== this.n ) { throw new Error( 'Matrix inner dimensions must agree.' ); } result = new Matrix( this.m, matrix.n ); - var matrixcolj = new ArrayType( this.n ); + const matrixcolj = new ArrayType( this.n ); for ( j = 0; j < matrix.n; j++ ) { for ( k = 0; k < this.n; k++ ) { matrixcolj[ k ] = matrix.entries[ matrix.index( k, j ) ]; @@ -397,9 +397,9 @@ define( require => { }, timesEquals: function( s ) { - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { - var index = this.index( i, j ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { + const index = this.index( i, j ); this.entries[ index ] = s * this.entries[ index ]; } } @@ -432,8 +432,8 @@ define( require => { }, trace: function() { - var t = 0; - for ( var i = 0; i < Math.min( this.m, this.n ); i++ ) { + let t = 0; + for ( let i = 0; i < Math.min( this.m, this.n ); i++ ) { t += this.entries[ this.index( i, i ) ]; } return t; @@ -446,10 +446,10 @@ define( require => { }, toString: function() { - var result = ''; + let result = ''; result += 'dim: ' + this.getRowDimension() + 'x' + this.getColumnDimension() + '\n'; - for ( var row = 0; row < this.getRowDimension(); row++ ) { - for ( var col = 0; col < this.getColumnDimension(); col++ ) { + for ( let row = 0; row < this.getRowDimension(); row++ ) { + for ( let col = 0; col < this.getColumnDimension(); col++ ) { result += this.get( row, col ) + ' '; } result += '\n'; @@ -477,14 +477,14 @@ define( require => { // Sets the current matrix to the values of the listed column vectors (Vector3). setVectors3: function( vectors ) { - var m = 3; - var n = vectors.length; + const m = 3; + const n = vectors.length; assert && assert( this.m === m ); assert && assert( this.n === n ); - for ( var i = 0; i < n; i++ ) { - var vector = vectors[ i ]; + for ( let i = 0; i < n; i++ ) { + const vector = vectors[ i ]; this.entries[ i ] = vector.x; this.entries[ i + n ] = vector.y; this.entries[ i + 2 * n ] = vector.z; @@ -497,9 +497,9 @@ define( require => { }; Matrix.identity = function( m, n ) { - var result = new Matrix( m, n ); - for ( var i = 0; i < m; i++ ) { - for ( var j = 0; j < n; j++ ) { + const result = new Matrix( m, n ); + for ( let i = 0; i < m; i++ ) { + for ( let j = 0; j < n; j++ ) { result.entries[ result.index( i, j ) ] = ( i === j ? 1.0 : 0.0 ); } } @@ -515,9 +515,9 @@ define( require => { * @returns {Matrix} */ Matrix.diagonalMatrix = function( diagonalValues ) { - var n = diagonalValues.length; - var result = new Matrix( n, n ); // Should fill in zeros - for ( var i = 0; i < n; i++ ) { + const n = diagonalValues.length; + const result = new Matrix( n, n ); // Should fill in zeros + for ( let i = 0; i < n; i++ ) { result.entries[ result.index( i, i ) ] = diagonalValues[ i ]; } return result; @@ -582,12 +582,12 @@ define( require => { */ Matrix.fromVectors2 = function( vectors ) { - var dimension = 2; - var n = vectors.length; - var data = new ArrayType( dimension * n ); + const dimension = 2; + const n = vectors.length; + const data = new ArrayType( dimension * n ); - for ( var i = 0; i < n; i++ ) { - var vector = vectors[ i ]; + for ( let i = 0; i < n; i++ ) { + const vector = vectors[ i ]; data[ i ] = vector.x; data[ i + n ] = vector.y; } @@ -596,12 +596,12 @@ define( require => { }; Matrix.fromVectors3 = function( vectors ) { - var dimension = 3; - var n = vectors.length; - var data = new ArrayType( dimension * n ); + const dimension = 3; + const n = vectors.length; + const data = new ArrayType( dimension * n ); - for ( var i = 0; i < n; i++ ) { - var vector = vectors[ i ]; + for ( let i = 0; i < n; i++ ) { + const vector = vectors[ i ]; data[ i ] = vector.x; data[ i + n ] = vector.y; data[ i + 2 * n ] = vector.z; @@ -611,12 +611,12 @@ define( require => { }; Matrix.fromVectors4 = function( vectors ) { - var dimension = 4; - var n = vectors.length; - var data = new ArrayType( dimension * n ); + const dimension = 4; + const n = vectors.length; + const data = new ArrayType( dimension * n ); - for ( var i = 0; i < n; i++ ) { - var vector = vectors[ i ]; + for ( let i = 0; i < n; i++ ) { + const vector = vectors[ i ]; data[ i ] = vector.x; data[ i + n ] = vector.y; data[ i + 2 * n ] = vector.z; diff --git a/js/Matrix3.js b/js/Matrix3.js index 2e325f6..f49469f 100644 --- a/js/Matrix3.js +++ b/js/Matrix3.js @@ -185,7 +185,7 @@ define( require => { }, toSVGMatrix: function() { - var result = document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ).createSVGMatrix(); + const result = document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ).createSVGMatrix(); // top two rows result.a = this.m00(); @@ -236,7 +236,7 @@ define( require => { // returns a parameter object suitable for use with jQuery's .css() getCSSTransformStyles: function() { - var transformCSS = this.getCSSTransform(); + const transformCSS = this.getCSSTransform(); // notes on triggering hardware acceleration: http://creativejs.com/2011/12/day-2-gpu-accelerate-your-dom-elements/ return { @@ -315,7 +315,7 @@ define( require => { }, inverted: function() { - var det; + let det; switch( this.type ) { case Types.IDENTITY: @@ -426,28 +426,28 @@ define( require => { *----------------------------------------------------------------------------*/ timesVector2: function( v ) { - var x = this.m00() * v.x + this.m01() * v.y + this.m02(); - var y = this.m10() * v.x + this.m11() * v.y + this.m12(); + const x = this.m00() * v.x + this.m01() * v.y + this.m02(); + const y = this.m10() * v.x + this.m11() * v.y + this.m12(); return new dot.Vector2( x, y ); }, timesVector3: function( v ) { - var x = this.m00() * v.x + this.m01() * v.y + this.m02() * v.z; - var y = this.m10() * v.x + this.m11() * v.y + this.m12() * v.z; - var z = this.m20() * v.x + this.m21() * v.y + this.m22() * v.z; + const x = this.m00() * v.x + this.m01() * v.y + this.m02() * v.z; + const y = this.m10() * v.x + this.m11() * v.y + this.m12() * v.z; + const z = this.m20() * v.x + this.m21() * v.y + this.m22() * v.z; return new dot.Vector3( x, y, z ); }, timesTransposeVector2: function( v ) { - var x = this.m00() * v.x + this.m10() * v.y; - var y = this.m01() * v.x + this.m11() * v.y; + const x = this.m00() * v.x + this.m10() * v.y; + const y = this.m01() * v.x + this.m11() * v.y; return new dot.Vector2( x, y ); }, // TODO: this operation seems to not work for transformDelta2, should be vetted timesRelativeVector2: function( v ) { - var x = this.m00() * v.x + this.m01() * v.y; - var y = this.m10() * v.y + this.m11() * v.y; + const x = this.m00() * v.x + this.m01() * v.y; + const y = this.m10() * v.y + this.m11() * v.y; return new dot.Vector2( x, y ); }, @@ -570,7 +570,7 @@ define( require => { }, invert: function() { - var det; + let det; switch( this.type ) { case Types.IDENTITY: @@ -733,9 +733,9 @@ define( require => { // axis is a normalized Vector3, angle in radians. setToRotationAxisAngle: function( axis, angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); - var C = 1 - c; + const c = Math.cos( angle ); + const s = Math.sin( angle ); + const C = 1 - c; return this.rowMajor( axis.x * axis.x * C + c, axis.x * axis.y * C - axis.z * s, axis.x * axis.z * C + axis.y * s, @@ -745,8 +745,8 @@ define( require => { }, setToRotationX: function( angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); + const c = Math.cos( angle ); + const s = Math.sin( angle ); return this.rowMajor( 1, 0, 0, @@ -756,8 +756,8 @@ define( require => { }, setToRotationY: function( angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); + const c = Math.cos( angle ); + const s = Math.sin( angle ); return this.rowMajor( c, 0, s, @@ -767,8 +767,8 @@ define( require => { }, setToRotationZ: function( angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); + const c = Math.cos( angle ); + const s = Math.sin( angle ); return this.rowMajor( c, -s, 0, @@ -778,8 +778,8 @@ define( require => { }, setToTranslationRotation: function( x, y, angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); + const c = Math.cos( angle ); + const s = Math.sin( angle ); return this.rowMajor( c, -s, x, @@ -803,26 +803,26 @@ define( require => { // a rotation matrix that rotates A to B (Vector3 instances), by rotating about the axis A.cross( B ) -- Shortest path. ideally should be unit vectors setRotationAToB: function( a, b ) { // see http://graphics.cs.brown.edu/~jfh/papers/Moller-EBA-1999/paper.pdf for information on this implementation - var start = a; - var end = b; + const start = a; + const end = b; - var epsilon = 0.0001; + const epsilon = 0.0001; - var e; - var h; - var f; + let e; + let h; + let f; - var v = start.cross( end ); + let v = start.cross( end ); e = start.dot( end ); f = ( e < 0 ) ? -e : e; // if "from" and "to" vectors are nearly parallel if ( f > 1.0 - epsilon ) { - var c1; - var c2; - var c3; + let c1; + let c2; + let c3; - var x = new dot.Vector3( + let x = new dot.Vector3( ( start.x > 0.0 ) ? start.x : -start.x, ( start.y > 0.0 ) ? start.y : -start.y, ( start.z > 0.0 ) ? start.z : -start.z @@ -845,7 +845,7 @@ define( require => { } } - var u = x.minus( start ); + const u = x.minus( start ); v = x.minus( end ); c1 = 2.0 / u.dot( u ); @@ -866,11 +866,11 @@ define( require => { } else { // the most common case, unless "start"="end", or "start"=-"end" - var hvx; - var hvz; - var hvxy; - var hvxz; - var hvyz; + let hvx; + let hvz; + let hvxy; + let hvxz; + let hvyz; h = 1.0 / ( 1.0 + e ); hvx = h * v.x; hvz = h * v.z; @@ -990,7 +990,7 @@ define( require => { //Shortcut for translation times a matrix (without allocating a translation matrix), see scenery#119 Matrix3.translationTimesMatrix = function( x, y, m ) { - var type; + let type; if ( m.type === Types.IDENTITY || m.type === Types.TRANSLATION_2D ) { return Matrix3.createFromPool( 1, 0, m.m02() + x, diff --git a/js/Matrix3Tests.js b/js/Matrix3Tests.js index c516a3a..abfd6e4 100644 --- a/js/Matrix3Tests.js +++ b/js/Matrix3Tests.js @@ -19,7 +19,7 @@ define( require => { assert.ok( Math.abs( a - b ) < 0.00000001, msg + ' expected: ' + b + ', result: ' + a ); } - var epsilon = 0.00001; + const epsilon = 0.00001; function approximateEqual( assert, a, b, msg ) { assert.ok( Math.abs( a - b ) < epsilon, msg + ' expected: ' + b + ', got: ' + a ); @@ -66,7 +66,7 @@ define( require => { } ); QUnit.test( 'Row-major', function( assert ) { - var m = Matrix3.createFromPool( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + const m = Matrix3.createFromPool( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); assert.equal( m.m00(), 1, 'm00' ); assert.equal( m.m01(), 2, 'm01' ); assert.equal( m.m02(), 3, 'm02' ); @@ -79,7 +79,7 @@ define( require => { } ); QUnit.test( 'Column-major', function( assert ) { - var m = Matrix3.createFromPool(); + const m = Matrix3.createFromPool(); m.columnMajor( 1, 4, 7, 2, 5, 8, 3, 6, 9 ); assert.equal( m.m00(), 1, 'm00' ); assert.equal( m.m01(), 2, 'm01' ); @@ -98,14 +98,14 @@ define( require => { } ); QUnit.test( 'Rotation', function( assert ) { - var angle = Math.PI / 6 + 0.2543; + const angle = Math.PI / 6 + 0.2543; approximateEqual( assert, Matrix3.rotation2( angle ).getRotation(), angle ); } ); QUnit.test( 'plus / add', function( assert ) { - var a = A(); - var b = B(); - var result = Matrix3.createFromPool( 0.583184, -1.32807, 0.400818, -0.207545, 0.401791, 0.882298, 0.81168, 0.370878, -0.0835274 ); + const a = A(); + const b = B(); + const result = Matrix3.createFromPool( 0.583184, -1.32807, 0.400818, -0.207545, 0.401791, 0.882298, 0.81168, 0.370878, -0.0835274 ); approximateMatrixEqual( assert, a.plus( b ), result, 'plus' ); approximateMatrixEqual( assert, a, A(), 'verifying immutability' ); @@ -115,9 +115,9 @@ define( require => { } ); QUnit.test( 'minus / subtract', function( assert ) { - var a = A(); - var b = B(); - var result = Matrix3.createFromPool( -0.149837, 0.417574, -0.580365, -0.3163, -0.819726, -1.04049, -0.949493, -1.61117, 0.634326 ); + const a = A(); + const b = B(); + const result = Matrix3.createFromPool( -0.149837, 0.417574, -0.580365, -0.3163, -0.819726, -1.04049, -0.949493, -1.61117, 0.634326 ); approximateMatrixEqual( assert, a.minus( b ), result, 'minus' ); approximateMatrixEqual( assert, a, A(), 'verifying immutability' ); @@ -127,8 +127,8 @@ define( require => { } ); QUnit.test( 'transposed / transpose', function( assert ) { - var a = A(); - var result = Matrix3.createFromPool( 0.216673, -0.261922, -0.0689069, -0.455249, -0.208968, -0.620147, -0.0897734, -0.0790977, 0.275399 ); + const a = A(); + const result = Matrix3.createFromPool( 0.216673, -0.261922, -0.0689069, -0.455249, -0.208968, -0.620147, -0.0897734, -0.0790977, 0.275399 ); approximateMatrixEqual( assert, a.transposed(), result, 'transposed' ); approximateMatrixEqual( assert, a, A(), 'verifying immutability' ); @@ -138,8 +138,8 @@ define( require => { } ); QUnit.test( 'negated / negate', function( assert ) { - var a = A(); - var result = Matrix3.createFromPool( -0.216673, 0.455249, 0.0897734, 0.261922, 0.208968, 0.0790977, 0.0689069, 0.620147, -0.275399 ); + const a = A(); + const result = Matrix3.createFromPool( -0.216673, 0.455249, 0.0897734, 0.261922, 0.208968, 0.0790977, 0.0689069, 0.620147, -0.275399 ); approximateMatrixEqual( assert, a.negated(), result, 'negated' ); approximateMatrixEqual( assert, a, A(), 'verifying immutability' ); @@ -149,8 +149,8 @@ define( require => { } ); QUnit.test( 'inverted / invert', function( assert ) { - var a = A(); - var result = Matrix3.createFromPool( 1.48663, -2.52483, -0.240555, -1.08195, -0.745893, -0.566919, -2.06439, -2.31134, 2.29431 ); + const a = A(); + const result = Matrix3.createFromPool( 1.48663, -2.52483, -0.240555, -1.08195, -0.745893, -0.566919, -2.06439, -2.31134, 2.29431 ); approximateMatrixEqual( assert, a.inverted(), result, 'inverted' ); approximateMatrixEqual( assert, a, A(), 'verifying immutability' ); @@ -160,9 +160,9 @@ define( require => { } ); QUnit.test( 'timesMatrix / multiplyMatrix', function( assert ) { - var a = A(); - var b = B(); - var result = Matrix3.createFromPool( -0.0243954, -0.556133, -0.299155, -0.177013, 0.0225954, -0.301007, 0.183536, -0.0456892, -0.72886 ); + const a = A(); + const b = B(); + const result = Matrix3.createFromPool( -0.0243954, -0.556133, -0.299155, -0.177013, 0.0225954, -0.301007, 0.183536, -0.0456892, -0.72886 ); approximateMatrixEqual( assert, a.timesMatrix( b ), result, 'timesMatrix' ); approximateMatrixEqual( assert, a, A(), 'verifying immutability' ); @@ -172,9 +172,9 @@ define( require => { } ); QUnit.test( 'timesVector2 / multiplyVector2', function( assert ) { - var c = C(); - var v = V2(); - var result = new Vector2( 0.543836, 0.926107 ); + const c = C(); + const v = V2(); + const result = new Vector2( 0.543836, 0.926107 ); approximateMatrixEqual( assert, c.timesVector2( v ), result, 'timesVector2' ); approximateMatrixEqual( assert, v, V2(), 'verifying immutability' ); @@ -184,8 +184,8 @@ define( require => { } ); QUnit.test( 'timesTransposeVector2 / multiplyTransposeVector2', function( assert ) { - var c = C(); - var v = V2(); + const c = C(); + const v = V2(); c.timesTransposeVector2( v ); approximateMatrixEqual( assert, v, V2(), 'verifying immutability' ); @@ -195,8 +195,8 @@ define( require => { } ); QUnit.test( 'timesRelativeVector2 / multiplyRelativeVector2', function( assert ) { - var c = C(); - var v = V2(); + const c = C(); + const v = V2(); c.timesRelativeVector2( v ); approximateMatrixEqual( assert, v, V2(), 'verifying immutability' ); @@ -210,9 +210,9 @@ define( require => { approximateMatrixEqual( assert, Matrix3.IDENTITY.timesMatrix( A() ), A(), 'I * A = A' ); approximateMatrixEqual( assert, A().timesMatrix( Matrix3.IDENTITY ), A(), 'A * I = A' ); - var translation = Matrix3.translation( 2, -5 ); - var rotation = Matrix3.rotation2( Math.PI / 6 ); - var scale = Matrix3.scale( 2, 3 ); + const translation = Matrix3.translation( 2, -5 ); + const rotation = Matrix3.rotation2( Math.PI / 6 ); + const scale = Matrix3.scale( 2, 3 ); approximateMatrixEqual( assert, translation.timesMatrix( translation.inverted() ), Matrix3.IDENTITY, 'translation inverse check' ); approximateMatrixEqual( assert, rotation.timesMatrix( rotation.inverted() ), Matrix3.IDENTITY, 'rotation inverse check' ); approximateMatrixEqual( assert, scale.timesMatrix( scale.inverted() ), Matrix3.IDENTITY, 'scale inverse check' ); @@ -222,29 +222,29 @@ define( require => { } ); QUnit.test( 'Matrix Scaling Tests', function( assert ) { - var scale = Matrix3.scale( -2, 3 ); - var scaleVector = scale.getScaleVector(); + const scale = Matrix3.scale( -2, 3 ); + const scaleVector = scale.getScaleVector(); approximateEqual( assert, scaleVector.x, 2, 'Scale X should be -2' ); approximateEqual( assert, scaleVector.y, 3, 'Scale Y should be 3' ); - var beforeScale = scale.timesMatrix( Matrix3.rotation2( Math.PI / 2 ) ); + const beforeScale = scale.timesMatrix( Matrix3.rotation2( Math.PI / 2 ) ); approximateEqual( assert, beforeScale.getScaleVector().x, 3, 'before pi/2 rotation x' ); approximateEqual( assert, beforeScale.getScaleVector().y, 2, 'before pi/2 rotation y' ); - var afterScale = Matrix3.rotation2( Math.PI / 2 ).timesMatrix( scale ); + const afterScale = Matrix3.rotation2( Math.PI / 2 ).timesMatrix( scale ); approximateEqual( assert, afterScale.getScaleVector().x, 2, 'after pi/2 rotation x' ); approximateEqual( assert, afterScale.getScaleVector().y, 3, 'after pi/2 rotation y' ); - var rotation = Matrix3.rotation2( 0.35264 ); + const rotation = Matrix3.rotation2( 0.35264 ); approximateEqual( assert, rotation.getScaleVector().x, 1, 'rotation x' ); approximateEqual( assert, rotation.getScaleVector().y, 1, 'rotation x' ); } ); QUnit.test( 'Matrix scaling()', function( assert ) { - var rotation = Matrix3.rotation2( Math.PI / 4 ); - var translation = Matrix3.translation( 20, 30 ); - var scale2 = Matrix3.scaling( 2 ); - var scale2x3y = Matrix3.scaling( 2, 3 ); + const rotation = Matrix3.rotation2( Math.PI / 4 ); + const translation = Matrix3.translation( 20, 30 ); + const scale2 = Matrix3.scaling( 2 ); + const scale2x3y = Matrix3.scaling( 2, 3 ); // the basics, just to make sure it is working assert.equal( scale2.getScaleVector().x, 2, 'normal x scale' ); @@ -252,7 +252,7 @@ define( require => { assert.equal( scale2x3y.getScaleVector().x, 2, 'normal x scale' ); assert.equal( scale2x3y.getScaleVector().y, 3, 'normal y scale' ); - var combination = rotation.timesMatrix( scale2 ).timesMatrix( translation ); + const combination = rotation.timesMatrix( scale2 ).timesMatrix( translation ); approximateEquals( assert, combination.getScaleVector().x, 2, 'rotated x scale' ); approximateEquals( assert, combination.getScaleVector().y, 2, 'rotated x scale' ); diff --git a/js/Matrix4.js b/js/Matrix4.js index 4c8e6e1..2c97061 100644 --- a/js/Matrix4.js +++ b/js/Matrix4.js @@ -17,7 +17,7 @@ define( require => { require( 'DOT/Vector3' ); require( 'DOT/Vector4' ); - var Float32Array = window.Float32Array || Array; + const Float32Array = window.Float32Array || Array; function Matrix4( v00, v01, v02, v03, v10, v11, v12, v13, v20, v21, v22, v23, v30, v31, v32, v33, type ) { @@ -44,7 +44,7 @@ define( require => { // TODO: possibly add rotations }; - var Types = Matrix4.Types; + const Types = Matrix4.Types; Matrix4.identity = function() { return new Matrix4( @@ -81,9 +81,9 @@ define( require => { // axis is a normalized Vector3, angle in radians. Matrix4.rotationAxisAngle = function( axis, angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); - var C = 1 - c; + const c = Math.cos( angle ); + const s = Math.sin( angle ); + const C = 1 - c; return new Matrix4( axis.x * axis.x * C + c, axis.x * axis.y * C - axis.z * s, axis.x * axis.z * C + axis.y * s, 0, @@ -96,8 +96,8 @@ define( require => { // TODO: add in rotation from quaternion, and from quat + translation Matrix4.rotationX = function( angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); + const c = Math.cos( angle ); + const s = Math.sin( angle ); return new Matrix4( 1, 0, 0, 0, @@ -108,8 +108,8 @@ define( require => { }; Matrix4.rotationY = function( angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); + const c = Math.cos( angle ); + const s = Math.sin( angle ); return new Matrix4( c, 0, s, 0, @@ -120,8 +120,8 @@ define( require => { }; Matrix4.rotationZ = function( angle ) { - var c = Math.cos( angle ); - var s = Math.sin( angle ); + const c = Math.cos( angle ); + const s = Math.sin( angle ); return new Matrix4( c, -s, 0, 0, @@ -133,7 +133,7 @@ define( require => { // aspect === width / height Matrix4.gluPerspective = function( fovYRadians, aspect, zNear, zFar ) { - var cotangent = Math.cos( fovYRadians ) / Math.sin( fovYRadians ); + const cotangent = Math.cos( fovYRadians ) / Math.sin( fovYRadians ); return new Matrix4( cotangent / aspect, 0, 0, 0, @@ -227,18 +227,18 @@ define( require => { // returns a vector that is equivalent to ( T(1,0,0).magnitude, T(0,1,0).magnitude, T(0,0,1).magnitude ) // where T is a relative transform getScaleVector: function() { - var m0003 = this.m00() + this.m03(); - var m1013 = this.m10() + this.m13(); - var m2023 = this.m20() + this.m23(); - var m3033 = this.m30() + this.m33(); - var m0103 = this.m01() + this.m03(); - var m1113 = this.m11() + this.m13(); - var m2123 = this.m21() + this.m23(); - var m3133 = this.m31() + this.m33(); - var m0203 = this.m02() + this.m03(); - var m1213 = this.m12() + this.m13(); - var m2223 = this.m22() + this.m23(); - var m3233 = this.m32() + this.m33(); + const m0003 = this.m00() + this.m03(); + const m1013 = this.m10() + this.m13(); + const m2023 = this.m20() + this.m23(); + const m3033 = this.m30() + this.m33(); + const m0103 = this.m01() + this.m03(); + const m1113 = this.m11() + this.m13(); + const m2123 = this.m21() + this.m23(); + const m3133 = this.m31() + this.m33(); + const m0203 = this.m02() + this.m03(); + const m1213 = this.m12() + this.m13(); + const m2223 = this.m22() + this.m23(); + const m3233 = this.m32() + this.m33(); return new dot.Vector3( Math.sqrt( m0003 * m0003 + m1013 * m1013 + m2023 * m2023 + m3033 * m3033 ), Math.sqrt( m0103 * m0103 + m1113 * m1113 + m2123 * m2123 + m3133 * m3133 ), @@ -465,10 +465,10 @@ define( require => { }, timesVector4: function( v ) { - var x = this.m00() * v.x + this.m01() * v.y + this.m02() * v.z + this.m03() * v.w; - var y = this.m10() * v.x + this.m11() * v.y + this.m12() * v.z + this.m13() * v.w; - var z = this.m20() * v.x + this.m21() * v.y + this.m22() * v.z + this.m23() * v.w; - var w = this.m30() * v.x + this.m31() * v.y + this.m32() * v.z + this.m33() * v.w; + const x = this.m00() * v.x + this.m01() * v.y + this.m02() * v.z + this.m03() * v.w; + const y = this.m10() * v.x + this.m11() * v.y + this.m12() * v.z + this.m13() * v.w; + const z = this.m20() * v.x + this.m21() * v.y + this.m22() * v.z + this.m23() * v.w; + const w = this.m30() * v.x + this.m31() * v.y + this.m32() * v.z + this.m33() * v.w; return new dot.Vector4( x, y, z, w ); }, @@ -477,10 +477,10 @@ define( require => { }, timesTransposeVector4: function( v ) { - var x = this.m00() * v.x + this.m10() * v.y + this.m20() * v.z + this.m30() * v.w; - var y = this.m01() * v.x + this.m11() * v.y + this.m21() * v.z + this.m31() * v.w; - var z = this.m02() * v.x + this.m12() * v.y + this.m22() * v.z + this.m32() * v.w; - var w = this.m03() * v.x + this.m13() * v.y + this.m23() * v.z + this.m33() * v.w; + const x = this.m00() * v.x + this.m10() * v.y + this.m20() * v.z + this.m30() * v.w; + const y = this.m01() * v.x + this.m11() * v.y + this.m21() * v.z + this.m31() * v.w; + const z = this.m02() * v.x + this.m12() * v.y + this.m22() * v.z + this.m32() * v.w; + const w = this.m03() * v.x + this.m13() * v.y + this.m23() * v.z + this.m33() * v.w; return new dot.Vector4( x, y, z, w ); }, @@ -489,9 +489,9 @@ define( require => { }, timesRelativeVector3: function( v ) { - var x = this.m00() * v.x + this.m10() * v.y + this.m20() * v.z; - var y = this.m01() * v.y + this.m11() * v.y + this.m21() * v.z; - var z = this.m02() * v.z + this.m12() * v.y + this.m22() * v.z; + const x = this.m00() * v.x + this.m10() * v.y + this.m20() * v.z; + const y = this.m01() * v.y + this.m11() * v.y + this.m21() * v.z; + const z = this.m02() * v.z + this.m12() * v.y + this.m22() * v.z; return new dot.Vector3( x, y, z ); }, diff --git a/js/MatrixOps3.js b/js/MatrixOps3.js index e34f3f1..d22d3f7 100644 --- a/js/MatrixOps3.js +++ b/js/MatrixOps3.js @@ -23,9 +23,9 @@ define( require => { */ // constants - var SQRT_HALF = Math.sqrt( 0.5 ); + const SQRT_HALF = Math.sqrt( 0.5 ); - var MatrixOps3 = { + const MatrixOps3 = { // use typed arrays if possible Array: dot.FastArray, @@ -74,12 +74,12 @@ define( require => { transpose3: function( matrix, result ) { assert && assert( matrix.length >= 9 ); assert && assert( result.length >= 9 ); - var m1 = matrix[ 3 ]; - var m2 = matrix[ 6 ]; - var m3 = matrix[ 1 ]; - var m5 = matrix[ 7 ]; - var m6 = matrix[ 2 ]; - var m7 = matrix[ 5 ]; + const m1 = matrix[ 3 ]; + const m2 = matrix[ 6 ]; + const m3 = matrix[ 1 ]; + const m5 = matrix[ 7 ]; + const m6 = matrix[ 2 ]; + const m7 = matrix[ 5 ]; result[ 0 ] = matrix[ 0 ]; result[ 1 ] = m1; result[ 2 ] = m2; @@ -115,15 +115,15 @@ define( require => { assert && assert( left.length >= 9 ); assert && assert( right.length >= 9 ); assert && assert( result.length >= 9 ); - var m0 = left[ 0 ] * right[ 0 ] + left[ 1 ] * right[ 3 ] + left[ 2 ] * right[ 6 ]; - var m1 = left[ 0 ] * right[ 1 ] + left[ 1 ] * right[ 4 ] + left[ 2 ] * right[ 7 ]; - var m2 = left[ 0 ] * right[ 2 ] + left[ 1 ] * right[ 5 ] + left[ 2 ] * right[ 8 ]; - var m3 = left[ 3 ] * right[ 0 ] + left[ 4 ] * right[ 3 ] + left[ 5 ] * right[ 6 ]; - var m4 = left[ 3 ] * right[ 1 ] + left[ 4 ] * right[ 4 ] + left[ 5 ] * right[ 7 ]; - var m5 = left[ 3 ] * right[ 2 ] + left[ 4 ] * right[ 5 ] + left[ 5 ] * right[ 8 ]; - var m6 = left[ 6 ] * right[ 0 ] + left[ 7 ] * right[ 3 ] + left[ 8 ] * right[ 6 ]; - var m7 = left[ 6 ] * right[ 1 ] + left[ 7 ] * right[ 4 ] + left[ 8 ] * right[ 7 ]; - var m8 = left[ 6 ] * right[ 2 ] + left[ 7 ] * right[ 5 ] + left[ 8 ] * right[ 8 ]; + const m0 = left[ 0 ] * right[ 0 ] + left[ 1 ] * right[ 3 ] + left[ 2 ] * right[ 6 ]; + const m1 = left[ 0 ] * right[ 1 ] + left[ 1 ] * right[ 4 ] + left[ 2 ] * right[ 7 ]; + const m2 = left[ 0 ] * right[ 2 ] + left[ 1 ] * right[ 5 ] + left[ 2 ] * right[ 8 ]; + const m3 = left[ 3 ] * right[ 0 ] + left[ 4 ] * right[ 3 ] + left[ 5 ] * right[ 6 ]; + const m4 = left[ 3 ] * right[ 1 ] + left[ 4 ] * right[ 4 ] + left[ 5 ] * right[ 7 ]; + const m5 = left[ 3 ] * right[ 2 ] + left[ 4 ] * right[ 5 ] + left[ 5 ] * right[ 8 ]; + const m6 = left[ 6 ] * right[ 0 ] + left[ 7 ] * right[ 3 ] + left[ 8 ] * right[ 6 ]; + const m7 = left[ 6 ] * right[ 1 ] + left[ 7 ] * right[ 4 ] + left[ 8 ] * right[ 7 ]; + const m8 = left[ 6 ] * right[ 2 ] + left[ 7 ] * right[ 5 ] + left[ 8 ] * right[ 8 ]; result[ 0 ] = m0; result[ 1 ] = m1; result[ 2 ] = m2; @@ -146,15 +146,15 @@ define( require => { assert && assert( left.length >= 9 ); assert && assert( right.length >= 9 ); assert && assert( result.length >= 9 ); - var m0 = left[ 0 ] * right[ 0 ] + left[ 3 ] * right[ 3 ] + left[ 6 ] * right[ 6 ]; - var m1 = left[ 0 ] * right[ 1 ] + left[ 3 ] * right[ 4 ] + left[ 6 ] * right[ 7 ]; - var m2 = left[ 0 ] * right[ 2 ] + left[ 3 ] * right[ 5 ] + left[ 6 ] * right[ 8 ]; - var m3 = left[ 1 ] * right[ 0 ] + left[ 4 ] * right[ 3 ] + left[ 7 ] * right[ 6 ]; - var m4 = left[ 1 ] * right[ 1 ] + left[ 4 ] * right[ 4 ] + left[ 7 ] * right[ 7 ]; - var m5 = left[ 1 ] * right[ 2 ] + left[ 4 ] * right[ 5 ] + left[ 7 ] * right[ 8 ]; - var m6 = left[ 2 ] * right[ 0 ] + left[ 5 ] * right[ 3 ] + left[ 8 ] * right[ 6 ]; - var m7 = left[ 2 ] * right[ 1 ] + left[ 5 ] * right[ 4 ] + left[ 8 ] * right[ 7 ]; - var m8 = left[ 2 ] * right[ 2 ] + left[ 5 ] * right[ 5 ] + left[ 8 ] * right[ 8 ]; + const m0 = left[ 0 ] * right[ 0 ] + left[ 3 ] * right[ 3 ] + left[ 6 ] * right[ 6 ]; + const m1 = left[ 0 ] * right[ 1 ] + left[ 3 ] * right[ 4 ] + left[ 6 ] * right[ 7 ]; + const m2 = left[ 0 ] * right[ 2 ] + left[ 3 ] * right[ 5 ] + left[ 6 ] * right[ 8 ]; + const m3 = left[ 1 ] * right[ 0 ] + left[ 4 ] * right[ 3 ] + left[ 7 ] * right[ 6 ]; + const m4 = left[ 1 ] * right[ 1 ] + left[ 4 ] * right[ 4 ] + left[ 7 ] * right[ 7 ]; + const m5 = left[ 1 ] * right[ 2 ] + left[ 4 ] * right[ 5 ] + left[ 7 ] * right[ 8 ]; + const m6 = left[ 2 ] * right[ 0 ] + left[ 5 ] * right[ 3 ] + left[ 8 ] * right[ 6 ]; + const m7 = left[ 2 ] * right[ 1 ] + left[ 5 ] * right[ 4 ] + left[ 8 ] * right[ 7 ]; + const m8 = left[ 2 ] * right[ 2 ] + left[ 5 ] * right[ 5 ] + left[ 8 ] * right[ 8 ]; result[ 0 ] = m0; result[ 1 ] = m1; result[ 2 ] = m2; @@ -177,15 +177,15 @@ define( require => { assert && assert( left.length >= 9 ); assert && assert( right.length >= 9 ); assert && assert( result.length >= 9 ); - var m0 = left[ 0 ] * right[ 0 ] + left[ 1 ] * right[ 1 ] + left[ 2 ] * right[ 2 ]; - var m1 = left[ 0 ] * right[ 3 ] + left[ 1 ] * right[ 4 ] + left[ 2 ] * right[ 5 ]; - var m2 = left[ 0 ] * right[ 6 ] + left[ 1 ] * right[ 7 ] + left[ 2 ] * right[ 8 ]; - var m3 = left[ 3 ] * right[ 0 ] + left[ 4 ] * right[ 1 ] + left[ 5 ] * right[ 2 ]; - var m4 = left[ 3 ] * right[ 3 ] + left[ 4 ] * right[ 4 ] + left[ 5 ] * right[ 5 ]; - var m5 = left[ 3 ] * right[ 6 ] + left[ 4 ] * right[ 7 ] + left[ 5 ] * right[ 8 ]; - var m6 = left[ 6 ] * right[ 0 ] + left[ 7 ] * right[ 1 ] + left[ 8 ] * right[ 2 ]; - var m7 = left[ 6 ] * right[ 3 ] + left[ 7 ] * right[ 4 ] + left[ 8 ] * right[ 5 ]; - var m8 = left[ 6 ] * right[ 6 ] + left[ 7 ] * right[ 7 ] + left[ 8 ] * right[ 8 ]; + const m0 = left[ 0 ] * right[ 0 ] + left[ 1 ] * right[ 1 ] + left[ 2 ] * right[ 2 ]; + const m1 = left[ 0 ] * right[ 3 ] + left[ 1 ] * right[ 4 ] + left[ 2 ] * right[ 5 ]; + const m2 = left[ 0 ] * right[ 6 ] + left[ 1 ] * right[ 7 ] + left[ 2 ] * right[ 8 ]; + const m3 = left[ 3 ] * right[ 0 ] + left[ 4 ] * right[ 1 ] + left[ 5 ] * right[ 2 ]; + const m4 = left[ 3 ] * right[ 3 ] + left[ 4 ] * right[ 4 ] + left[ 5 ] * right[ 5 ]; + const m5 = left[ 3 ] * right[ 6 ] + left[ 4 ] * right[ 7 ] + left[ 5 ] * right[ 8 ]; + const m6 = left[ 6 ] * right[ 0 ] + left[ 7 ] * right[ 1 ] + left[ 8 ] * right[ 2 ]; + const m7 = left[ 6 ] * right[ 3 ] + left[ 7 ] * right[ 4 ] + left[ 8 ] * right[ 5 ]; + const m8 = left[ 6 ] * right[ 6 ] + left[ 7 ] * right[ 7 ] + left[ 8 ] * right[ 8 ]; result[ 0 ] = m0; result[ 1 ] = m1; result[ 2 ] = m2; @@ -210,15 +210,15 @@ define( require => { assert && assert( left.length >= 9 ); assert && assert( right.length >= 9 ); assert && assert( result.length >= 9 ); - var m0 = left[ 0 ] * right[ 0 ] + left[ 3 ] * right[ 1 ] + left[ 6 ] * right[ 2 ]; - var m1 = left[ 0 ] * right[ 3 ] + left[ 3 ] * right[ 4 ] + left[ 6 ] * right[ 5 ]; - var m2 = left[ 0 ] * right[ 6 ] + left[ 3 ] * right[ 7 ] + left[ 6 ] * right[ 8 ]; - var m3 = left[ 1 ] * right[ 0 ] + left[ 4 ] * right[ 1 ] + left[ 7 ] * right[ 2 ]; - var m4 = left[ 1 ] * right[ 3 ] + left[ 4 ] * right[ 4 ] + left[ 7 ] * right[ 5 ]; - var m5 = left[ 1 ] * right[ 6 ] + left[ 4 ] * right[ 7 ] + left[ 7 ] * right[ 8 ]; - var m6 = left[ 2 ] * right[ 0 ] + left[ 5 ] * right[ 1 ] + left[ 8 ] * right[ 2 ]; - var m7 = left[ 2 ] * right[ 3 ] + left[ 5 ] * right[ 4 ] + left[ 8 ] * right[ 5 ]; - var m8 = left[ 2 ] * right[ 6 ] + left[ 5 ] * right[ 7 ] + left[ 8 ] * right[ 8 ]; + const m0 = left[ 0 ] * right[ 0 ] + left[ 3 ] * right[ 1 ] + left[ 6 ] * right[ 2 ]; + const m1 = left[ 0 ] * right[ 3 ] + left[ 3 ] * right[ 4 ] + left[ 6 ] * right[ 5 ]; + const m2 = left[ 0 ] * right[ 6 ] + left[ 3 ] * right[ 7 ] + left[ 6 ] * right[ 8 ]; + const m3 = left[ 1 ] * right[ 0 ] + left[ 4 ] * right[ 1 ] + left[ 7 ] * right[ 2 ]; + const m4 = left[ 1 ] * right[ 3 ] + left[ 4 ] * right[ 4 ] + left[ 7 ] * right[ 5 ]; + const m5 = left[ 1 ] * right[ 6 ] + left[ 4 ] * right[ 7 ] + left[ 7 ] * right[ 8 ]; + const m6 = left[ 2 ] * right[ 0 ] + left[ 5 ] * right[ 1 ] + left[ 8 ] * right[ 2 ]; + const m7 = left[ 2 ] * right[ 3 ] + left[ 5 ] * right[ 4 ] + left[ 8 ] * right[ 5 ]; + const m8 = left[ 2 ] * right[ 6 ] + left[ 5 ] * right[ 7 ] + left[ 8 ] * right[ 8 ]; result[ 0 ] = m0; result[ 1 ] = m1; result[ 2 ] = m2; @@ -239,9 +239,9 @@ define( require => { */ mult3Vector3: function( matrix, vector, result ) { assert && assert( matrix.length >= 9 ); - var x = matrix[ 0 ] * vector.x + matrix[ 1 ] * vector.y + matrix[ 2 ] * vector.z; - var y = matrix[ 3 ] * vector.x + matrix[ 4 ] * vector.y + matrix[ 5 ] * vector.z; - var z = matrix[ 6 ] * vector.x + matrix[ 7 ] * vector.y + matrix[ 8 ] * vector.z; + const x = matrix[ 0 ] * vector.x + matrix[ 1 ] * vector.y + matrix[ 2 ] * vector.z; + const y = matrix[ 3 ] * vector.x + matrix[ 4 ] * vector.y + matrix[ 5 ] * vector.z; + const z = matrix[ 6 ] * vector.x + matrix[ 7 ] * vector.y + matrix[ 8 ] * vector.z; result.x = x; result.y = y; result.z = z; @@ -256,9 +256,9 @@ define( require => { */ swapNegateColumn: function( matrix, idx0, idx1 ) { assert && assert( matrix.length >= 9 ); - var tmp0 = matrix[ idx0 ]; - var tmp1 = matrix[ idx0 + 3 ]; - var tmp2 = matrix[ idx0 + 6 ]; + const tmp0 = matrix[ idx0 ]; + const tmp1 = matrix[ idx0 + 3 ]; + const tmp2 = matrix[ idx0 + 6 ]; matrix[ idx0 ] = matrix[ idx1 ]; matrix[ idx0 + 3 ] = matrix[ idx1 + 3 ]; @@ -311,15 +311,15 @@ define( require => { * @param {number} idx1 - [input] The larger row/column index */ preMult3Givens: function( matrix, cos, sin, idx0, idx1 ) { - var baseA = idx0 * 3; - var baseB = idx1 * 3; + const baseA = idx0 * 3; + const baseB = idx1 * 3; // lexicographically in column-major order for "affine" section - var a = cos * matrix[ baseA + 0 ] + sin * matrix[ baseB + 0 ]; - var b = cos * matrix[ baseB + 0 ] - sin * matrix[ baseA + 0 ]; - var c = cos * matrix[ baseA + 1 ] + sin * matrix[ baseB + 1 ]; - var d = cos * matrix[ baseB + 1 ] - sin * matrix[ baseA + 1 ]; - var e = cos * matrix[ baseA + 2 ] + sin * matrix[ baseB + 2 ]; - var f = cos * matrix[ baseB + 2 ] - sin * matrix[ baseA + 2 ]; + const a = cos * matrix[ baseA + 0 ] + sin * matrix[ baseB + 0 ]; + const b = cos * matrix[ baseB + 0 ] - sin * matrix[ baseA + 0 ]; + const c = cos * matrix[ baseA + 1 ] + sin * matrix[ baseB + 1 ]; + const d = cos * matrix[ baseB + 1 ] - sin * matrix[ baseA + 1 ]; + const e = cos * matrix[ baseA + 2 ] + sin * matrix[ baseB + 2 ]; + const f = cos * matrix[ baseB + 2 ] - sin * matrix[ baseA + 2 ]; matrix[ baseA + 0 ] = a; matrix[ baseB + 0 ] = b; matrix[ baseA + 1 ] = c; @@ -341,12 +341,12 @@ define( require => { */ postMult3Givens: function( matrix, cos, sin, idx0, idx1 ) { // lexicographically in row-major order for the "transposed affine" section - var a = cos * matrix[ idx0 + 0 ] + sin * matrix[ idx1 + 0 ]; - var b = cos * matrix[ idx1 + 0 ] - sin * matrix[ idx0 + 0 ]; - var c = cos * matrix[ idx0 + 3 ] + sin * matrix[ idx1 + 3 ]; - var d = cos * matrix[ idx1 + 3 ] - sin * matrix[ idx0 + 3 ]; - var e = cos * matrix[ idx0 + 6 ] + sin * matrix[ idx1 + 6 ]; - var f = cos * matrix[ idx1 + 6 ] - sin * matrix[ idx0 + 6 ]; + const a = cos * matrix[ idx0 + 0 ] + sin * matrix[ idx1 + 0 ]; + const b = cos * matrix[ idx1 + 0 ] - sin * matrix[ idx0 + 0 ]; + const c = cos * matrix[ idx0 + 3 ] + sin * matrix[ idx1 + 3 ]; + const d = cos * matrix[ idx1 + 3 ] - sin * matrix[ idx0 + 3 ]; + const e = cos * matrix[ idx0 + 6 ] + sin * matrix[ idx1 + 6 ]; + const f = cos * matrix[ idx1 + 6 ] - sin * matrix[ idx0 + 6 ]; matrix[ idx0 + 0 ] = a; matrix[ idx1 + 0 ] = b; matrix[ idx0 + 3 ] = c; @@ -367,21 +367,21 @@ define( require => { */ applyJacobi3: function( mS, mQ, idx0, idx1 ) { // submatrix entries for idx0,idx1 - var a11 = mS[ 3 * idx0 + idx0 ]; - var a12 = mS[ 3 * idx0 + idx1 ]; // we assume mS is symmetric, so we don't need a21 - var a22 = mS[ 3 * idx1 + idx1 ]; + const a11 = mS[ 3 * idx0 + idx0 ]; + const a12 = mS[ 3 * idx0 + idx1 ]; // we assume mS is symmetric, so we don't need a21 + const a22 = mS[ 3 * idx1 + idx1 ]; // Approximate givens angle, see https://graphics.cs.wisc.edu/Papers/2011/MSTTS11/SVD_TR1690.pdf (section 2.3) // "Computing the Singular Value Decomposition of 3x3 matrices with minimal branching and elementary floating point operations" // Aleka McAdams, Andrew Selle, Rasmus Tamstorf, Joseph Teran, Eftychios Sifakis - var lhs = a12 * a12; - var rhs = a11 - a22; + const lhs = a12 * a12; + let rhs = a11 - a22; rhs = rhs * rhs; - var useAngle = lhs < rhs; - var w = 1 / Math.sqrt( lhs + rhs ); + const useAngle = lhs < rhs; + const w = 1 / Math.sqrt( lhs + rhs ); // NOTE: exact Givens angle is 0.5 * Math.atan( 2 * a12 / ( a11 - a22 ) ), but clamped to withing +-Math.PI / 4 - var cos = useAngle ? ( w * ( a11 - a22 ) ) : SQRT_HALF; - var sin = useAngle ? ( w * a12 ) : SQRT_HALF; + const cos = useAngle ? ( w * ( a11 - a22 ) ) : SQRT_HALF; + const sin = useAngle ? ( w * a12 ) : SQRT_HALF; // S' = Q * S * transpose( Q ) this.preMult3Givens( mS, cos, sin, idx0, idx1 ); @@ -402,7 +402,7 @@ define( require => { */ jacobiIteration3: function( mS, mQ, n ) { // for 3x3, we eliminate non-diagonal entries iteratively - for ( var i = 0; i < n; i++ ) { + for ( let i = 0; i < n; i++ ) { this.applyJacobi3( mS, mQ, 0, 1 ); this.applyJacobi3( mS, mQ, 0, 2 ); this.applyJacobi3( mS, mQ, 1, 2 ); @@ -422,14 +422,14 @@ define( require => { qrAnnihilate3: function( q, r, row, col ) { assert && assert( row > col ); // only in the lower-triangular area - var epsilon = 0.0000000001; - var cos; - var sin; + const epsilon = 0.0000000001; + let cos; + let sin; - var diagonalValue = r[ this.index3( col, col ) ]; - var targetValue = r[ this.index3( row, col ) ]; - var diagonalSquared = diagonalValue * diagonalValue; - var targetSquared = targetValue * targetValue; + const diagonalValue = r[ this.index3( col, col ) ]; + const targetValue = r[ this.index3( row, col ) ]; + const diagonalSquared = diagonalValue * diagonalValue; + const targetSquared = targetValue * targetValue; // handle the case where both (row,col) and (col,col) are very small (would cause instabilities) if ( diagonalSquared + targetSquared < epsilon ) { @@ -437,7 +437,7 @@ define( require => { sin = 0; } else { - var rsqr = 1 / Math.sqrt( diagonalSquared + targetSquared ); + const rsqr = 1 / Math.sqrt( diagonalSquared + targetSquared ); cos = rsqr * diagonalValue; sin = rsqr * targetValue; } @@ -460,9 +460,9 @@ define( require => { */ svd3: function( a, jacobiIterationCount, resultU, resultSigma, resultV ) { // shorthands - var q = resultU; - var v = resultV; - var r = resultSigma; + const q = resultU; + const v = resultV; + const r = resultSigma; // for now, use 'r' as our S == transpose( A ) * A, so we don't have to use scratch matrices this.mult3LeftTranspose( a, a, r ); @@ -478,10 +478,10 @@ define( require => { // Sort columns of R and V based on singular values (needed for the QR step, and useful anyways). // Their product will remain unchanged. - var mag0 = r[ 0 ] * r[ 0 ] + r[ 3 ] * r[ 3 ] + r[ 6 ] * r[ 6 ]; // column vector magnitudes - var mag1 = r[ 1 ] * r[ 1 ] + r[ 4 ] * r[ 4 ] + r[ 7 ] * r[ 7 ]; - var mag2 = r[ 2 ] * r[ 2 ] + r[ 5 ] * r[ 5 ] + r[ 8 ] * r[ 8 ]; - var tmpMag; + let mag0 = r[ 0 ] * r[ 0 ] + r[ 3 ] * r[ 3 ] + r[ 6 ] * r[ 6 ]; // column vector magnitudes + let mag1 = r[ 1 ] * r[ 1 ] + r[ 4 ] * r[ 4 ] + r[ 7 ] * r[ 7 ]; + let mag2 = r[ 2 ] * r[ 2 ] + r[ 5 ] * r[ 5 ] + r[ 8 ] * r[ 8 ]; + let tmpMag; if ( mag0 < mag1 ) { // swap magnitudes tmpMag = mag0; @@ -511,7 +511,7 @@ define( require => { this.qrAnnihilate3( q, r, 2, 1 ); // checks for a singular U value, we'll add in the needed 1 entries to make sure our U is orthogonal - var bigEpsilon = 0.001; // they really should be around 1 + const bigEpsilon = 0.001; // they really should be around 1 if ( q[ 0 ] * q[ 0 ] + q[ 1 ] * q[ 1 ] + q[ 2 ] * q[ 2 ] < bigEpsilon ) { q[ 0 ] = 1; } @@ -534,13 +534,13 @@ define( require => { * @param {FastMath.Array} result - [output] 3xN Matrix, where N is the number of column vectors */ setVectors3: function( columnVectors, result ) { - var m = 3; - var n = columnVectors.length; + const m = 3; + const n = columnVectors.length; assert && assert( result.length >= m * n, 'Array length check' ); - for ( var i = 0; i < n; i++ ) { - var vector = columnVectors[ i ]; + for ( let i = 0; i < n; i++ ) { + const vector = columnVectors[ i ]; result[ i ] = vector.x; result[ i + n ] = vector.y; result[ i + 2 * n ] = vector.z; @@ -593,8 +593,8 @@ define( require => { assert && assert( result.length >= n * m ); assert && assert( matrix !== result, 'In-place modification not implemented yet' ); - for ( var row = 0; row < m; row++ ) { - for ( var col = 0; col < n; col++ ) { + for ( let row = 0; row < m; row++ ) { + for ( let col = 0; col < n; col++ ) { result[ m * col + row ] = matrix[ n * row + col ]; } } @@ -616,10 +616,10 @@ define( require => { assert && assert( result.length >= m * p ); assert && assert( left !== result && right !== result, 'In-place modification not implemented yet' ); - for ( var row = 0; row < m; row++ ) { - for ( var col = 0; col < p; col++ ) { - var x = 0; - for ( var k = 0; k < n; k++ ) { + for ( let row = 0; row < m; row++ ) { + for ( let col = 0; col < p; col++ ) { + let x = 0; + for ( let k = 0; k < n; k++ ) { x += left[ this.index( m, n, row, k ) ] * right[ this.index( n, p, k, col ) ]; } result[ this.index( m, p, row, col ) ] = x; @@ -643,10 +643,10 @@ define( require => { assert && assert( result.length >= m * p ); assert && assert( left !== result && right !== result, 'In-place modification not implemented yet' ); - for ( var row = 0; row < m; row++ ) { - for ( var col = 0; col < p; col++ ) { - var x = 0; - for ( var k = 0; k < n; k++ ) { + for ( let row = 0; row < m; row++ ) { + for ( let col = 0; col < p; col++ ) { + let x = 0; + for ( let k = 0; k < n; k++ ) { x += left[ this.index( m, n, row, k ) ] * right[ this.index( p, n, col, k ) ]; } result[ this.index( m, p, row, col ) ] = x; @@ -668,9 +668,9 @@ define( require => { assert && assert( matrix.length >= m * n ); assert && assert( result.length >= m * n ); - for ( var col = 0; col < n; col++ ) { - var permutedColumnIndex = permutation.indices[ col ]; - for ( var row = 0; row < m; row++ ) { + for ( let col = 0; col < n; col++ ) { + const permutedColumnIndex = permutation.indices[ col ]; + for ( let row = 0; row < m; row++ ) { result[ this.index( m, n, row, col ) ] = matrix[ this.index( m, n, row, permutedColumnIndex ) ]; } } diff --git a/js/MatrixOps3Tests.js b/js/MatrixOps3Tests.js index cb23e4b..e883002 100644 --- a/js/MatrixOps3Tests.js +++ b/js/MatrixOps3Tests.js @@ -19,16 +19,16 @@ define( require => { } function approxEqualArray( assert, arr, barr, msg ) { - for ( var i = 0; i < arr.length; i++ ) { + for ( let i = 0; i < arr.length; i++ ) { approxEqual( assert, arr[ i ], barr[ i ], msg + ': index ' + i ); } } /* eslint-disable no-undef */ QUnit.test( '3x3 mults', function( assert ) { - var a = new MatrixOps3.Array( [ 1, 2, 7, 5, 2, 6, -1, -5, 4 ] ); // a:= {{1, 2, 7}, {5, 2, 6}, {-1, -5, 4}} - var b = new MatrixOps3.Array( [ 4, 3, 1, -7, 2, -1, -1, 0, -2 ] ); // b:= {{4, 3, 1}, {-7, 2, -1}, {-1, 0, -2}} - var c = new MatrixOps3.Array( 9 ); + const a = new MatrixOps3.Array( [ 1, 2, 7, 5, 2, 6, -1, -5, 4 ] ); // a:= {{1, 2, 7}, {5, 2, 6}, {-1, -5, 4}} + const b = new MatrixOps3.Array( [ 4, 3, 1, -7, 2, -1, -1, 0, -2 ] ); // b:= {{4, 3, 1}, {-7, 2, -1}, {-1, 0, -2}} + const c = new MatrixOps3.Array( 9 ); MatrixOps3.mult3( a, b, c ); approxEqualArray( assert, c, [ -17, 7, -15, 0, 19, -9, 27, -13, -4 ], 'mult3' ); @@ -42,13 +42,13 @@ define( require => { } ); QUnit.test( 'optimized Givens rotation equivalence', function( assert ) { - var a = new MatrixOps3.Array( [ 1, 2, 7, 5, 2, 6, -1, -5, 4 ] ); - var normal = new MatrixOps3.Array( 9 ); - var accel = new MatrixOps3.Array( 9 ); - var givens = new MatrixOps3.Array( 9 ); + const a = new MatrixOps3.Array( [ 1, 2, 7, 5, 2, 6, -1, -5, 4 ] ); + const normal = new MatrixOps3.Array( 9 ); + const accel = new MatrixOps3.Array( 9 ); + const givens = new MatrixOps3.Array( 9 ); - var cos = Math.cos( Math.PI / 6 ); - var sin = Math.sin( Math.PI / 6 ); + const cos = Math.cos( Math.PI / 6 ); + const sin = Math.sin( Math.PI / 6 ); MatrixOps3.set3( a, normal ); MatrixOps3.set3( a, accel ); @@ -93,14 +93,14 @@ define( require => { } ); QUnit.test( 'SVD', function( assert ) { - var a = new MatrixOps3.Array( [ 1, 2, 7, 5, 2, 6, -1, -5, 4 ] ); - var u = new MatrixOps3.Array( 9 ); - var sigma = new MatrixOps3.Array( 9 ); - var v = new MatrixOps3.Array( 9 ); + const a = new MatrixOps3.Array( [ 1, 2, 7, 5, 2, 6, -1, -5, 4 ] ); + const u = new MatrixOps3.Array( 9 ); + const sigma = new MatrixOps3.Array( 9 ); + const v = new MatrixOps3.Array( 9 ); MatrixOps3.svd3( a, 20, u, sigma, v ); - var c = new MatrixOps3.Array( 9 ); + const c = new MatrixOps3.Array( 9 ); // c = U * Sigma * V^T MatrixOps3.mult3( u, sigma, c ); diff --git a/js/OpenRange.js b/js/OpenRange.js index 20ca6c5..c783820 100644 --- a/js/OpenRange.js +++ b/js/OpenRange.js @@ -112,8 +112,8 @@ define( require => { * @returns {string} */ toString: function() { - var leftBracket = this.openMin ? '(' : '['; - var rightBracket = this.openMax ? ')' : ']'; + const leftBracket = this.openMin ? '(' : '['; + const rightBracket = this.openMax ? ')' : ']'; return '[Range ' + leftBracket + 'min:' + this.min + ' max:' + this.max + rightBracket + ']'; }, diff --git a/js/OpenRangeTests.js b/js/OpenRangeTests.js index 13a436d..5e2f59a 100644 --- a/js/OpenRangeTests.js +++ b/js/OpenRangeTests.js @@ -13,13 +13,13 @@ define( require => { const OpenRange = require( 'DOT/OpenRange' ); const Range = require( 'DOT/Range' ); - var minHalfOpenOptions = { openMax: false }; - var maxHalfOpenOptions = { openMin: false }; + const minHalfOpenOptions = { openMax: false }; + const maxHalfOpenOptions = { openMin: false }; QUnit.module( 'OpenRange'); QUnit.test( 'half open min', function( assert ) { - var testMinOpenRange = new OpenRange( 1, 10, minHalfOpenOptions ); + const testMinOpenRange = new OpenRange( 1, 10, minHalfOpenOptions ); assert.notOk( testMinOpenRange.contains( 1 ), '(1, 10] does not contain 1' ); assert.notOk( testMinOpenRange.intersects( new Range( 0, 1 ) ), '(1, 10] does not intersect [0, 1]' ); assert.notOk( testMinOpenRange.containsRange( new Range( 1, 2 ), '(1, 10] does not contain [1, 2]' ) ); @@ -29,7 +29,7 @@ define( require => { } ); QUnit.test( 'half open max', function( assert ) { - var maxOpenRange = new OpenRange( 1, 10, maxHalfOpenOptions ); + const maxOpenRange = new OpenRange( 1, 10, maxHalfOpenOptions ); assert.notOk( maxOpenRange.contains( 10 ), '[1, 10) does not contain 10' ); assert.notOk( maxOpenRange.intersects( new Range( 10, 11 ) ), '[1, 10) does not intersect [10,11]' ); assert.notOk( maxOpenRange.containsRange( new Range( 9, 10 ), '[1, 10) does not contiain [9, 10]' ) ); @@ -39,7 +39,7 @@ define( require => { } ); QUnit.test( 'fully open range', function( assert ) { - var openRange = new OpenRange( 1, 10 ); + const openRange = new OpenRange( 1, 10 ); assert.notOk( openRange.contains( 1 ), '(1, 10) does not contain 1' ); assert.notOk( openRange.contains( 10 ), '(1, 10) does not contain 10' ); assert.notOk( openRange.intersects( new Range( 0, 1 ) ), '(1, 10) does not intersect [0, 1]' ); @@ -55,7 +55,7 @@ define( require => { } ); QUnit.test( 'setter overrides', function( assert ) { - var openRange = new OpenRange( 1, 10 ); + let openRange = new OpenRange( 1, 10 ); assert.notOk( openRange.setMin( 2 ), 'can set min < max' ); window.assert && assert.throws( function() { openRange.setMin( 10 ); }, 'cannot set min = max in OpenRange' ); openRange = new OpenRange( 1, 10 ); @@ -70,7 +70,7 @@ define( require => { assert.throws( function() { return new OpenRange( 1, 1, maxHalfOpenOptions ); }, 'max open range with min === max throws an error' ); assert.throws( function() { return new OpenRange( 1, 1 ); }, 'full open range with min === max throws an error' ); - var range = new OpenRange( 1, 10 ); + let range = new OpenRange( 1, 10 ); assert.throws( function() { range.setMin( 10 ); }, 'setting min equal to max throws an error' ); range = new OpenRange( 1, 10 ); assert.throws( function() { range.setMin( 11 ); }, 'setting min greater than max throws an error' ); diff --git a/js/Permutation.js b/js/Permutation.js index 0baf0ca..22c375e 100644 --- a/js/Permutation.js +++ b/js/Permutation.js @@ -24,8 +24,8 @@ define( require => { // An identity permutation with a specific number of elements Permutation.identity = function( size ) { assert && assert( size >= 0 ); - var indices = new Array( size ); - for ( var i = 0; i < size; i++ ) { + const indices = new Array( size ); + for ( let i = 0; i < size; i++ ) { indices[ i ] = i; } return new Permutation( indices ); @@ -33,7 +33,7 @@ define( require => { // lists all permutations that have a given size Permutation.permutations = function( size ) { - var result = []; + const result = []; Permutation.forEachPermutation( dot.rangeInclusive( 0, size - 1 ), function( integers ) { result.push( new Permutation( integers ) ); } ); @@ -52,15 +52,15 @@ define( require => { callback( prefix ); } else { - for ( var i = 0; i < array.length; i++ ) { - var element = array[ i ]; + for ( let i = 0; i < array.length; i++ ) { + const element = array[ i ]; // remove the element from the array - var nextArray = array.slice( 0 ); + const nextArray = array.slice( 0 ); nextArray.splice( i, 1 ); // add it into the prefix - var nextPrefix = prefix.slice( 0 ); + const nextPrefix = prefix.slice( 0 ); nextPrefix.push( element ); recursiveForEachPermutation( nextArray, nextPrefix, callback ); @@ -86,8 +86,8 @@ define( require => { } // permute it as an array - var result = new Array( arrayOrInt.length ); - for ( var i = 0; i < arrayOrInt.length; i++ ) { + const result = new Array( arrayOrInt.length ); + for ( let i = 0; i < arrayOrInt.length; i++ ) { result[ i ] = arrayOrInt[ this.indices[ i ] ]; } return result; @@ -100,21 +100,21 @@ define( require => { // The inverse of this permutation inverted: function() { - var newPermutation = new Array( this.size() ); - for ( var i = 0; i < this.size(); i++ ) { + const newPermutation = new Array( this.size() ); + for ( let i = 0; i < this.size(); i++ ) { newPermutation[ this.indices[ i ] ] = i; } return new Permutation( newPermutation ); }, withIndicesPermuted: function( indices ) { - var result = []; - var self = this; + const result = []; + const self = this; Permutation.forEachPermutation( indices, function( integers ) { - var oldIndices = self.indices; - var newPermutation = oldIndices.slice( 0 ); + const oldIndices = self.indices; + const newPermutation = oldIndices.slice( 0 ); - for ( var i = 0; i < indices.length; i++ ) { + for ( let i = 0; i < indices.length; i++ ) { newPermutation[ indices[ i ] ] = oldIndices[ integers[ i ] ]; } result.push( new Permutation( newPermutation ) ); @@ -128,10 +128,10 @@ define( require => { }; Permutation.testMe = function( console ) { - var a = new Permutation( [ 1, 4, 3, 2, 0 ] ); + const a = new Permutation( [ 1, 4, 3, 2, 0 ] ); console.log( a.toString() ); - var b = a.inverted(); + const b = a.inverted(); console.log( b.toString() ); console.log( b.withIndicesPermuted( [ 0, 3, 4 ] ).toString() ); diff --git a/js/Plane3.js b/js/Plane3.js index 19d3a11..a1dc789 100644 --- a/js/Plane3.js +++ b/js/Plane3.js @@ -58,7 +58,7 @@ define( require => { * @returns {Plane3|null} */ Plane3.fromTriangle = function( a, b, c ) { - var normal = ( c.minus( a ) ).cross( b.minus( a ) ); + const normal = ( c.minus( a ) ).cross( b.minus( a ) ); if ( normal.magnitude === 0 ) { return null; } diff --git a/js/QRDecomposition.js b/js/QRDecomposition.js index 2ccc06a..ae65cbe 100644 --- a/js/QRDecomposition.js +++ b/js/QRDecomposition.js @@ -11,7 +11,7 @@ define( require => { const dot = require( 'DOT/dot' ); - var ArrayType = window.Float64Array || Array; + const ArrayType = window.Float64Array || Array; // require( 'DOT/Matrix' ); // commented out so Require.js doesn't complain about the circular dependency @@ -20,22 +20,22 @@ define( require => { // TODO: size! this.QR = matrix.getArrayCopy(); - var QR = this.QR; + const QR = this.QR; this.m = matrix.getRowDimension(); - var m = this.m; + const m = this.m; this.n = matrix.getColumnDimension(); - var n = this.n; + const n = this.n; this.Rdiag = new ArrayType( n ); - var i; - var j; - var k; + let i; + let j; + let k; // Main loop. for ( k = 0; k < n; k++ ) { // Compute 2-norm of k-th column without under/overflow. - var nrm = 0; + let nrm = 0; for ( i = k; i < m; i++ ) { nrm = dot.Matrix.hypot( nrm, QR[ this.matrix.index( i, k ) ] ); } @@ -52,7 +52,7 @@ define( require => { // Apply transformation to remaining columns. for ( j = k + 1; j < n; j++ ) { - var s = 0.0; + let s = 0.0; for ( i = k; i < m; i++ ) { s += QR[ this.matrix.index( i, k ) ] * QR[ this.matrix.index( i, j ) ]; } @@ -65,13 +65,13 @@ define( require => { this.Rdiag[ k ] = -nrm; } }; - var QRDecomposition = dot.QRDecomposition; + const QRDecomposition = dot.QRDecomposition; QRDecomposition.prototype = { constructor: QRDecomposition, isFullRank: function() { - for ( var j = 0; j < this.n; j++ ) { + for ( let j = 0; j < this.n; j++ ) { if ( this.Rdiag[ j ] === 0 ) { return false; } @@ -80,9 +80,9 @@ define( require => { }, getH: function() { - var result = new dot.Matrix( this.m, this.n ); - for ( var i = 0; i < this.m; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + const result = new dot.Matrix( this.m, this.n ); + for ( let i = 0; i < this.m; i++ ) { + for ( let j = 0; j < this.n; j++ ) { if ( i >= j ) { result.entries[ result.index( i, j ) ] = this.QR[ this.matrix.index( i, j ) ]; } @@ -95,9 +95,9 @@ define( require => { }, getR: function() { - var result = new dot.Matrix( this.n, this.n ); - for ( var i = 0; i < this.n; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + const result = new dot.Matrix( this.n, this.n ); + for ( let i = 0; i < this.n; i++ ) { + for ( let j = 0; j < this.n; j++ ) { if ( i < j ) { result.entries[ result.index( i, j ) ] = this.QR[ this.matrix.index( i, j ) ]; } @@ -113,10 +113,10 @@ define( require => { }, getQ: function() { - var i; - var j; - var k; - var result = new dot.Matrix( this.m, this.n ); + let i; + let j; + let k; + const result = new dot.Matrix( this.m, this.n ); for ( k = this.n - 1; k >= 0; k-- ) { for ( i = 0; i < this.m; i++ ) { result.entries[ result.index( i, k ) ] = 0.0; @@ -124,7 +124,7 @@ define( require => { result.entries[ result.index( k, k ) ] = 1.0; for ( j = k; j < this.n; j++ ) { if ( this.QR[ this.matrix.index( k, k ) ] !== 0 ) { - var s = 0.0; + let s = 0.0; for ( i = k; i < this.m; i++ ) { s += this.QR[ this.matrix.index( i, k ) ] * result.entries[ result.index( i, j ) ]; } @@ -146,18 +146,18 @@ define( require => { throw new Error( 'Matrix is rank deficient.' ); } - var i; - var j; - var k; + let i; + let j; + let k; // Copy right hand side - var nx = matrix.getColumnDimension(); - var X = matrix.getArrayCopy(); + const nx = matrix.getColumnDimension(); + const X = matrix.getArrayCopy(); // Compute Y = transpose(Q)*matrix for ( k = 0; k < this.n; k++ ) { for ( j = 0; j < nx; j++ ) { - var s = 0.0; + let s = 0.0; for ( i = k; i < this.m; i++ ) { s += this.QR[ this.matrix.index( i, k ) ] * X[ matrix.index( i, j ) ]; } diff --git a/js/Quaternion.js b/js/Quaternion.js index ad985bf..b266f5b 100644 --- a/js/Quaternion.js +++ b/js/Quaternion.js @@ -176,7 +176,7 @@ define( require => { * @returns {Quaternion} */ normalized: function() { - var magnitude = this.magnitude; + const magnitude = this.magnitude; assert && assert( magnitude !== 0, 'Cannot normalize a zero-magnitude quaternion' ); return this.timesScalar( 1 / magnitude ); }, @@ -201,18 +201,18 @@ define( require => { toRotationMatrix: function() { // see http://en.wikipedia.org/wiki/Rotation_matrix#Quaternion - var norm = this.magnitudeSquared; - var flip = ( norm === 1 ) ? 2 : ( norm > 0 ) ? 2 / norm : 0; + const norm = this.magnitudeSquared; + const flip = ( norm === 1 ) ? 2 : ( norm > 0 ) ? 2 / norm : 0; - var xx = this.x * this.x * flip; - var xy = this.x * this.y * flip; - var xz = this.x * this.z * flip; - var xw = this.w * this.x * flip; - var yy = this.y * this.y * flip; - var yz = this.y * this.z * flip; - var yw = this.w * this.y * flip; - var zz = this.z * this.z * flip; - var zw = this.w * this.z * flip; + const xx = this.x * this.x * flip; + const xy = this.x * this.y * flip; + const xz = this.x * this.z * flip; + const xw = this.w * this.x * flip; + const yy = this.y * this.y * flip; + const yz = this.y * this.z * flip; + const yw = this.w * this.y * flip; + const zz = this.z * this.z * flip; + const zw = this.w * this.z * flip; return dot.Matrix3.dirtyFromPool().columnMajor( 1 - ( yy + zz ), @@ -237,17 +237,17 @@ define( require => { * @returns {Quaternion} */ Quaternion.fromEulerAngles = function( yaw, roll, pitch ) { - var sinPitch = Math.sin( pitch * 0.5 ); - var cosPitch = Math.cos( pitch * 0.5 ); - var sinRoll = Math.sin( roll * 0.5 ); - var cosRoll = Math.cos( roll * 0.5 ); - var sinYaw = Math.sin( yaw * 0.5 ); - var cosYaw = Math.cos( yaw * 0.5 ); - - var a = cosRoll * cosPitch; - var b = sinRoll * sinPitch; - var c = cosRoll * sinPitch; - var d = sinRoll * cosPitch; + const sinPitch = Math.sin( pitch * 0.5 ); + const cosPitch = Math.cos( pitch * 0.5 ); + const sinRoll = Math.sin( roll * 0.5 ); + const cosRoll = Math.cos( roll * 0.5 ); + const sinYaw = Math.sin( yaw * 0.5 ); + const cosYaw = Math.cos( yaw * 0.5 ); + + const a = cosRoll * cosPitch; + const b = sinRoll * sinPitch; + const c = cosRoll * sinPitch; + const d = sinRoll * cosPitch; return new Quaternion( a * sinYaw + b * cosYaw, @@ -266,19 +266,19 @@ define( require => { * @returns {Quaternion} */ Quaternion.fromRotationMatrix = function( matrix ) { - var v00 = matrix.m00(); - var v01 = matrix.m01(); - var v02 = matrix.m02(); - var v10 = matrix.m10(); - var v11 = matrix.m11(); - var v12 = matrix.m12(); - var v20 = matrix.m20(); - var v21 = matrix.m21(); - var v22 = matrix.m22(); + const v00 = matrix.m00(); + const v01 = matrix.m01(); + const v02 = matrix.m02(); + const v10 = matrix.m10(); + const v11 = matrix.m11(); + const v12 = matrix.m12(); + const v20 = matrix.m20(); + const v21 = matrix.m21(); + const v22 = matrix.m22(); // from graphics gems code - var trace = v00 + v11 + v22; - var sqt; + const trace = v00 + v11 + v22; + let sqt; // we protect the division by s by ensuring that s>=1 if ( trace >= 0 ) { @@ -346,7 +346,7 @@ define( require => { return a; } - var dot = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; + let dot = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; if ( dot < 0 ) { b = b.negated(); @@ -354,13 +354,13 @@ define( require => { } // how much of each quaternion should be contributed - var ratioA = 1 - t; - var ratioB = t; + let ratioA = 1 - t; + let ratioB = t; // tweak them if necessary if ( ( 1 - dot ) > 0.1 ) { - var theta = Math.acos( dot ); - var invSinTheta = ( 1 / Math.sin( theta ) ); + const theta = Math.acos( dot ); + const invSinTheta = ( 1 / Math.sin( theta ) ); ratioA = ( Math.sin( ( 1 - t ) * theta ) * invSinTheta ); ratioB = ( Math.sin( ( t * theta ) ) * invSinTheta ); diff --git a/js/Random.js b/js/Random.js index 666dec8..bb7703c 100644 --- a/js/Random.js +++ b/js/Random.js @@ -43,7 +43,7 @@ define( require => { assert && assert( false, 'cannot specify seed and staticSeed, use one or the other' ); } - var seed = options.staticSeed ? window.phet.chipper.randomSeed : options.seed; + const seed = options.staticSeed ? window.phet.chipper.randomSeed : options.seed; this.setSeed( seed ); } @@ -77,7 +77,7 @@ define( require => { * @returns {number} - an integer */ nextInt: function( n ) { - var value = this.nextDouble() * n; + const value = this.nextDouble() * n; return value | 0; // convert to int by removing the decimal places }, @@ -94,7 +94,7 @@ define( require => { assert && assert( Util.isInteger( min ), 'min must be an integer: ' + min ); assert && assert( Util.isInteger( max ), 'max must be an integer: ' + max ); - var range = max - min; + const range = max - min; return this.nextInt( range + 1 ) + min; }, @@ -105,7 +105,7 @@ define( require => { */ sample: function( array ) { assert && assert( array.length > 0, 'Array should have at least 1 item.' ); - var index = this.nextIntBetween( 0, array.length - 1 ); + const index = this.nextIntBetween( 0, array.length - 1 ); return array[ index ]; }, @@ -118,12 +118,12 @@ define( require => { */ shuffle: function( array ) { assert && assert( array, 'Array should exist' ); - var self = this; - var index = -1; - var result = new Array( array.length ); + const self = this; + let index = -1; + const result = new Array( array.length ); _.forEach( array, function( value ) { - var rand = self.nextIntBetween( 0, ++index ); + const rand = self.nextIntBetween( 0, ++index ); result[ index ] = result[ rand ]; result[ rand ] = value; } ); diff --git a/js/RunningAverage.js b/js/RunningAverage.js index f2d9fb1..40640b4 100644 --- a/js/RunningAverage.js +++ b/js/RunningAverage.js @@ -52,7 +52,7 @@ define( require => { this.numSamples = 0; // Need to clear all of the samples - for ( var i = 0; i < this.windowSize; i++ ) { + for ( let i = 0; i < this.windowSize; i++ ) { this.samples[ i ] = 0; } }, diff --git a/js/SingularValueDecomposition.js b/js/SingularValueDecomposition.js index 7603afb..c6a64b5 100644 --- a/js/SingularValueDecomposition.js +++ b/js/SingularValueDecomposition.js @@ -11,61 +11,61 @@ define( require => { const dot = require( 'DOT/dot' ); - var ArrayType = window.Float64Array || Array; + const ArrayType = window.Float64Array || Array; // require( 'DOT/Matrix' ); // commented out so Require.js doesn't complain about the circular dependency function SingularValueDecomposition( matrix ) { this.matrix = matrix; - var Arg = matrix; + const Arg = matrix; // Derived from LINPACK code. // Initialize. - var A = Arg.getArrayCopy(); + const A = Arg.getArrayCopy(); this.m = Arg.getRowDimension(); this.n = Arg.getColumnDimension(); - var m = this.m; - var n = this.n; + const m = this.m; + const n = this.n; - var min = Math.min; - var max = Math.max; - var pow = Math.pow; - var abs = Math.abs; + const min = Math.min; + const max = Math.max; + const pow = Math.pow; + const abs = Math.abs; /* Apparently the failing cases are only a proper subset of (m= n"); } */ - var nu = min( m, n ); + const nu = min( m, n ); this.s = new ArrayType( min( m + 1, n ) ); - var s = this.s; + const s = this.s; this.U = new ArrayType( m * nu ); - var U = this.U; + const U = this.U; this.V = new ArrayType( n * n ); - var V = this.V; - var e = new ArrayType( n ); - var work = new ArrayType( m ); - var wantu = true; - var wantv = true; + const V = this.V; + const e = new ArrayType( n ); + const work = new ArrayType( m ); + const wantu = true; + const wantv = true; - var i; - var j; - var k; - var t; - var f; + let i; + let j; + let k; + let t; + let f; - var cs; - var sn; + let cs; + let sn; - var hypot = dot.Matrix.hypot; + const hypot = dot.Matrix.hypot; // Reduce A to bidiagonal form, storing the diagonal elements // in s and the super-diagonal elements in e. - var nct = min( m - 1, n ); - var nrt = max( 0, min( n - 2, m ) ); + const nct = min( m - 1, n ); + const nrt = max( 0, min( n - 2, m ) ); for ( k = 0; k < max( nct, nrt ); k++ ) { if ( k < nct ) { @@ -168,7 +168,7 @@ define( require => { // Set up the final bidiagonal matrix or order p. - var p = min( n, m + 1 ); + let p = min( n, m + 1 ); if ( nct < n ) { s[ nct ] = A[ nct * n + nct ]; } @@ -243,10 +243,10 @@ define( require => { // Main iteration loop for the singular values. - var pp = p - 1; - var iter = 0; - var eps = pow( 2.0, -52.0 ); - var tiny = pow( 2.0, -966.0 ); + const pp = p - 1; + let iter = 0; + const eps = pow( 2.0, -52.0 ); + const tiny = pow( 2.0, -966.0 ); while ( p > 0 ) { var kase; @@ -365,15 +365,15 @@ define( require => { // Calculate the shift. - var scale = max( max( max( max( abs( s[ p - 1 ] ), abs( s[ p - 2 ] ) ), abs( e[ p - 2 ] ) ), abs( s[ k ] ) ), abs( e[ k ] ) ); - var sp = s[ p - 1 ] / scale; - var spm1 = s[ p - 2 ] / scale; - var epm1 = e[ p - 2 ] / scale; - var sk = s[ k ] / scale; - var ek = e[ k ] / scale; - var b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2.0; - var c = (sp * epm1) * (sp * epm1); - var shift = 0.0; + const scale = max( max( max( max( abs( s[ p - 1 ] ), abs( s[ p - 2 ] ) ), abs( e[ p - 2 ] ) ), abs( s[ k ] ) ), abs( e[ k ] ) ); + const sp = s[ p - 1 ] / scale; + const spm1 = s[ p - 2 ] / scale; + const epm1 = e[ p - 2 ] / scale; + const sk = s[ k ] / scale; + const ek = e[ k ] / scale; + const b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2.0; + const c = (sp * epm1) * (sp * epm1); + let shift = 0.0; if ( (b !== 0.0) || (c !== 0.0) ) { shift = Math.sqrt( b * b + c ); if ( b < 0.0 ) { @@ -382,7 +382,7 @@ define( require => { shift = c / (b + shift); } f = (sk + sp) * (sk - sp) + shift; - var g = sk * ek; + let g = sk * ek; // Chase zeros. @@ -495,9 +495,9 @@ define( require => { }, getS: function() { - var result = new dot.Matrix( this.n, this.n ); - for ( var i = 0; i < this.n; i++ ) { - for ( var j = 0; j < this.n; j++ ) { + const result = new dot.Matrix( this.n, this.n ); + for ( let i = 0; i < this.n; i++ ) { + for ( let j = 0; j < this.n; j++ ) { result.entries[ result.index( i, j ) ] = 0.0; } result.entries[ result.index( i, i ) ] = this.s[ i ]; @@ -515,10 +515,10 @@ define( require => { rank: function() { // changed to 23 from 52 (bits of mantissa), since we are using floats here! - var eps = Math.pow( 2.0, -23.0 ); - var tol = Math.max( this.m, this.n ) * this.s[ 0 ] * eps; - var r = 0; - for ( var i = 0; i < this.s.length; i++ ) { + const eps = Math.pow( 2.0, -23.0 ); + const tol = Math.max( this.m, this.n ) * this.s[ 0 ] * eps; + let r = 0; + for ( let i = 0; i < this.s.length; i++ ) { if ( this.s[ i ] > tol ) { r++; } @@ -538,8 +538,8 @@ define( require => { * @returns {Matrix} - n x m */ SingularValueDecomposition.pseudoinverse = function( matrix ) { - var svd = new SingularValueDecomposition( matrix ); - var sigmaPseudoinverse = dot.Matrix.diagonalMatrix( svd.getSingularValues().map( function( value ) { + const svd = new SingularValueDecomposition( matrix ); + const sigmaPseudoinverse = dot.Matrix.diagonalMatrix( svd.getSingularValues().map( function( value ) { if ( Math.abs( value ) < 1e-300 ) { return 0; } diff --git a/js/Sphere3.js b/js/Sphere3.js index 09e87c6..869fb15 100644 --- a/js/Sphere3.js +++ b/js/Sphere3.js @@ -49,35 +49,35 @@ define( require => { * @returns {{ distance: number, hitPoint: Vector3, normal, fromOutside: boolean }| null} */ intersect: function( ray, epsilon ) { - var raydir = ray.direction; - var pos = ray.position; - var centerToRay = pos.minus( this.center ); + const raydir = ray.direction; + const pos = ray.position; + const centerToRay = pos.minus( this.center ); // basically, we can use the quadratic equation to solve for both possible hit points (both +- roots are the hit points) - var tmp = raydir.dot( centerToRay ); - var centerToRayDistSq = centerToRay.magnitudeSquared; - var det = 4 * tmp * tmp - 4 * ( centerToRayDistSq - this.radius * this.radius ); + const tmp = raydir.dot( centerToRay ); + const centerToRayDistSq = centerToRay.magnitudeSquared; + const det = 4 * tmp * tmp - 4 * ( centerToRayDistSq - this.radius * this.radius ); if ( det < epsilon ) { // ray misses sphere entirely return null; } - var base = raydir.dot( this.center ) - raydir.dot( pos ); - var sqt = Math.sqrt( det ) / 2; + const base = raydir.dot( this.center ) - raydir.dot( pos ); + const sqt = Math.sqrt( det ) / 2; // the "first" entry point distance into the sphere. if we are inside the sphere, it is behind us - var ta = base - sqt; + const ta = base - sqt; // the "second" entry point distance - var tb = base + sqt; + const tb = base + sqt; if ( tb < epsilon ) { // sphere is behind ray, so don't return an intersection return null; } - var hitPositionB = ray.pointAtDistance( tb ); - var normalB = hitPositionB.minus( this.center ).normalized(); + const hitPositionB = ray.pointAtDistance( tb ); + const normalB = hitPositionB.minus( this.center ).normalized(); if ( ta < epsilon ) { // we are inside the sphere @@ -91,8 +91,8 @@ define( require => { } else { // two possible hits - var hitPositionA = ray.pointAtDistance( ta ); - var normalA = hitPositionA.minus( this.center ).normalized(); + const hitPositionA = ray.pointAtDistance( ta ); + const normalA = hitPositionA.minus( this.center ).normalized(); // close hit, we have out => in return { @@ -117,46 +117,46 @@ define( require => { * results like { distance, hitPoint, normal, fromOutside }. */ intersections: function( ray, epsilon ) { - var raydir = ray.direction; - var pos = ray.position; - var centerToRay = pos.minus( this.center ); + const raydir = ray.direction; + const pos = ray.position; + const centerToRay = pos.minus( this.center ); // basically, we can use the quadratic equation to solve for both possible hit points (both +- roots are the hit points) - var tmp = raydir.dot( centerToRay ); - var centerToRayDistSq = centerToRay.magnitudeSquared; - var det = 4 * tmp * tmp - 4 * ( centerToRayDistSq - this.radius * this.radius ); + const tmp = raydir.dot( centerToRay ); + const centerToRayDistSq = centerToRay.magnitudeSquared; + const det = 4 * tmp * tmp - 4 * ( centerToRayDistSq - this.radius * this.radius ); if ( det < epsilon ) { // ray misses sphere entirely return []; } - var base = raydir.dot( this.center ) - raydir.dot( pos ); - var sqt = Math.sqrt( det ) / 2; + const base = raydir.dot( this.center ) - raydir.dot( pos ); + const sqt = Math.sqrt( det ) / 2; // the "first" entry point distance into the sphere. if we are inside the sphere, it is behind us - var ta = base - sqt; + const ta = base - sqt; // the "second" entry point distance - var tb = base + sqt; + const tb = base + sqt; if ( tb < epsilon ) { // sphere is behind ray, so don't return an intersection return []; } - var hitPositionB = ray.pointAtDistance( tb ); - var normalB = hitPositionB.minus( this.center ).normalized(); + const hitPositionB = ray.pointAtDistance( tb ); + const normalB = hitPositionB.minus( this.center ).normalized(); - var hitPositionA = ray.pointAtDistance( ta ); - var normalA = hitPositionA.minus( this.center ).normalized(); + const hitPositionA = ray.pointAtDistance( ta ); + const normalA = hitPositionA.minus( this.center ).normalized(); - var resultB = { + const resultB = { distance: tb, hitPoint: hitPositionB, normal: normalB.negated(), fromOutside: false }; - var resultA = { + const resultA = { distance: ta, hitPoint: hitPositionA, normal: normalA, diff --git a/js/Transform3.js b/js/Transform3.js index b6561e5..7c6cfc5 100644 --- a/js/Transform3.js +++ b/js/Transform3.js @@ -20,7 +20,7 @@ define( require => { require( 'DOT/Vector2' ); require( 'DOT/Ray2' ); - var scratchMatrix = new dot.Matrix3(); + const scratchMatrix = new dot.Matrix3(); function checkMatrix( matrix ) { return ( matrix instanceof dot.Matrix3 ) && matrix.isFinite(); @@ -198,7 +198,7 @@ define( require => { * @returns {Transform3} */ copy: function() { - var transform = new Transform3( this.matrix ); + const transform = new Transform3( this.matrix ); transform.inverse = this.inverse; transform.matrixTransposed = this.matrixTransposed; @@ -316,7 +316,7 @@ define( require => { * @returns {Vector2} */ transformDelta2: function( v ) { - var m = this.getMatrix(); + const m = this.getMatrix(); // m . v - m . Vector2.ZERO return new dot.Vector2( m.m00() * v.x + m.m01() * v.y, m.m10() * v.x + m.m11() * v.y ); }, @@ -346,7 +346,7 @@ define( require => { * @returns {number} */ transformX: function( x ) { - var m = this.getMatrix(); + const m = this.getMatrix(); assert && assert( !m.m01(), 'Transforming an X value with a rotation/shear is ill-defined' ); return m.m00() * x + m.m02(); }, @@ -360,7 +360,7 @@ define( require => { * @returns {number} */ transformY: function( y ) { - var m = this.getMatrix(); + const m = this.getMatrix(); assert && assert( !m.m10(), 'Transforming a Y value with a rotation/shear is ill-defined' ); return m.m11() * y + m.m12(); }, @@ -374,7 +374,7 @@ define( require => { * @returns {number} */ transformDeltaX: function( x ) { - var m = this.getMatrix(); + const m = this.getMatrix(); // same as this.transformDelta2( new dot.Vector2( x, 0 ) ).x; return m.m00() * x; }, @@ -388,7 +388,7 @@ define( require => { * @returns {number} */ transformDeltaY: function( y ) { - var m = this.getMatrix(); + const m = this.getMatrix(); // same as this.transformDelta2( new dot.Vector2( 0, y ) ).y; return m.m11() * y; }, @@ -462,7 +462,7 @@ define( require => { * @returns {Vector2} */ inverseDelta2: function( v ) { - var m = this.getInverse(); + const m = this.getInverse(); // m . v - m . Vector2.ZERO return new dot.Vector2( m.m00() * v.x + m.m01() * v.y, m.m10() * v.x + m.m11() * v.y ); }, @@ -496,7 +496,7 @@ define( require => { * @returns {number} */ inverseX: function( x ) { - var m = this.getInverse(); + const m = this.getInverse(); assert && assert( !m.m01(), 'Inverting an X value with a rotation/shear is ill-defined' ); return m.m00() * x + m.m02(); }, @@ -512,7 +512,7 @@ define( require => { * @returns {number} */ inverseY: function( y ) { - var m = this.getInverse(); + const m = this.getInverse(); assert && assert( !m.m10(), 'Inverting a Y value with a rotation/shear is ill-defined' ); return m.m11() * y + m.m12(); }, @@ -528,7 +528,7 @@ define( require => { * @returns {number} */ inverseDeltaX: function( x ) { - var m = this.getInverse(); + const m = this.getInverse(); assert && assert( !m.m01(), 'Inverting an X value with a rotation/shear is ill-defined' ); // same as this.inverseDelta2( new dot.Vector2( x, 0 ) ).x; return m.m00() * x; @@ -545,7 +545,7 @@ define( require => { * @returns {number} */ inverseDeltaY: function( y ) { - var m = this.getInverse(); + const m = this.getInverse(); assert && assert( !m.m10(), 'Inverting a Y value with a rotation/shear is ill-defined' ); // same as this.inverseDelta2( new dot.Vector2( 0, y ) ).y; return m.m11() * y; diff --git a/js/Transform3Tests.js b/js/Transform3Tests.js index 06d1a91..6ee1cf9 100644 --- a/js/Transform3Tests.js +++ b/js/Transform3Tests.js @@ -17,7 +17,7 @@ define( require => { QUnit.module( 'Transform3' ); - var epsilon = 1e-7; + const epsilon = 1e-7; function approximateEqual( assert, a, b, msg ) { assert.ok( Math.abs( a - b ) < epsilon, msg + ' expected: ' + b + ', got: ' + a ); @@ -28,31 +28,31 @@ define( require => { } QUnit.test( 'Ray2 transforms', function( assert ) { - var transform = new Transform3( Matrix3.createFromPool( 0, -2, 5, 3, 0, 8, 0, 0, 1 ) ); - var ray = new Ray2( new Vector2( 2, 7 ), new Vector2( -5, 2 ).normalized() ); + const transform = new Transform3( Matrix3.createFromPool( 0, -2, 5, 3, 0, 8, 0, 0, 1 ) ); + const ray = new Ray2( new Vector2( 2, 7 ), new Vector2( -5, 2 ).normalized() ); - var tray = transform.transformRay2( ray ); - var iray = transform.inverseRay2( ray ); + const tray = transform.transformRay2( ray ); + const iray = transform.inverseRay2( ray ); - var backOffset = transform.inversePosition2( tray.pointAtDistance( 1 ) ); - var backPos = transform.inversePosition2( tray.position ); + const backOffset = transform.inversePosition2( tray.pointAtDistance( 1 ) ); + const backPos = transform.inversePosition2( tray.position ); assert.ok( ray.direction.equalsEpsilon( backOffset.minus( backPos ).normalized(), 0.00001 ), 'transformRay2 ray linearity' ); - var forwardOffset = transform.transformPosition2( iray.pointAtDistance( 1 ) ); - var forwardPos = transform.transformPosition2( iray.position ); + const forwardOffset = transform.transformPosition2( iray.pointAtDistance( 1 ) ); + const forwardPos = transform.transformPosition2( iray.position ); assert.ok( ray.direction.equalsEpsilon( forwardOffset.minus( forwardPos ).normalized(), 0.00001 ), 'inverseRay2 ray linearity' ); approximateRayEqual( assert, transform.inverseRay2( transform.transformRay2( ray ) ), ray, 'inverse correctness' ); } ); QUnit.test( 'Transform x/y', function( assert ) { - var t = new Transform3( Matrix3.createFromPool( 2, 0, 10, 0, 3, 1, 0, 0, 1 ) ); + const t = new Transform3( Matrix3.createFromPool( 2, 0, 10, 0, 3, 1, 0, 0, 1 ) ); assert.equal( t.transformX( 5 ), 20 ); assert.equal( t.transformY( 5 ), 16 ); assert.equal( t.inverseX( 20 ), 5 ); assert.equal( t.inverseY( 16 ), 5 ); - var t2 = new Transform3( Matrix3.rotation2( Math.PI / 6 ) ); + const t2 = new Transform3( Matrix3.rotation2( Math.PI / 6 ) ); window.assert && assert.throws( function() { // eslint-disable-line no-undef t2.transformX( 5 ); } ); @@ -62,8 +62,8 @@ define( require => { } ); QUnit.test( 'Transform delta', function( assert ) { - var t1 = new Transform3( Matrix3.createFromPool( 2, 1, 0, -2, 5, 0, 0, 0, 1 ) ); - var t2 = new Transform3( Matrix3.createFromPool( 2, 1, 52, -2, 5, -61, 0, 0, 1 ) ); + const t1 = new Transform3( Matrix3.createFromPool( 2, 1, 0, -2, 5, 0, 0, 0, 1 ) ); + const t2 = new Transform3( Matrix3.createFromPool( 2, 1, 52, -2, 5, -61, 0, 0, 1 ) ); assert.ok( t1.transformDelta2( Vector2.ZERO ).equalsEpsilon( Vector2.ZERO, 1e-7 ), 'ensuring linearity at 0, no translation' ); assert.ok( t2.transformDelta2( Vector2.ZERO ).equalsEpsilon( Vector2.ZERO, 1e-7 ), 'ensuring linearity at 0, with translation' ); @@ -71,13 +71,13 @@ define( require => { assert.ok( t1.transformDelta2( new Vector2( 2, -3 ) ).equalsEpsilon( new Vector2( 1, -19 ), 1e-7 ), 'basic delta check, no translation' ); assert.ok( t2.transformDelta2( new Vector2( 2, -3 ) ).equalsEpsilon( new Vector2( 1, -19 ), 1e-7 ), 'basic delta check, with translation' ); - var v = new Vector2( -71, 27 ); + const v = new Vector2( -71, 27 ); assert.ok( t1.inverseDelta2( t1.transformDelta2( v ) ).equalsEpsilon( v, 1e-7 ), 'inverse check, no translation' ); assert.ok( t2.inverseDelta2( t2.transformDelta2( v ) ).equalsEpsilon( v, 1e-7 ), 'inverse check, with translation' ); } ); QUnit.test( 'Transform delta x/y', function( assert ) { - var t = new Transform3( Matrix3.createFromPool( 2, 0, 52, 0, 5, -61, 0, 0, 1 ) ); + const t = new Transform3( Matrix3.createFromPool( 2, 0, 52, 0, 5, -61, 0, 0, 1 ) ); approximateEqual( assert, t.transformDeltaX( 1 ), 2, 'deltaX' ); approximateEqual( assert, t.transformDeltaY( 1 ), 5, 'deltaY' ); @@ -85,15 +85,15 @@ define( require => { approximateEqual( assert, t.transformDeltaX( 71 ), t.transformDelta2( new Vector2( 71, 27 ) ).x, 'deltaX check vs transformDelta' ); approximateEqual( assert, t.transformDeltaY( 27 ), t.transformDelta2( new Vector2( 71, 27 ) ).y, 'deltaY check vs transformDelta' ); - var v = new Vector2( -71, 27 ); + const v = new Vector2( -71, 27 ); approximateEqual( assert, t.inverseDeltaX( t.transformDeltaX( v.x ) ), v.x, 'inverse check X' ); approximateEqual( assert, t.inverseDeltaY( t.transformDeltaY( v.y ) ), v.y, 'inverse check Y' ); } ); QUnit.test( 'Transform setMatrix ensuring matrix instance equivalence', function( assert ) { - var t = new Transform3(); + const t = new Transform3(); - var m = t.getMatrix(); + const m = t.getMatrix(); t.setMatrix( Matrix3.createFromPool( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) ); assert.equal( t.getMatrix(), m ); @@ -106,9 +106,9 @@ define( require => { } ); QUnit.test( 'Transform event firing', function( assert ) { - var t = new Transform3(); + const t = new Transform3(); - var count = 0; + let count = 0; t.on( 'change', function( assert ) { count += 1; } ); assert.equal( count, 0 ); @@ -123,7 +123,7 @@ define( require => { } ); QUnit.test( 'Transform inverse validation', function( assert ) { - var t = new Transform3(); + const t = new Transform3(); assert.ok( t.transformPosition2( new Vector2( 2, 4 ) ).equals( new Vector2( 2, 4 ) ) ); assert.ok( t.inversePosition2( new Vector2( 2, 4 ) ).equals( new Vector2( 2, 4 ) ) ); @@ -137,7 +137,7 @@ define( require => { } ); QUnit.test( 'transform creation and setting', function( assert ) { - var t = new Transform3(); + const t = new Transform3(); t.append( Matrix3.rotation2( Math.PI ) ); assert.ok( true, 'so we have at least 1 test in this set' ); } ); diff --git a/js/Transform4.js b/js/Transform4.js index 4cbb674..f9055ec 100644 --- a/js/Transform4.js +++ b/js/Transform4.js @@ -22,7 +22,7 @@ define( require => { require( 'DOT/Vector3' ); require( 'DOT/Ray3' ); - var scratchMatrix = new dot.Matrix4(); + const scratchMatrix = new dot.Matrix4(); /** * check if the matrix is Finite and is of type Matrix4 @@ -187,7 +187,7 @@ define( require => { * @returns {Transform4} */ copy: function() { - var transform = new Transform4( this.matrix ); + const transform = new Transform4( this.matrix ); transform.inverse = this.inverse; transform.matrixTransposed = this.matrixTransposed; diff --git a/js/Util.js b/js/Util.js index ce973ae..29868ee 100644 --- a/js/Util.js +++ b/js/Util.js @@ -14,13 +14,13 @@ define( require => { // require( 'DOT/Vector2' ); // Require.js doesn't like the circular reference // constants - var EPSILON = Number.MIN_VALUE; - var TWO_PI = 2 * Math.PI; + const EPSILON = Number.MIN_VALUE; + const TWO_PI = 2 * Math.PI; // "static" variables used in boxMullerTransform - var generate; - var z0; - var z1; + let generate; + let z0; + let z1; var Util = { /** @@ -60,10 +60,10 @@ define( require => { moduloBetweenDown: function( value, min, max ) { assert && assert( max > min, 'max > min required for moduloBetween' ); - var divisor = max - min; + const divisor = max - min; // get a partial result of value-min between [0,divisor) - var partial = ( value - min ) % divisor; + let partial = ( value - min ) % divisor; if ( partial < 0 ) { // since if value-min < 0, the remainder will give us a negative number partial += divisor; @@ -100,8 +100,8 @@ define( require => { if ( b < a ) { return []; } - var result = new Array( b - a + 1 ); - for ( var i = a; i <= b; i++ ) { + const result = new Array( b - a + 1 ); + for ( let i = a; i <= b; i++ ) { result[ i - a ] = i; } return result; @@ -196,7 +196,7 @@ define( require => { * @returns {Vector2|null} */ lineLineIntersection: function( p1, p2, p3, p4 ) { - var epsilon = 1e-10; + const epsilon = 1e-10; // If the endpoints are the same, they don't properly define a line if ( p1.equals( p2 ) || p3.equals( p4 ) ) { @@ -205,12 +205,12 @@ define( require => { // Taken from an answer in // http://stackoverflow.com/questions/385305/efficient-maths-algorithm-to-calculate-intersections - var x12 = p1.x - p2.x; - var x34 = p3.x - p4.x; - var y12 = p1.y - p2.y; - var y34 = p3.y - p4.y; + const x12 = p1.x - p2.x; + const x34 = p3.x - p4.x; + const y12 = p1.y - p2.y; + const y34 = p3.y - p4.y; - var denom = x12 * y34 - y12 * x34; + const denom = x12 * y34 - y12 * x34; // If the denominator is 0, lines are parallel or coincident if ( Math.abs( denom ) < epsilon ) { @@ -218,8 +218,8 @@ define( require => { } // define intersection using determinants, see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection - var a = p1.x * p2.y - p1.y * p2.x; - var b = p3.x * p4.y - p3.y * p4.x; + const a = p1.x * p2.y - p1.y * p2.x; + const b = p3.x * p4.y - p3.y * p4.x; return new dot.Vector2( ( a * x34 - x12 * b ) / denom, @@ -240,12 +240,12 @@ define( require => { // TODO: Can we make scratch vectors here, avoiding the circular reference? // midpoints between p1-p2 and p2-p3 - var p12 = new dot.Vector2( ( p1.x + p2.x ) / 2, ( p1.y + p2.y ) / 2 ); - var p23 = new dot.Vector2( ( p2.x + p3.x ) / 2, ( p2.y + p3.y ) / 2 ); + const p12 = new dot.Vector2( ( p1.x + p2.x ) / 2, ( p1.y + p2.y ) / 2 ); + const p23 = new dot.Vector2( ( p2.x + p3.x ) / 2, ( p2.y + p3.y ) / 2 ); // perpendicular points from the minpoints - var p12x = new dot.Vector2( p12.x + ( p2.y - p1.y ), p12.y - ( p2.x - p1.x ) ); - var p23x = new dot.Vector2( p23.x + ( p3.y - p2.y ), p23.y - ( p3.x - p2.x ) ); + const p12x = new dot.Vector2( p12.x + ( p2.y - p1.y ), p12.y - ( p2.x - p1.x ) ); + const p23x = new dot.Vector2( p23.x + ( p3.y - p2.y ), p23.y - ( p3.x - p2.x ) ); return Util.lineLineIntersection( p12, p12x, p23, p23x ); }, @@ -269,17 +269,17 @@ define( require => { assert && assert( Util.triangleAreaSigned( p1, p2, p3 ) > 0, 'Defined points should be in a counterclockwise order' ); - var m00 = p1.x - p.x; - var m01 = p1.y - p.y; - var m02 = ( p1.x - p.x ) * ( p1.x - p.x ) + ( p1.y - p.y ) * ( p1.y - p.y ); - var m10 = p2.x - p.x; - var m11 = p2.y - p.y; - var m12 = ( p2.x - p.x ) * ( p2.x - p.x ) + ( p2.y - p.y ) * ( p2.y - p.y ); - var m20 = p3.x - p.x; - var m21 = p3.y - p.y; - var m22 = ( p3.x - p.x ) * ( p3.x - p.x ) + ( p3.y - p.y ) * ( p3.y - p.y ); - - var determinant = m00 * m11 * m22 + m01 * m12 * m20 + m02 * m10 * m21 - m02 * m11 * m20 - m01 * m10 * m22 - m00 * m12 * m21; + const m00 = p1.x - p.x; + const m01 = p1.y - p.y; + const m02 = ( p1.x - p.x ) * ( p1.x - p.x ) + ( p1.y - p.y ) * ( p1.y - p.y ); + const m10 = p2.x - p.x; + const m11 = p2.y - p.y; + const m12 = ( p2.x - p.x ) * ( p2.x - p.x ) + ( p2.y - p.y ) * ( p2.y - p.y ); + const m20 = p3.x - p.x; + const m21 = p3.y - p.y; + const m22 = ( p3.x - p.x ) * ( p3.x - p.x ) + ( p3.y - p.y ) * ( p3.y - p.y ); + + const determinant = m00 * m11 * m22 + m01 * m12 * m20 + m02 * m10 * m21 - m02 * m11 * m20 - m01 * m10 * m22 - m00 * m12 * m21; return determinant > 0; }, @@ -308,37 +308,37 @@ define( require => { epsilon = epsilon === undefined ? 1e-5 : epsilon; // center is the origin for now, but leaving in computations so that we can change that in the future. optimize away if needed - var center = new dot.Vector3( 0, 0, 0 ); + const center = new dot.Vector3( 0, 0, 0 ); - var rayDir = ray.direction; - var pos = ray.position; - var centerToRay = pos.minus( center ); + const rayDir = ray.direction; + const pos = ray.position; + const centerToRay = pos.minus( center ); // basically, we can use the quadratic equation to solve for both possible hit points (both +- roots are the hit points) - var tmp = rayDir.dot( centerToRay ); - var centerToRayDistSq = centerToRay.magnitudeSquared; - var det = 4 * tmp * tmp - 4 * ( centerToRayDistSq - radius * radius ); + const tmp = rayDir.dot( centerToRay ); + const centerToRayDistSq = centerToRay.magnitudeSquared; + const det = 4 * tmp * tmp - 4 * ( centerToRayDistSq - radius * radius ); if ( det < epsilon ) { // ray misses sphere entirely return null; } - var base = rayDir.dot( center ) - rayDir.dot( pos ); - var sqt = Math.sqrt( det ) / 2; + const base = rayDir.dot( center ) - rayDir.dot( pos ); + const sqt = Math.sqrt( det ) / 2; // the "first" entry point distance into the sphere. if we are inside the sphere, it is behind us - var ta = base - sqt; + const ta = base - sqt; // the "second" entry point distance - var tb = base + sqt; + const tb = base + sqt; if ( tb < epsilon ) { // sphere is behind ray, so don't return an intersection return null; } - var hitPositionB = ray.pointAtDistance( tb ); - var normalB = hitPositionB.minus( center ).normalized(); + const hitPositionB = ray.pointAtDistance( tb ); + const normalB = hitPositionB.minus( center ).normalized(); if ( ta < epsilon ) { // we are inside the sphere @@ -352,8 +352,8 @@ define( require => { } else { // two possible hits - var hitPositionA = ray.pointAtDistance( ta ); - var normalA = hitPositionA.minus( center ).normalized(); + const hitPositionA = ray.pointAtDistance( ta ); + const normalA = hitPositionA.minus( center ).normalized(); // close hit, we have out => in return { @@ -402,16 +402,16 @@ define( require => { solveQuadraticRootsReal: function( a, b, c ) { // Check for a degenerate case where we don't have a quadratic, or if the order of magnitude is such where the // linear solution would be expected - var epsilon = 1E7; + const epsilon = 1E7; if ( a === 0 || Math.abs( b / a ) > epsilon || Math.abs( c / a ) > epsilon ) { return Util.solveLinearRootsReal( b, c ); } - var discriminant = b * b - 4 * a * c; + const discriminant = b * b - 4 * a * c; if ( discriminant < 0 ) { return []; } - var sqrt = Math.sqrt( discriminant ); + const sqrt = Math.sqrt( discriminant ); // TODO: how to handle if discriminant is 0? give unique root or double it? // TODO: probably just use Complex for the future return [ @@ -441,7 +441,7 @@ define( require => { } //We need to test whether a is several orders of magnitude less than b, c, d - var epsilon = 1E7; + const epsilon = 1E7; if ( a === 0 || Math.abs( b / a ) > epsilon || Math.abs( c / a ) > epsilon || Math.abs( d / a ) > epsilon ) { return Util.solveQuadraticRootsReal( b, c, d ); @@ -454,29 +454,29 @@ define( require => { c /= a; d /= a; - var q = ( 3.0 * c - ( b * b ) ) / 9; - var r = ( -( 27 * d ) + b * ( 9 * c - 2 * ( b * b ) ) ) / 54; - var discriminant = q * q * q + r * r; - var b3 = b / 3; + const q = ( 3.0 * c - ( b * b ) ) / 9; + const r = ( -( 27 * d ) + b * ( 9 * c - 2 * ( b * b ) ) ) / 54; + const discriminant = q * q * q + r * r; + const b3 = b / 3; if ( discriminant > 1e-7 ) { // a single real root - var dsqrt = Math.sqrt( discriminant ); + const dsqrt = Math.sqrt( discriminant ); return [ Util.cubeRoot( r + dsqrt ) + Util.cubeRoot( r - dsqrt ) - b3 ]; } // three real roots if ( discriminant === 0 ) { // contains a double root - var rsqrt = Util.cubeRoot( r ); - var doubleRoot = -b3 - rsqrt; + const rsqrt = Util.cubeRoot( r ); + const doubleRoot = -b3 - rsqrt; return [ -b3 + 2 * rsqrt, doubleRoot, doubleRoot ]; } else { // all unique - var qX = -q * q * q; + let qX = -q * q * q; qX = Math.acos( r / Math.sqrt( qX ) ); - var rr = 2 * Math.sqrt( -q ); + const rr = 2 * Math.sqrt( -q ); return [ -b3 + rr * Math.cos( qX / 3 ), -b3 + rr * Math.cos( ( qX + 2 * Math.PI ) / 3 ), @@ -544,8 +544,8 @@ define( require => { * @returns {string} */ toFixed: function( value, decimalPlaces ) { - var multiplier = Math.pow( 10, decimalPlaces ); - var newValue = Util.roundSymmetric( value * multiplier ) / multiplier; + const multiplier = Math.pow( 10, decimalPlaces ); + const newValue = Util.roundSymmetric( value * multiplier ) / multiplier; return newValue.toFixed( decimalPlaces ); }, @@ -611,7 +611,7 @@ define( require => { // Point1(a,b), Point2(c,d), Point3(e,f) // See http://jeffe.cs.illinois.edu/teaching/373/notes/x05-convexhull.pdf // @returns {number} - var ccw = function( a, b, c, d, e, f ) { + const ccw = function( a, b, c, d, e, f ) { return ( f - b ) * ( c - a ) - ( d - b ) * ( e - a ); }; @@ -624,7 +624,7 @@ define( require => { return null; } - var denom = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ); + const denom = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ); // If denominator is 0, the lines are parallel or coincident if ( Math.abs( denom ) < 1e-10 ) { return null; @@ -639,8 +639,8 @@ define( require => { } // Use determinants to calculate intersection, see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection - var intersectionX = ( ( x1 * y2 - y1 * x2 ) * ( x3 - x4 ) - ( x1 - x2 ) * ( x3 * y4 - y3 * x4 ) ) / denom; - var intersectionY = ( ( x1 * y2 - y1 * x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 * y4 - y3 * x4 ) ) / denom; + const intersectionX = ( ( x1 * y2 - y1 * x2 ) * ( x3 - x4 ) - ( x1 - x2 ) * ( x3 * y4 - y3 * x4 ) ) / denom; + const intersectionY = ( ( x1 * y2 - y1 * x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 * y4 - y3 * x4 ) ) / denom; return new dot.Vector2( intersectionX, intersectionY ); }, @@ -657,15 +657,15 @@ define( require => { */ distToSegmentSquared: function( point, a, b ) { // the square of the distance between a and b, - var segmentSquaredLength = a.distanceSquared( b ); + const segmentSquaredLength = a.distanceSquared( b ); // if the segment length is zero, the a and b point are coincident. return the squared distance between a and point if ( segmentSquaredLength === 0 ) { return point.distanceSquared( a ); } // the t value parametrize the projection of the point onto the a b line - var t = ( ( point.x - a.x ) * ( b.x - a.x ) + ( point.y - a.y ) * ( b.y - a.y ) ) / segmentSquaredLength; + const t = ( ( point.x - a.x ) * ( b.x - a.x ) + ( point.y - a.y ) * ( b.y - a.y ) ) / segmentSquaredLength; - var distanceSquared; + let distanceSquared; if ( t < 0 ) { // if t<0, the projection point is outside the ab line, beyond a @@ -811,8 +811,8 @@ define( require => { return z1 * sigma + mu; } - var u1; - var u2; + let u1; + let u2; do { u1 = random.nextDouble(); u2 = random.nextDouble(); @@ -830,8 +830,8 @@ define( require => { * @returns {number} */ numberOfDecimalPlaces: function( value ) { - var count = 0; - var multiplier = 1; + let count = 0; + let multiplier = 1; while ( ( value * multiplier ) % 1 !== 0 ) { count++; multiplier *= 10; diff --git a/js/UtilTests.js b/js/UtilTests.js index 6019825..094ea17 100644 --- a/js/UtilTests.js +++ b/js/UtilTests.js @@ -25,7 +25,7 @@ define( require => { const bSorted = b.slice().sort(); assert.equal( a.length, b.length, msg + ' (length different)' ); - for ( var i = 0; i < a.length; i++ ) { + for ( let i = 0; i < a.length; i++ ) { approximateEquals( assert, aSorted[ i ], bSorted[ i ], msg + ' (index ' + i + ')' ); } } @@ -49,29 +49,29 @@ define( require => { assert.equal( Util.roundSymmetric( 0.3 ), 0, '0.3 => 0' ); assert.equal( Util.roundSymmetric( 0.8 ), 1, '0.8 => 1' ); assert.equal( Util.roundSymmetric( -0.5 ), -1, '-0.5 => -1' ); - for ( var i = 0; i < 20; i++ ) { + for ( let i = 0; i < 20; i++ ) { assert.equal( Util.roundSymmetric( i ), i, i + ' integer' ); assert.equal( Util.roundSymmetric( -i ), -i, -i + ' integer' ); assert.equal( Util.roundSymmetric( i + 0.5 ), i + 1, ( i + 0.5 ) + ' => ' + ( i + 1 ) ); assert.equal( Util.roundSymmetric( -i - 0.5 ), -i - 1, ( -i - 0.5 ) + ' => ' + ( -i - 1 ) ); } - var original = dot.v2( 1.5, -2.5 ); - var rounded = original.roundedSymmetric(); + const original = dot.v2( 1.5, -2.5 ); + const rounded = original.roundedSymmetric(); assert.ok( original.equals( dot.v2( 1.5, -2.5 ) ), 'sanity' ); assert.ok( rounded.equals( dot.v2( 2, -3 ) ), 'rounded' ); - var result = original.roundSymmetric(); + const result = original.roundSymmetric(); assert.equal( result, original, 'reflexive' ); assert.ok( original.equals( rounded ), 'both rounded now' ); } ); QUnit.test( 'lineLineIntersection', function( assert ) { - var f = Util.lineLineIntersection; + const f = Util.lineLineIntersection; - var p1 = Vector2.ZERO; - var p2 = new Vector2( 1, 1 ); - var p3 = new Vector2( -10, 10 ); - var p4 = new Vector2( -12, 8 ); + const p1 = Vector2.ZERO; + const p2 = new Vector2( 1, 1 ); + const p3 = new Vector2( -10, 10 ); + const p4 = new Vector2( -12, 8 ); assert.equal( f( p1, p2, p3, p4 ), null ); assert.equal( f( p1, p4, p4, p1 ), null ); @@ -81,15 +81,15 @@ define( require => { } ); QUnit.test( 'lineSegmentIntersection', function( assert ) { - var h = Util.lineSegmentIntersection; + const h = Util.lineSegmentIntersection; - var p1 = dot.Vector2.ZERO; - var p2 = new dot.Vector2( 1, 1 ); - var p3 = new dot.Vector2( -10, 8 ); - var p4 = new dot.Vector2( -3, -3 ); - var p5 = new dot.Vector2( 8, -10 ); + const p1 = dot.Vector2.ZERO; + const p2 = new dot.Vector2( 1, 1 ); + const p3 = new dot.Vector2( -10, 8 ); + const p4 = new dot.Vector2( -3, -3 ); + const p5 = new dot.Vector2( 8, -10 ); - var f = function( p1, p2, p3, p4 ) { + const f = function( p1, p2, p3, p4 ) { return h( p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y ); }; @@ -108,11 +108,11 @@ define( require => { } ); QUnit.test( 'distToSegmentSquared', function( assert ) { - var f = Util.distToSegmentSquared; + const f = Util.distToSegmentSquared; - var p1 = Vector2.ZERO; - var p2 = new Vector2( -6, 0 ); - var p3 = new Vector2( -5, 1 ); + const p1 = Vector2.ZERO; + const p2 = new Vector2( -6, 0 ); + const p3 = new Vector2( -5, 1 ); approximateEquals( assert, f( p1, p2, p3 ), 26 ); approximateEquals( assert, f( p2, p3, p1 ), 2 ); @@ -134,7 +134,7 @@ define( require => { } ); QUnit.test( 'rangeInclusive', function( assert ) { - var arr = Util.rangeInclusive( 2, 4 ); + let arr = Util.rangeInclusive( 2, 4 ); assert.equal( arr.length, 3 ); assert.equal( arr[ 0 ], 2 ); assert.equal( arr[ 1 ], 3 ); @@ -145,7 +145,7 @@ define( require => { } ); QUnit.test( 'rangeExclusive', function( assert ) { - var arr = Util.rangeExclusive( 2, 4 ); + let arr = Util.rangeExclusive( 2, 4 ); assert.equal( arr.length, 1 ); assert.equal( arr[ 0 ], 3 ); diff --git a/js/Vector2.js b/js/Vector2.js index 1625206..6337dcb 100644 --- a/js/Vector2.js +++ b/js/Vector2.js @@ -91,8 +91,8 @@ define( require => { * @returns {number} */ distanceXY: function( x, y ) { - var dx = this.x - x; - var dy = this.y - y; + const dx = this.x - x; + const dy = this.y - y; return Math.sqrt( dx * dx + dy * dy ); }, @@ -104,8 +104,8 @@ define( require => { * @returns {number} */ distanceSquared: function( point ) { - var dx = this.x - point.x; - var dy = this.y - point.y; + const dx = this.x - point.x; + const dy = this.y - point.y; return dx * dx + dy * dy; }, @@ -118,8 +118,8 @@ define( require => { * @returns {number} */ distanceSquaredXY: function( x, y ) { - var dx = this.x - x; - var dy = this.y - y; + const dx = this.x - x; + const dy = this.y - y; return dx * dx + dy * dy; }, @@ -173,8 +173,8 @@ define( require => { * @returns {number} */ angleBetween: function( v ) { - var thisMagnitude = this.magnitude; - var vMagnitude = v.magnitude; + const thisMagnitude = this.magnitude; + const vMagnitude = v.magnitude; return Math.acos( dot.clamp( ( this.x * v.x + this.y * v.y ) / ( thisMagnitude * vMagnitude ), -1, 1 ) ); }, @@ -262,7 +262,7 @@ define( require => { * @returns {Vector2} */ normalized: function() { - var mag = this.magnitude; + const mag = this.magnitude; if ( mag === 0 ) { throw new Error( 'Cannot normalize a zero-magnitude vector' ); } @@ -481,8 +481,8 @@ define( require => { * @returns {Vector2} */ rotated: function( angle ) { - var newAngle = this.angle + angle; - var mag = this.magnitude; + const newAngle = this.angle + angle; + const mag = this.magnitude; return new Vector2( mag * Math.cos( newAngle ), mag * Math.sin( newAngle ) ); }, @@ -496,10 +496,10 @@ define( require => { * @returns {Vector2} this for chaining */ rotateAboutXY: function( x, y, angle ) { - var dx = this.x - x; - var dy = this.y - y; - var cos = Math.cos( angle ); - var sin = Math.sin( angle ); + const dx = this.x - x; + const dy = this.y - y; + const cos = Math.cos( angle ); + const sin = Math.sin( angle ); this.x = x + dx * cos - dy * sin; this.y = y + dx * sin + dy * cos; return this; // for chaining @@ -654,7 +654,7 @@ define( require => { * @returns {Vector2} */ setMagnitude: function( magnitude ) { - var scale = magnitude / this.magnitude; + const scale = magnitude / this.magnitude; return this.multiplyScalar( scale ); }, @@ -826,7 +826,7 @@ define( require => { * @returns {Vector2} */ normalize: function() { - var mag = this.magnitude; + const mag = this.magnitude; if ( mag === 0 ) { throw new Error( 'Cannot normalize a zero-magnitude vector' ); } @@ -860,8 +860,8 @@ define( require => { * @returns {Vector2} */ rotate: function( angle ) { - var newAngle = this.angle + angle; - var mag = this.magnitude; + const newAngle = this.angle + angle; + const mag = this.magnitude; return this.setXY( mag * Math.cos( newAngle ), mag * Math.sin( newAngle ) ); }, @@ -920,8 +920,8 @@ define( require => { * @returns {number} the angle between the vectors */ getAngleBetweenVectors: function( startVector, endVector ) { - var dx = endVector.x - startVector.x; - var dy = endVector.y - startVector.y; + const dx = endVector.x - startVector.x; + const dy = endVector.y - startVector.y; return Math.atan2( dy, dx ); }, @@ -932,8 +932,8 @@ define( require => { * @returns {number} the angle between the vectors */ getDistanceBetweenVectors: function( startVector, endVector ) { - var dx = endVector.x - startVector.x; - var dy = endVector.y - startVector.y; + const dx = endVector.x - startVector.x; + const dy = endVector.y - startVector.y; return Math.sqrt( dx * dx + dy * dy ); } } ); @@ -952,7 +952,7 @@ define( require => { Vector2.Immutable = function ImmutableVector2( x, y ) { Vector2.call( this, x, y ); }; - var Immutable = Vector2.Immutable; + const Immutable = Vector2.Immutable; inherit( Vector2, Immutable ); diff --git a/js/Vector3.js b/js/Vector3.js index ee455b5..7213bed 100644 --- a/js/Vector3.js +++ b/js/Vector3.js @@ -96,9 +96,9 @@ define( require => { * @returns {number} */ distanceXYZ: function( x, y, z ) { - var dx = this.x - x; - var dy = this.y - y; - var dz = this.z - z; + const dx = this.x - x; + const dy = this.y - y; + const dz = this.z - z; return Math.sqrt( dx * dx + dy * dy + dz * dz ); }, @@ -110,9 +110,9 @@ define( require => { * @returns {number} */ distanceSquared: function( point ) { - var dx = this.x - point.x; - var dy = this.y - point.y; - var dz = this.z - point.z; + const dx = this.x - point.x; + const dy = this.y - point.y; + const dz = this.z - point.z; return dx * dx + dy * dy + dz * dz; }, @@ -126,9 +126,9 @@ define( require => { * @returns {number} */ distanceSquaredXYZ: function( x, y, z ) { - var dx = this.x - x; - var dy = this.y - y; - var dz = this.z - z; + const dx = this.x - x; + const dy = this.y - y; + const dz = this.z - z; return dx * dx + dy * dy + dz * dz; }, @@ -257,7 +257,7 @@ define( require => { * @returns {Vector3} */ normalized: function() { - var mag = this.magnitude; + const mag = this.magnitude; if ( mag === 0 ) { throw new Error( 'Cannot normalize a zero-magnitude vector' ); } @@ -589,7 +589,7 @@ define( require => { * @returns {Vector3} */ setMagnitude: function( magnitude ) { - var scale = magnitude / this.magnitude; + const scale = magnitude / this.magnitude; return this.multiplyScalar( scale ); }, @@ -763,7 +763,7 @@ define( require => { * @returns {Vector3} */ normalize: function() { - var mag = this.magnitude; + const mag = this.magnitude; if ( mag === 0 ) { throw new Error( 'Cannot normalize a zero-magnitude vector' ); } @@ -818,7 +818,7 @@ define( require => { this.y = y !== undefined ? y : 0; this.z = z !== undefined ? z : 0; }; - var Immutable = Vector3.Immutable; + const Immutable = Vector3.Immutable; inherit( Vector3, Immutable ); diff --git a/js/Vector4.js b/js/Vector4.js index fc312fb..536c9ef 100644 --- a/js/Vector4.js +++ b/js/Vector4.js @@ -104,10 +104,10 @@ define( require => { * @returns {number} */ distanceXYZW: function( x, y, z, w ) { - var dx = this.x - x; - var dy = this.y - y; - var dz = this.z - z; - var dw = this.w - w; + const dx = this.x - x; + const dy = this.y - y; + const dz = this.z - z; + const dw = this.w - w; return Math.sqrt( dx * dx + dy * dy + dz * dz + dw * dw ); }, @@ -133,10 +133,10 @@ define( require => { * @returns {number} */ distanceSquaredXYZW: function( x, y, z, w ) { - var dx = this.x - x; - var dy = this.y - y; - var dz = this.z - z; - var dw = this.w - w; + const dx = this.x - x; + const dy = this.y - y; + const dz = this.z - z; + const dw = this.w - w; return dx * dx + dy * dy + dz * dz + dw * dw; }, @@ -251,7 +251,7 @@ define( require => { * @returns {Vector4} */ normalized: function() { - var magnitude = this.magnitude; + const magnitude = this.magnitude; assert && assert( magnitude !== 0, 'Cannot normalize a zero-magnitude vector' ); return this.dividedScalar( magnitude ); }, @@ -585,7 +585,7 @@ define( require => { * @returns {Vector4} */ setMagnitude: function( magnitude ) { - var scale = magnitude / this.magnitude; + const scale = magnitude / this.magnitude; return this.multiplyScalar( scale ); }, @@ -761,7 +761,7 @@ define( require => { * @returns {Vector4} */ normalize: function() { - var mag = this.magnitude; + const mag = this.magnitude; if ( mag === 0 ) { throw new Error( 'Cannot normalize a zero-magnitude vector' ); } @@ -802,7 +802,7 @@ define( require => { this.z = z !== undefined ? z : 0; this.w = w !== undefined ? w : 1; }; - var Immutable = Vector4.Immutable; + const Immutable = Vector4.Immutable; inherit( Vector4, Immutable ); diff --git a/js/dot.js b/js/dot.js index 34ee2a4..ccc0972 100644 --- a/js/dot.js +++ b/js/dot.js @@ -5,7 +5,7 @@ define( require => { const Namespace = require( 'PHET_CORE/Namespace' ); - var dot = new Namespace( 'dot' ); + const dot = new Namespace( 'dot' ); dot.register( 'v2', function( x, y ) { return new dot.Vector2( x, y ); } ); dot.register( 'v3', function( x, y, z ) { return new dot.Vector3( x, y, z ); } );