fix: radians -> angle

This commit is contained in:
cha0s 2021-04-20 06:26:13 -05:00
parent 0c15cd0f94
commit 40d85508b3
2 changed files with 3 additions and 3 deletions

View File

@ -52,7 +52,7 @@ export const add = (l, r) => l + r;
export const div = (l, r) => l / r;
export const frac = (number) => number % 1;
export const angleFromRad = (r) => (
(360 + ((2 * Math.PI - (r + HALF_PI)) % (Math.PI * 2)) / -PI_180) % 360
(360 + ((2 * Math.PI - ((Math.PI - r) + HALF_PI + Math.PI)) % (Math.PI * 2)) / -PI_180) % 360
);
export const angleRange = (angle, delta) => ({
min: 360 + (angle - delta),

View File

@ -4,8 +4,8 @@ import {angleFromRad, HALF_PI, PI} from '../src/math';
it('can translate radians into degrees', () => {
expect(angleFromRad(0)).to.equal(90);
expect(angleFromRad(HALF_PI)).to.equal(180);
expect(angleFromRad(HALF_PI)).to.equal(0);
expect(angleFromRad(PI)).to.equal(270);
expect(angleFromRad(PI + HALF_PI)).to.equal(0);
expect(angleFromRad(PI + HALF_PI)).to.equal(180);
expect(angleFromRad(2 * PI)).to.equal(90);
});