Skip to content

Commit

Permalink
#develop added deg-to-rad and rad-to-deg helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
bennobuilder committed Nov 14, 2024
1 parent 8818fc8 commit a04b36e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@blgc/utils",
"description": "Straightforward, typesafe, and tree-shakable collection of utility functions",
"version": "0.0.24",
"version": "0.0.25",
"private": false,
"scripts": {
"build": "shx rm -rf dist && chmod +x ../../scripts/cli.sh && ../../scripts/cli.sh bundle",
Expand Down
20 changes: 20 additions & 0 deletions packages/utils/src/deg-to-rad.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest';

import { degToRad } from './deg-to-rad';

describe('degToRad function', () => {
it('should convert degrees to radians correctly', () => {
expect(degToRad(180)).toBe(Math.PI);
expect(degToRad(90)).toBe(Math.PI / 2);
expect(degToRad(45)).toBe(Math.PI / 4);
});

it('should handle zero correctly', () => {
expect(degToRad(0)).toBe(0);
});

it('should handle negative values correctly', () => {
expect(degToRad(-180)).toBe(-Math.PI);
expect(degToRad(-90)).toBe(-Math.PI / 2);
});
});
8 changes: 8 additions & 0 deletions packages/utils/src/deg-to-rad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Converts degrees to radians
* @param deg - The angle in degrees
* @returns The angle in radians
*/
export function degToRad(deg: number): number {
return deg * (Math.PI / 180);
}
2 changes: 2 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './ContinuousId';
export * from './deep-copy';
export * from './deep-replace-var';
export * from './define-config';
export * from './deg-to-rad';
export * from './extract-error-data';
export * from './extract-start-end-point-from-mat3';
export * from './from-hex';
Expand All @@ -24,6 +25,7 @@ export * from './mat3-to-array';
export * from './multiply-vec2';
export * from './not-empty';
export * from './pick-properties';
export * from './rad-to-deg';
export * from './random-hex';
export * from './result';
export * from './rgb-to-hex';
Expand Down
20 changes: 20 additions & 0 deletions packages/utils/src/rad-to-deg.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest';

import { radToDeg } from './rad-to-deg';

describe('radToDeg function', () => {
it('should convert radians to degrees correctly', () => {
expect(radToDeg(Math.PI)).toBe(180);
expect(radToDeg(Math.PI / 2)).toBe(90);
expect(radToDeg(Math.PI / 4)).toBe(45);
});

it('should handle zero correctly', () => {
expect(radToDeg(0)).toBe(0);
});

it('should handle negative values correctly', () => {
expect(radToDeg(-Math.PI)).toBe(-180);
expect(radToDeg(-Math.PI / 2)).toBe(-90);
});
});
8 changes: 8 additions & 0 deletions packages/utils/src/rad-to-deg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Converts radians to degrees
* @param rad - The angle in radians
* @returns The angle in degrees
*/
export function radToDeg(rad: number): number {
return rad * (180 / Math.PI);
}

0 comments on commit a04b36e

Please sign in to comment.