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

Commit

Permalink
Add rounding to radial snap for telling_time_2
Browse files Browse the repository at this point in the history
fix #11155; fix #11159; fix #11178
close #11149; close #11167
  • Loading branch information
beneater committed Jan 14, 2012
1 parent 1770356 commit 64c5817
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions exercises/telling_time_2.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html data-require="math math-format graphie time interactive angles word-problems"> <html data-require="math math-format graphie time interactive angles word-problems">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Setting time</title> <title>Telling time 2</title>
<script src="../khan-exercise.js"></script> <script src="../khan-exercise.js"></script>
</head> </head>
<body> <body>
Expand All @@ -12,9 +12,9 @@


<div class="vars"> <div class="vars">
<div data-ensure="!( HOUR === 1 && MINUTE === 0 )"> <div data-ensure="!( HOUR === 1 && MINUTE === 0 )">
<var id="HOUR">randRange( 1, 12 )</var> <var id="HOUR">randRange( 1, 12 )</var>
<var id="MINUTE_INCREMENT">15</var> <var id="MINUTE_INCREMENT">15</var>
<var id="MINUTE">randRange( 0, (60 / MINUTE_INCREMENT) - 1 ) * MINUTE_INCREMENT</var> <var id="MINUTE">randRange( 0, (60 / MINUTE_INCREMENT) - 1 ) * MINUTE_INCREMENT</var>
</div> </div>
<var id="MINUTE_IS_ZERO">MINUTE === 0</var> <var id="MINUTE_IS_ZERO">MINUTE === 0</var>
<var id="NICE_MINUTE"> MINUTE &gt; 5 ? MINUTE : "0" + MINUTE</var> <var id="NICE_MINUTE"> MINUTE &gt; 5 ? MINUTE : "0" + MINUTE</var>
Expand Down
24 changes: 14 additions & 10 deletions utils/interactive.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -321,6 +321,18 @@ jQuery.extend( KhanUtil, {
mouseY = Math.round(mouseY / (graph.scale[1] * movablePoint.snapY)) * (graph.scale[1] * movablePoint.snapY); mouseY = Math.round(mouseY / (graph.scale[1] * movablePoint.snapY)) * (graph.scale[1] * movablePoint.snapY);
} }


// coord{X|Y} are the scaled coordinate values
var coordX = mouseX / graph.scale[0] + graph.range[0][0];
var coordY = graph.range[1][1] - mouseY / graph.scale[1];

// snap coordinates to grid
if ( movablePoint.snapX !== 0 ) {
coordX = Math.round( coordX / movablePoint.snapX ) * movablePoint.snapX;
}
if ( movablePoint.snapY !== 0 ) {
coordY = Math.round( coordY / movablePoint.snapY ) * movablePoint.snapY;
}

// snap to points around circle // snap to points around circle
if ( movablePoint.constraints.fixedDistance.snapPoints ) { if ( movablePoint.constraints.fixedDistance.snapPoints ) {


Expand Down Expand Up @@ -351,18 +363,10 @@ jQuery.extend( KhanUtil, {
// convert back to coordinates relative to graphie canvas // convert back to coordinates relative to graphie canvas
mouseX = mouseXrel + centerX; mouseX = mouseXrel + centerX;
mouseY = - mouseYrel + centerY; mouseY = - mouseYrel + centerY;
coordX = KhanUtil.roundTo( 5, mouseX / graph.scale[0] + graph.range[0][0] );
coordY = KhanUtil.roundTo( 5, graph.range[1][1] - mouseY / graph.scale[1] );
} }


// coord{X|Y} are the scaled coordinate values
var coordX = mouseX / graph.scale[0] + graph.range[0][0];
var coordY = graph.range[1][1] - mouseY / graph.scale[1];
// snap coordinates to grid
if ( movablePoint.snapX !== 0 ) {
coordX = Math.round( coordX / movablePoint.snapX ) * movablePoint.snapX;
}
if ( movablePoint.snapY !== 0 ) {
coordY = Math.round( coordY / movablePoint.snapY ) * movablePoint.snapY;
}
// apply any constraints on movement // apply any constraints on movement
var coord = movablePoint.applyConstraint([ coordX, coordY ]); var coord = movablePoint.applyConstraint([ coordX, coordY ]);
coordX = coord[0]; coordX = coord[0];
Expand Down

0 comments on commit 64c5817

Please sign in to comment.