From ace9a96fc2cdd5962deab0f48f9064cfa8212788 Mon Sep 17 00:00:00 2001 From: Andrew Sliwinski Date: Mon, 17 Oct 2016 11:52:02 -0400 Subject: [PATCH] Fix degToRad function definition. Resolves GH-229 --- src/blocks/scratch3_motion.js | 2 +- src/util/math-util.js | 2 +- test/unit/util_math.js | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/blocks/scratch3_motion.js b/src/blocks/scratch3_motion.js index 3e19e6ef1..a8687e4f9 100644 --- a/src/blocks/scratch3_motion.js +++ b/src/blocks/scratch3_motion.js @@ -37,7 +37,7 @@ Scratch3MotionBlocks.prototype.getPrimitives = function() { Scratch3MotionBlocks.prototype.moveSteps = function (args, util) { var steps = Cast.toNumber(args.STEPS); - var radians = MathUtil.degToRad(util.target.direction); + var radians = MathUtil.degToRad(90 - util.target.direction); var dx = steps * Math.cos(radians); var dy = steps * Math.sin(radians); util.target.setXY(util.target.x + dx, util.target.y + dy); diff --git a/src/util/math-util.js b/src/util/math-util.js index b53698ef1..14ebb450e 100644 --- a/src/util/math-util.js +++ b/src/util/math-util.js @@ -6,7 +6,7 @@ function MathUtil () {} * @return {!number} Equivalent value in radians. */ MathUtil.degToRad = function (deg) { - return (Math.PI * (90 - deg)) / 180; + return deg * Math.PI / 180; }; /** diff --git a/test/unit/util_math.js b/test/unit/util_math.js index b282e90cc..b198ef1d3 100644 --- a/test/unit/util_math.js +++ b/test/unit/util_math.js @@ -2,12 +2,11 @@ var test = require('tap').test; var math = require('../../src/util/math-util'); test('degToRad', function (t) { - // @todo This is incorrect - t.strictEqual(math.degToRad(0), 1.5707963267948966); - t.strictEqual(math.degToRad(1), 1.5533430342749535); - t.strictEqual(math.degToRad(180), -1.5707963267948966); - t.strictEqual(math.degToRad(360), -4.71238898038469); - t.strictEqual(math.degToRad(720), -10.995574287564276); + t.strictEqual(math.degToRad(0), 0); + t.strictEqual(math.degToRad(1), 0.017453292519943295); + t.strictEqual(math.degToRad(180), Math.PI); + t.strictEqual(math.degToRad(360), 2 * Math.PI); + t.strictEqual(math.degToRad(720), 4 * Math.PI); t.end(); });