Skip to content

Commit

Permalink
common: Add toDegree
Browse files Browse the repository at this point in the history
 * Add toDegree function to convert Radians to Degrees
  • Loading branch information
JoaoMario109 authored and toji committed Apr 14, 2024
1 parent df5278f commit df064ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/gl-matrix/common-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
11 changes: 11 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export function setMatrixArrayType(type) {

const degree = Math.PI / 180;

const radian = 180 / Math.PI;

/**
* Convert Degree To Radian
*
Expand All @@ -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
Expand Down

0 comments on commit df064ad

Please sign in to comment.