Convert { @NonNull public static String bearing2(double degrees) { if (Double.isNaN(degrees)) { return ""; } else { degrees %= 360; if (degrees < 0) degrees += 360; final String bearingStr = ((int) degrees) + "°"; if (337.5 <= degrees || degrees < 22.5) return bearingStr + " (N)"; else if (degrees < 67.5) return bearingStr + " (NE)"; else if (degrees < 112.5) return bearingStr + " (E)"; else if (degrees < 157.5) return bearingStr + " (SE)"; else if (degrees < 202.5) return bearingStr + " (S)"; else if (degrees < 247.5) return bearingStr + " (SW)"; else if (degrees < 292.5) return bearingStr + " (W)"; else return bearingStr + " (NW)"; } }  static double kts2mps(double knots); @NonNull static String altitude(double m); @NonNull static String distance(double m); @NonNull static String distance(double m, int precision, boolean units); @NonNull static String distance2(double m, int precision); @NonNull static String distance3(double m); @NonNull static String speed(double mps); @NonNull static String speed(double mps, int precision, boolean units); @NonNull static String glide(double glideRatio, int precision, boolean units); @NonNull static String glide(double groundSpeed, double climb, int precision, boolean units); @NonNull static String glide2(double groundSpeed, double climb, int precision, boolean units); @NonNull static String pressure(double hPa); @NonNull static String angle(double degrees); @NonNull static String angle2(double degrees); @NonNull static String bearing2(double degrees); static boolean metric; static final double FT; static final double MPH; static final double KPH; static final float MPHf; static final float KPHf; static final String GLIDE_STATIONARY; static final String GLIDE_LEVEL; static final String GLIDE_VERTICAL; }
@Test public void convertBearing2() { assertEquals("0° (N)", Convert.bearing2(0.0)); assertEquals("45° (NE)", Convert.bearing2(45.0)); assertEquals("90° (E)", Convert.bearing2(90.0)); assertEquals("90° (E)", Convert.bearing2(90.5)); assertEquals("135° (SE)", Convert.bearing2(135.0)); assertEquals("188° (S)", Convert.bearing2(188.0)); assertEquals("225° (SW)", Convert.bearing2(-135.0)); assertEquals("270° (W)", Convert.bearing2(-90.0)); assertEquals("300° (NW)", Convert.bearing2(660.0)); assertEquals("300° (NW)", Convert.bearing2(1020.0)); assertEquals("300° (NW)", Convert.bearing2(-60.0)); assertEquals("300° (NW)", Convert.bearing2(-420.0)); assertEquals("300° (NW)", Convert.bearing2(-780.0)); assertEquals("", Convert.bearing2(Double.NaN)); }