1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 19:42:01 +02:00
OpenSTF/res/app/components/stf/screen/rotator.js
2016-01-19 23:08:33 +09:00

33 lines
490 B
JavaScript

var mapping = {
0: {
0: 0
, 90: -90
, 180: -180
, 270: 90
}
, 90: {
0: 90
, 90: 0
, 180: -90
, 270: 180
}
, 180: {
0: 180
, 90: 90
, 180: 0
, 270: -90
}
, 270: {
0: -90
, 90: -180
, 180: 90
, 270: 0
}
}
module.exports = function rotator(oldRotation, newRotation) {
var r1 = oldRotation < 0 ? 360 + oldRotation % 360 : oldRotation % 360
var r2 = newRotation < 0 ? 360 + newRotation % 360 : newRotation % 360
return mapping[r1][r2]
}