Not magic numbers for arc degrees in Java

If you’re working on some feature that includes rotation, and you’re obsessed with a MagicNumber checkstyle rule, most likely you have constants like these in your code:

1
2
public static final short DEGREES_90 = 90;
public static final short DEGREES_180 = 180;

Boring, aren’t they?

Here are some mad, but mathematically clean and correct replacements that I can’t resist to share:

1
2
3
4
5
6
public final class Degrees {
    public static final short DEGREES_90 = (short) Math.toDegrees(Math.PI / 2);
    public static final short DEGREES_180 = (short) Math.toDegrees(Math.PI);
    public static final short DEGREES_270 = (short) Math.toDegrees(Math.PI / 2 * 3);
    public static final short DEGREES_360 = (short) Math.toDegrees(Math.PI * 2);
}

Don’t mention it! (literally)