From df064ad2f785fbd025ce33c57c351b077649ce7f Mon Sep 17 00:00:00 2001 From: JoaoMario109 Date: Thu, 22 Feb 2024 09:08:29 -0300 Subject: [PATCH] common: Add toDegree * Add toDegree function to convert Radians to Degrees --- spec/gl-matrix/common-spec.js | 5 +++++ src/common.js | 11 +++++++++++ 2 files changed, 16 insertions(+) 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