diff --git a/utils/congruence.js b/utils/congruence.js index cd9d40333..afdb14bf2 100644 --- a/utils/congruence.js +++ b/utils/congruence.js @@ -52,7 +52,7 @@ jQuery.extend( KhanUtil, { // When point 0 moves, check if it's close enough to point 3 to make a triangle triangle.points[0].onMove = function( coordX, coordY ) { triangle.points[0].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { triangle.snapCorrect(); } triangle.update(); @@ -62,7 +62,7 @@ jQuery.extend( KhanUtil, { // When point 3 moves, check if it's close enough to point 0 to make a triangle triangle.points[3].onMove = function( coordX, coordY ) { triangle.points[3].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { triangle.snapCorrect(); } triangle.update(); @@ -117,7 +117,7 @@ jQuery.extend( KhanUtil, { // When point 0 moves, check if it's close enough to point 3 to make a triangle triangle.points[0].onMove = function( coordX, coordY ) { triangle.points[0].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { triangle.snapCorrect(); } triangle.update(); @@ -130,12 +130,12 @@ jQuery.extend( KhanUtil, { triangle.points[2].coord = [ coordX, coordY ]; triangle.points[3].setCoord(triangle.points[3].applyConstraint( triangle.points[3].coord, { fixedDistance: { - dist: KhanUtil.distance( triangle.points[3].coord, origCoord ), + dist: KhanUtil.getDistance( triangle.points[3].coord, origCoord ), point: triangle.points[2] } })); // Check if point 3 ends up close enough to point 0 to make a triangle - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { triangle.snapCorrect(); } triangle.update(); @@ -144,7 +144,7 @@ jQuery.extend( KhanUtil, { // When point 3 moves, check if it's close enough to point 0 to make a triangle triangle.points[3].onMove = function( coordX, coordY ) { triangle.points[3].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { triangle.snapCorrect(); } triangle.update(); @@ -154,7 +154,7 @@ jQuery.extend( KhanUtil, { triangle.snapCorrect = function() { var angle1 = options.triangle.angles[1] * (triangle.reflected ? -1 : 1); // SSA has two possible shapes: See which one we're closest to' - if ( Math.abs( KhanUtil.distance( triangle.points[2].coord, triangle.points[3].coord ) - options.triangle.sideLengths[2] ) > 1.0 ) { + if ( Math.abs( KhanUtil.getDistance( triangle.points[2].coord, triangle.points[3].coord ) - options.triangle.sideLengths[2] ) > 1.0 ) { this.isCongruent = false; angle1 = Math.abs(angle1); var angle2 = Math.abs(options.triangle.angles[2] * (triangle.reflected ? -1 : 1)); @@ -210,7 +210,7 @@ jQuery.extend( KhanUtil, { } })); // Check if point 0 ends up close enough to point 3 to make a triangle - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { triangle.snapCorrect(); } triangle.update(); @@ -220,7 +220,7 @@ jQuery.extend( KhanUtil, { // When point 3 moves, check if it's close enough to point 0 to make a triangle triangle.points[3].onMove = function( coordX, coordY ) { triangle.points[3].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.2 ) { triangle.snapCorrect(); } triangle.update(); @@ -270,7 +270,7 @@ jQuery.extend( KhanUtil, { } })); // Check if point 0 ends up close enough to point 3 to make a triangle - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { triangle.snapCorrect(); } triangle.update(); @@ -280,7 +280,7 @@ jQuery.extend( KhanUtil, { // When point 3 moves, check if it's close enough to point 0 to make a triangle triangle.points[3].onMove = function( coordX, coordY ) { triangle.points[3].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { triangle.snapCorrect(); } triangle.update(); @@ -340,7 +340,7 @@ jQuery.extend( KhanUtil, { // When point 0 moves, check if it's close enough to point 3 to make a triangle triangle.points[0].onMove = function( coordX, coordY ) { triangle.points[0].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { triangle.snapCorrect(); } triangle.update(); @@ -350,7 +350,7 @@ jQuery.extend( KhanUtil, { // When point 3 moves, check if it's close enough to point 0 to make a triangle triangle.points[3].onMove = function( coordX, coordY ) { triangle.points[3].coord = [ coordX, coordY ]; - if ( KhanUtil.distance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { + if ( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[3].coord ) < 0.3 ) { triangle.snapCorrect(); } triangle.update(); @@ -408,7 +408,7 @@ jQuery.extend( KhanUtil, { var origCoord = triangle.points[3].coord; triangle.points[3].coord = [ coordX, coordY ]; triangle.points[0].setCoord([ coordX, coordY ]); - var scaleFactor = KhanUtil.distance([ coordX, coordY ], triangle.rotationPoint.coord) / triangle.radii[3]; + var scaleFactor = KhanUtil.getDistance([ coordX, coordY ], triangle.rotationPoint.coord) / triangle.radii[3]; triangle.points[1].setCoord( triangle.points[1].applyConstraint( triangle.points[1].coord, { fixedDistance: { dist: triangle.radii[1] * scaleFactor, @@ -422,7 +422,7 @@ jQuery.extend( KhanUtil, { } })); // Check if the triangle is close enough to congruent to make it easier/possible to get wrong - if ( Math.abs( KhanUtil.distance( triangle.points[0].coord, triangle.points[1].coord ) - options.triangle.sideLengths[0] ) < 0.3 ) { + if ( Math.abs( KhanUtil.getDistance( triangle.points[0].coord, triangle.points[1].coord ) - options.triangle.sideLengths[0] ) < 0.3 ) { triangle.snapCorrect(); triangle.isCongruent = true; } else { @@ -435,20 +435,20 @@ jQuery.extend( KhanUtil, { triangle.snapCorrect = function() { this.points[3].setCoord( this.points[0].applyConstraint( this.points[0].coord, { fixedDistance: { - dist: KhanUtil.distance( options.triangle.points[0], options.triangle.centroid ), + dist: KhanUtil.getDistance( options.triangle.points[0], options.triangle.centroid ), point: this.rotationPoint } })); this.points[0].setCoord( this.points[3].coord ); this.points[1].setCoord( this.points[1].applyConstraint( this.points[1].coord, { fixedDistance: { - dist: KhanUtil.distance( options.triangle.points[1], options.triangle.centroid ), + dist: KhanUtil.getDistance( options.triangle.points[1], options.triangle.centroid ), point: this.rotationPoint } })); this.points[2].setCoord( this.points[2].applyConstraint( this.points[2].coord, { fixedDistance: { - dist: KhanUtil.distance( options.triangle.points[2], options.triangle.centroid ), + dist: KhanUtil.getDistance( options.triangle.points[2], options.triangle.centroid ), point: this.rotationPoint } })); @@ -495,7 +495,7 @@ jQuery.extend( KhanUtil, { } for ( var point = 0; point < 4; ++point ) { - triangle.radii[point] = KhanUtil.distance( triangle.points[point].coord, triangle.rotationPoint.coord ); + triangle.radii[point] = KhanUtil.getDistance( triangle.points[point].coord, triangle.rotationPoint.coord ); if ( triangle.points[point].isRotationPoint ) { triangle.points[point].constraints.fixedDistance = { dist: triangle.radii[point], point: triangle.rotationPoint }; } diff --git a/utils/interactive.js b/utils/interactive.js index 3cf2c4880..13d9aac69 100644 --- a/utils/interactive.js +++ b/utils/interactive.js @@ -1,8 +1,8 @@ jQuery.extend( KhanUtil, { - + // Fill opacity for inequality shading FILL_OPACITY: 0.3, - + dragging: false, // Wrap graphInit to create a fixed-size graph automatically scaled to the given range @@ -248,7 +248,7 @@ jQuery.extend( KhanUtil, { var constrainedAngle = (constraints.fixedAngle.angle + KhanUtil.findAngle( ref, vertex ) ) * Math.PI / 180; // angle is the angle from vertex to the mouse with reference to the screen var angle = KhanUtil.findAngle( coord, vertex ) * Math.PI / 180; - var distance = KhanUtil.distance( coord, vertex ); + var distance = KhanUtil.getDistance( coord, vertex ); var length = distance * Math.cos(constrainedAngle - angle); length = length < 1.0 ? 1.0 : length; newCoord[0] = length * Math.cos(constrainedAngle) + vertex[0]; @@ -384,7 +384,7 @@ jQuery.extend( KhanUtil, { // as part of a hint to show the user the correct place to put the point. movablePoint.moveTo = function( coordX, coordY, updateLines ) { // find distance in pixels to move - var distance = KhanUtil.distance( this.graph.scalePoint([ coordX, coordY ]), this.graph.scalePoint( this.coord ) ); + var distance = KhanUtil.getDistance( this.graph.scalePoint([ coordX, coordY ]), this.graph.scalePoint( this.coord ) ); // 5ms per pixel seems good var time = distance * 5; @@ -635,7 +635,7 @@ jQuery.extend( KhanUtil, { }).join(""); }, - distance: function( point1, point2 ) { + getDistance: function( point1, point2 ) { return Math.sqrt( (point1[0] - point2[0]) * (point1[0] - point2[0]) + (point1[1] - point2[1]) * (point1[1] - point2[1]) ); }, @@ -895,7 +895,7 @@ jQuery.extend( KhanUtil, { } var angle = KhanUtil.findAngle( this.coordZ, this.coordA ); var scaledA = graph.scalePoint( this.coordA ); - var lineLength = KhanUtil.distance(this.coordA, this.coordZ); + var lineLength = KhanUtil.getDistance(this.coordA, this.coordZ); if ( this.extendLine ) { if ( this.coordA[0] !== this.coordZ[0] ) { var slope = ( this.coordZ[1] - this.coordA[1] ) / ( this.coordZ[0] - this.coordA[0] ); @@ -908,7 +908,7 @@ jQuery.extend( KhanUtil, { scaledA = graph.scalePoint([ graph.range[0][1], y2 ]); scaledA[0]--; } - lineLength = KhanUtil.distance( [ graph.range[0][0], y1 ], [ graph.range[0][1], y2 ] ); + lineLength = KhanUtil.getDistance( [ graph.range[0][0], y1 ], [ graph.range[0][1], y2 ] ); } else { if (this.coordA[1] < this.coordZ[1] ) { scaledA = graph.scalePoint([ this.coordA[0], graph.range[1][0] ]); diff --git a/utils/parabola-intuition.js b/utils/parabola-intuition.js index aa680d5c9..7b707496b 100644 --- a/utils/parabola-intuition.js +++ b/utils/parabola-intuition.js @@ -15,7 +15,7 @@ jQuery.extend( KhanUtil, { directrixLine.remove(); lineEndcap.remove(); graph.style({ strokeWidth: 1.5, stroke: KhanUtil.GREEN, opacity: 0.0 }); - var vertexDistance = KhanUtil.distance( [ coordX, coordY ], vertex.coord ); + var vertexDistance = KhanUtil.getDistance( [ coordX, coordY ], vertex.coord ); // Draw a line from the vertex to the highlighted point on the parabola vertexLine = graph.line( [coordX, coordY], vertex.coord );