getDirectionFromAngle static method
Implementation
static Direction getDirectionFromAngle(
double angle, {
double directionSpace = 2.5,
}) {
double degrees = angle * PI_180;
if (degrees > -directionSpace && degrees <= directionSpace) {
return Direction.right;
}
if (degrees > directionSpace && degrees <= (90 - directionSpace)) {
return Direction.downRight;
}
if (degrees > (90 - directionSpace) && degrees <= (90 + directionSpace)) {
return Direction.down;
}
if (degrees > (90 + directionSpace) && degrees <= (180 - directionSpace)) {
return Direction.downLeft;
}
if ((degrees > (180 - directionSpace) && degrees <= 180) ||
(degrees >= -180 && degrees <= -(180 - directionSpace))) {
return Direction.left;
}
if (degrees > -(180 - directionSpace) &&
degrees <= -(90 + directionSpace)) {
return Direction.upLeft;
}
if (degrees > -(90 + directionSpace) && degrees <= -(90 - directionSpace)) {
return Direction.up;
}
if (degrees > -(90 - directionSpace) && degrees <= -directionSpace) {
return Direction.upRight;
}
return Direction.left;
}