Skip to content

Commit 4863510

Browse files
authored
Merge pull request #5682 from KevinGrajeda/anglemode
Fixes #5160
2 parents aa15566 + f1a1518 commit 4863510

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/math/trigonometry.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ p5.prototype.radians = angle => angle * constants.DEG_TO_RAD;
281281
/**
282282
* Sets the current mode of p5 to the given mode. Default mode is RADIANS.
283283
*
284+
* Calling <a href="#/p5/angleMode">angleMode()</a> with no arguments returns current anglemode.
284285
* @method angleMode
285286
* @param {Constant} mode either RADIANS or DEGREES
286-
*
287287
* @example
288288
* <div>
289289
* <code>
@@ -306,8 +306,15 @@ p5.prototype.radians = angle => angle * constants.DEG_TO_RAD;
306306
* </div>
307307
*
308308
*/
309+
/**
310+
* @method angleMode
311+
* @return {Constant} mode either RADIANS or DEGREES
312+
*/
309313
p5.prototype.angleMode = function(mode) {
310-
if (mode === constants.DEGREES || mode === constants.RADIANS) {
314+
p5._validateParameters('angleMode', arguments);
315+
if (typeof mode === 'undefined') {
316+
return this._angleMode;
317+
} else if (mode === constants.DEGREES || mode === constants.RADIANS) {
311318
this._angleMode = mode;
312319
}
313320
};

test/unit/math/trigonometry.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,33 @@ suite('Trigonometry', function() {
4848
suite('p5.prototype.angleMode', function() {
4949
test('should set constant to DEGREES', function() {
5050
myp5.angleMode(DEGREES);
51-
assert.equal(myp5._angleMode, 'degrees');
51+
assert.equal(myp5.angleMode(), 'degrees');
5252
});
5353

5454
test('should set constant to RADIANS', function() {
5555
myp5.angleMode(RADIANS);
56-
assert.equal(myp5._angleMode, 'radians');
56+
assert.equal(myp5.angleMode(), 'radians');
57+
});
58+
59+
test('wrong param type', function() {
60+
assert.validationError(function() {
61+
myp5.angleMode('wtflolzkk');
62+
});
63+
});
64+
65+
test('should return radians', function() {
66+
myp5.angleMode(RADIANS);
67+
assert.equal(myp5.angleMode(), 'radians');
68+
});
69+
70+
test('should return degrees', function() {
71+
myp5.angleMode(DEGREES);
72+
assert.equal(myp5.angleMode(), 'degrees');
5773
});
5874

5975
test('should always be RADIANS or DEGREES', function() {
6076
myp5.angleMode('wtflolzkk');
61-
assert.equal(myp5._angleMode, 'radians');
77+
assert.equal(myp5.angleMode(), 'radians');
6278
});
6379
});
6480

0 commit comments

Comments
 (0)