Fix degToRad function definition. Resolves GH-229

This commit is contained in:
Andrew Sliwinski 2016-10-17 11:52:02 -04:00
parent 80fa2d5a58
commit ace9a96fc2
3 changed files with 7 additions and 8 deletions

View file

@ -37,7 +37,7 @@ Scratch3MotionBlocks.prototype.getPrimitives = function() {
Scratch3MotionBlocks.prototype.moveSteps = function (args, util) { Scratch3MotionBlocks.prototype.moveSteps = function (args, util) {
var steps = Cast.toNumber(args.STEPS); 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 dx = steps * Math.cos(radians);
var dy = steps * Math.sin(radians); var dy = steps * Math.sin(radians);
util.target.setXY(util.target.x + dx, util.target.y + dy); util.target.setXY(util.target.x + dx, util.target.y + dy);

View file

@ -6,7 +6,7 @@ function MathUtil () {}
* @return {!number} Equivalent value in radians. * @return {!number} Equivalent value in radians.
*/ */
MathUtil.degToRad = function (deg) { MathUtil.degToRad = function (deg) {
return (Math.PI * (90 - deg)) / 180; return deg * Math.PI / 180;
}; };
/** /**

View file

@ -2,12 +2,11 @@ var test = require('tap').test;
var math = require('../../src/util/math-util'); var math = require('../../src/util/math-util');
test('degToRad', function (t) { test('degToRad', function (t) {
// @todo This is incorrect t.strictEqual(math.degToRad(0), 0);
t.strictEqual(math.degToRad(0), 1.5707963267948966); t.strictEqual(math.degToRad(1), 0.017453292519943295);
t.strictEqual(math.degToRad(1), 1.5533430342749535); t.strictEqual(math.degToRad(180), Math.PI);
t.strictEqual(math.degToRad(180), -1.5707963267948966); t.strictEqual(math.degToRad(360), 2 * Math.PI);
t.strictEqual(math.degToRad(360), -4.71238898038469); t.strictEqual(math.degToRad(720), 4 * Math.PI);
t.strictEqual(math.degToRad(720), -10.995574287564276);
t.end(); t.end();
}); });