From 08ed474897cd9de8e4f4c60ac57dcada7ab1cd4d Mon Sep 17 00:00:00 2001 From: Stephen Chang Date: Wed, 3 Jun 2015 14:53:44 -0400 Subject: [PATCH] support (-360,360) angles for whalesong/image rotate --- whalesong/image/private/js-impl.js | 11 +++++++++-- whalesong/image/private/kernel.js | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/whalesong/image/private/js-impl.js b/whalesong/image/private/js-impl.js index 18c3099..3802c7e 100644 --- a/whalesong/image/private/js-impl.js +++ b/whalesong/image/private/js-impl.js @@ -154,6 +154,9 @@ var checkPlaceY = plt.baselib.check.makeCheckArgumentType( var checkAngle = plt.baselib.check.makeCheckArgumentType( isAngle, "finite real number between 0 and 360"); +var checkRotateAngle = plt.baselib.check.makeCheckArgumentType( + isRotateAngle, + "finite real number between -360 and 360"); var checkMode = plt.baselib.check.makeCheckArgumentType( @@ -790,9 +793,13 @@ EXPORTS['rotate'] = 'rotate', 2, function(MACHINE) { - var angle = checkAngle(MACHINE, "rotate", 0); + var angle = checkRotateAngle(MACHINE, "rotate", 0); var img = checkImage(MACHINE, "rotate", 1); - return makeRotateImage(jsnums.toFixnum(-angle), img); + if (jsnums.lessThan(angle, 0)) { + return makeRotateImage(jsnums.toFixnum(-(360 + angle)), img); + } else { + return makeRotateImage(jsnums.toFixnum(-angle), img); + } }); diff --git a/whalesong/image/private/kernel.js b/whalesong/image/private/kernel.js index b5d1806..fdd03b0 100644 --- a/whalesong/image/private/kernel.js +++ b/whalesong/image/private/kernel.js @@ -26,6 +26,12 @@ var isAngle = function(x) { jsnums.greaterThanOrEqual(x, 0) && jsnums.lessThan(x, 360); }; +// differentiate between rotation angle and other angles +var isRotateAngle = function(x) { + return plt.baselib.numbers.isReal(x) && + jsnums.greaterThan(x, -360) && + jsnums.lessThan(x, 360); +}; // Produces true if the value is a color or a color string. @@ -1469,6 +1475,7 @@ EXPORTS.isImage = isImage; EXPORTS.isScene = isScene; EXPORTS.isColorOrColorString = isColorOrColorString; EXPORTS.isAngle = isAngle; +EXPORTS.isRotateAngle = isRotateAngle; EXPORTS.isSideCount = isSideCount; EXPORTS.isStepCount = isStepCount; EXPORTS.isPointsCount = isPointsCount;