Convert a bearing to be within the 0 to +360 degrees range. Compass bearing is in the rangen 0° ... 360°
double normalizeBearing(final double bearing) => (bearing + 360) % 360;