From e89a292c7144ee856fe364a10d5a65e892961c07 Mon Sep 17 00:00:00 2001 From: KevinGrajeda Date: Fri, 27 May 2022 18:16:36 -0500 Subject: [PATCH 1/3] add parameter validation and return to angleMode --- src/math/trigonometry.js | 13 +++++++++++-- test/unit/math/trigonometry.js | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/math/trigonometry.js b/src/math/trigonometry.js index dfbbfc1cb0..979189d9f3 100644 --- a/src/math/trigonometry.js +++ b/src/math/trigonometry.js @@ -281,9 +281,10 @@ p5.prototype.radians = angle => angle * constants.DEG_TO_RAD; /** * Sets the current mode of p5 to the given mode. Default mode is RADIANS. * + * Calling angleMode() with no arguments returns current anglemode. * @method angleMode * @param {Constant} mode either RADIANS or DEGREES - * + * @chainable * @example *
* @@ -306,10 +307,18 @@ p5.prototype.radians = angle => angle * constants.DEG_TO_RAD; *
* */ +/** + * @method angleMode + * @return {Constant} mode either RADIANS or DEGREES + */ p5.prototype.angleMode = function(mode) { - if (mode === constants.DEGREES || mode === constants.RADIANS) { + p5._validateParameters('angleMode', arguments); + if (typeof mode === 'undefined') { + return this._angleMode; + } else if (mode === constants.DEGREES || mode === constants.RADIANS) { this._angleMode = mode; } + return this; }; /** diff --git a/test/unit/math/trigonometry.js b/test/unit/math/trigonometry.js index 437945f471..47d619fb15 100644 --- a/test/unit/math/trigonometry.js +++ b/test/unit/math/trigonometry.js @@ -60,6 +60,16 @@ suite('Trigonometry', function() { myp5.angleMode('wtflolzkk'); assert.equal(myp5._angleMode, 'radians'); }); + + test('should return radians', function() { + myp5.angleMode(RADIANS); + assert.equal(myp5.angleMode(), 'radians'); + }); + + test('should return degrees', function() { + myp5.angleMode(DEGREES); + assert.equal(myp5.angleMode(), 'degrees'); + }); }); suite('p5.prototype.degrees', function() { From aa4de60c1ac340d95063043bf7f1d1161cf6fdb3 Mon Sep 17 00:00:00 2001 From: KevinGrajeda Date: Wed, 8 Jun 2022 19:16:59 -0500 Subject: [PATCH 2/3] added new test and fixed test --- test/unit/math/trigonometry.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/unit/math/trigonometry.js b/test/unit/math/trigonometry.js index 47d619fb15..3445baa4c3 100644 --- a/test/unit/math/trigonometry.js +++ b/test/unit/math/trigonometry.js @@ -48,17 +48,18 @@ suite('Trigonometry', function() { suite('p5.prototype.angleMode', function() { test('should set constant to DEGREES', function() { myp5.angleMode(DEGREES); - assert.equal(myp5._angleMode, 'degrees'); + assert.equal(myp5.angleMode(), 'degrees'); }); test('should set constant to RADIANS', function() { myp5.angleMode(RADIANS); - assert.equal(myp5._angleMode, 'radians'); + assert.equal(myp5.angleMode(), 'radians'); }); - test('should always be RADIANS or DEGREES', function() { - myp5.angleMode('wtflolzkk'); - assert.equal(myp5._angleMode, 'radians'); + test('wrong param type', function() { + assert.validationError(function() { + myp5.angleMode('wtflolzkk'); + }); }); test('should return radians', function() { @@ -70,6 +71,11 @@ suite('Trigonometry', function() { myp5.angleMode(DEGREES); assert.equal(myp5.angleMode(), 'degrees'); }); + + test('should always be RADIANS or DEGREES', function() { + myp5.angleMode('wtflolzkk'); + assert.equal(myp5.angleMode(), 'radians'); + }); }); suite('p5.prototype.degrees', function() { From f1a15189cca64a395e6baf0c8849658b2cea9ceb Mon Sep 17 00:00:00 2001 From: KevinGrajeda Date: Sat, 16 Jul 2022 22:32:07 -0500 Subject: [PATCH 3/3] chainable removed in angleMode --- src/math/trigonometry.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/math/trigonometry.js b/src/math/trigonometry.js index 979189d9f3..536d1d575d 100644 --- a/src/math/trigonometry.js +++ b/src/math/trigonometry.js @@ -284,7 +284,6 @@ p5.prototype.radians = angle => angle * constants.DEG_TO_RAD; * Calling angleMode() with no arguments returns current anglemode. * @method angleMode * @param {Constant} mode either RADIANS or DEGREES - * @chainable * @example *
* @@ -318,7 +317,6 @@ p5.prototype.angleMode = function(mode) { } else if (mode === constants.DEGREES || mode === constants.RADIANS) { this._angleMode = mode; } - return this; }; /**