Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Resolve KhanUtil.distance() name collision between word-problems and …
Browse files Browse the repository at this point in the history
…interactive
  • Loading branch information
beneater committed Dec 14, 2011
1 parent 72121d8 commit 9c5aae3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
38 changes: 19 additions & 19 deletions utils/congruence.js
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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
}
}));
Expand Down Expand Up @@ -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 };
}
Expand Down
14 changes: 7 additions & 7 deletions 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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]) );
},

Expand Down Expand Up @@ -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] );
Expand All @@ -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] ]);
Expand Down
2 changes: 1 addition & 1 deletion utils/parabola-intuition.js
Expand Up @@ -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 );
Expand Down

0 comments on commit 9c5aae3

Please sign in to comment.