diff --git a/spec/gl-matrix/common-spec.js b/spec/gl-matrix/common-spec.js index 748eb144..c8cc5ac0 100644 --- a/spec/gl-matrix/common-spec.js +++ b/spec/gl-matrix/common-spec.js @@ -8,6 +8,11 @@ describe("common", function(){ it("should return a value of 3.141592654(Math.PI)", function(){ expect(result).toBeEqualish(Math.PI); }); }); + describe("toDegree", function(){ + beforeEach(function(){ result = glMatrix.toDegree(Math.PI); }); + it("should return a value of 180", function(){ expect(result).toBeEqualish(180); }); + }); + describe("equals", function() { let r0, r1, r2; beforeEach(function() { diff --git a/src/common.js b/src/common.js index 1bb5ddde..728f134d 100644 --- a/src/common.js +++ b/src/common.js @@ -34,6 +34,8 @@ export function setMatrixArrayType(type) { const degree = Math.PI / 180; +const radian = 180 / Math.PI; + /** * Convert Degree To Radian * @@ -43,6 +45,15 @@ export function toRadian(a) { return a * degree; } +/** + * Convert Radian To Degree + * + * @param {Number} a Angle in Radians + */ +export function toDegree(a) { + return a * radian; +} + /** * Tests whether or not the arguments have approximately the same value, within an absolute * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less