Browse files

Add rounding to radial snap for telling_time_2

fix #11155; fix #11159; fix #11178
close #11149; close #11167
  • Loading branch information...
1 parent 1770356 commit 64c5817391863fdb446eb783a8f85111287acde5 @beneater beneater committed Jan 13, 2012
Showing with 18 additions and 14 deletions.
  1. +4 −4 exercises/telling_time_2.html
  2. +14 −10 utils/interactive.js
View
8 exercises/telling_time_2.html
@@ -2,7 +2,7 @@
<html data-require="math math-format graphie time interactive angles word-problems">
<head>
<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>
</head>
<body>
@@ -12,9 +12,9 @@
<div class="vars">
<div data-ensure="!( HOUR === 1 && MINUTE === 0 )">
- <var id="HOUR">randRange( 1, 12 )</var>
- <var id="MINUTE_INCREMENT">15</var>
- <var id="MINUTE">randRange( 0, (60 / MINUTE_INCREMENT) - 1 ) * MINUTE_INCREMENT</var>
+ <var id="HOUR">randRange( 1, 12 )</var>
+ <var id="MINUTE_INCREMENT">15</var>
+ <var id="MINUTE">randRange( 0, (60 / MINUTE_INCREMENT) - 1 ) * MINUTE_INCREMENT</var>
</div>
<var id="MINUTE_IS_ZERO">MINUTE === 0</var>
<var id="NICE_MINUTE"> MINUTE &gt; 5 ? MINUTE : "0" + MINUTE</var>
View
24 utils/interactive.js
@@ -321,6 +321,18 @@ jQuery.extend( KhanUtil, {
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
if ( movablePoint.constraints.fixedDistance.snapPoints ) {
@@ -351,18 +363,10 @@ jQuery.extend( KhanUtil, {
// convert back to coordinates relative to graphie canvas
mouseX = mouseXrel + centerX;
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
var coord = movablePoint.applyConstraint([ coordX, coordY ]);
coordX = coord[0];

0 comments on commit 64c5817

Please sign in to comment.