Skip to content

Instantly share code, notes, and snippets.

@kappuccino
Created December 1, 2020 19:24
Show Gist options
  • Save kappuccino/42a08bcb26ec656d9be73e2323f7f82f to your computer and use it in GitHub Desktop.
Save kappuccino/42a08bcb26ec656d9be73e2323f7f82f to your computer and use it in GitHub Desktop.
Fligh Sim - Helper
/*
PB: trouver la valeur en degré de la rotation du marker sur a map
Solution ???
calcNextRotation()
prev: la valeur degré de la rotation actuelle (peut être supérieure à 360)
next: la valeur réeel de la diretion de l'avion (compris entre 0 et 360)
calcAngle() determine le degré de rotation sans prendre en compte le nombre de tour
*/
function calcNextRotation(prev, nextDeg){
if(!prev) return nextDeg
const prevDeg = calcAngle(prev)
let prevDeg_ = prevDeg > 180 ? (prevDeg - 360) : prevDeg
let nextDeg_ = nextDeg > 180 ? (nextDeg - 360) : nextDeg
let delta = nextDeg_ - prevDeg_
return prev + delta
}
function calcAngle(angle){
return angle > 360 ? angle % 360 : angle
}
test('405 rotation is 45deg', () => {
expect(calcAngle(405)).toBe(45)
})
test('1125 rotation is 45deg', () => {
expect(calcAngle(1125)).toBe(45)
})
test('rotation 45 → 90 : 90', () => {
expect(calcNextRotation(45, 90)).toBe(90)
})
test('rotation 405 → 90 : 450', () => {
expect(calcNextRotation(405, 90)).toBe(450)
})
test('rotation 315 → 45 : 405', () => {
expect(calcNextRotation(315, 45)).toBe(405)
})
test('rotation 405 → 270 : 270', () => {
expect(calcNextRotation(405, 300)).toBe(300)
})
test('rotation 1125 → 315 : 1035', () => {
expect(calcNextRotation(1125, 315)).toBe(1035)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment