mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-24 10:48:46 +00:00
getDegreeAngleFromDirection fix
This commit is contained in:
parent
5a9258f859
commit
5df06748e1
@ -8,5 +8,7 @@ export function randomPositiveOrNegative(): number {
|
|||||||
|
|
||||||
export function getDegreeAngleFromDirection(x: number, y: number): number {
|
export function getDegreeAngleFromDirection(x: number, y: number): number {
|
||||||
const radianAngle = Math.atan2(y, x);
|
const radianAngle = Math.atan2(y, x);
|
||||||
return (radianAngle / Math.PI) * 180;
|
const angle = (radianAngle / Math.PI) * 180;
|
||||||
|
|
||||||
|
return angle < 0 ? angle + 360 : angle;
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,7 @@ const testCases: { x: number; y: number; expectedAngle: number }[] = [
|
|||||||
|
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
test(`returns correct degree angle for direction [X: ${testCase.x} , Y: ${testCase.y}] (${testCase.expectedAngle} degrees)`, () => {
|
test(`returns correct degree angle for direction [X: ${testCase.x} , Y: ${testCase.y}] (${testCase.expectedAngle} degrees)`, () => {
|
||||||
let angle = getDegreeAngleFromDirection(testCase.x, testCase.y);
|
const angle = getDegreeAngleFromDirection(testCase.x, testCase.y);
|
||||||
if (angle < 0) angle += 360;
|
|
||||||
|
|
||||||
expect(angle).toBe(testCase.expectedAngle);
|
expect(angle).toBe(testCase.expectedAngle);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user