CoordinateUtils { public static double getLongitudeM180P180(double longitude) { double newLong = longitude % 360; if (newLong > 180) { newLong -= 360; } if (newLong < -180) { newLong += 360; } return newLong; }  static double getLongitudeM180P180(double longitude); static List<Range> createRange(int minj, int maxj, int mini, int maxi); static int findCoordElementBounded(CoordinateAxis1D axis, double pos, int lastIndex); static List<Range> getRangesFromLatLonRect(GridCoordSys gcs, LatLonRect rect); static double getMinOrMaxLon(double lon1, double lon2, boolean wantMin); static MinMax computeMinMax(MinMax ref, MinMax work); static MAMath.MinMax computeLatMinMax(MAMath.MinMax minMaxYValue2D, CoordinateAxis2D latAxis, int minj, int mini, int maxj, int maxi); static MAMath.MinMax computeLonMinMax(MAMath.MinMax minMaxXValue2D,
                                                 CoordinateAxis2D lonAxis,
                                                 int minj,
                                                 int mini,
                                                 int maxj,
                                                 int maxi,
                                                 double minx,
                                                 double maxx); static MinMax computeMinMaxX(Projection dataProjection, LatLonRect rect); static MinMax computeMinMaxY(Projection dataProjection, LatLonRect rect); static MinMax[] computeMinMaxXY(Projection dataProjection, LatLonRect rect); static void checkXYAxis(CoordinateAxis xaxis, CoordinateAxis yaxis, GridCoordSys gcs); static double checkLon(double lon, double refXMin); static boolean isInside(double lat, double lon, MinMax minMaxX, MinMax minMaxY); static void removeEmptyYXRanges(List<List<Range>> listRanges); static boolean hasEmptyYXRanges(List<List<Range>> listRanges); static List<Range> createEmptyYXRanges(); static boolean hasRange(List<Range> ranges); static boolean hasRange(Range range); static void getRangeValues(GridCoordSys gcs, Range rangeLat, Range rangeLon, double[] rangeValueLat, double[] rangeValueLon); static MAMath.MinMax getMinMaxValueForAxis(CoordinateAxis axis); static double getMinValueForAxis(CoordinateAxis axis); static double getMaxValueForAxis(CoordinateAxis axis); static String getMinValForAxisAsString(CoordinateAxis axis); static String getMaxValForAxisAsString(CoordinateAxis axis); static int findMinDepthIndex(double[] depths, double from); static int findMaxDepthIndex(double[] depths, double to);  }
@Test public void testGetLongitudeM180P180() { assertTrue(CoordinateUtils.getLongitudeM180P180(-180.5) == 179.5); assertTrue(CoordinateUtils.getLongitudeM180P180(-180) == -180); assertTrue(CoordinateUtils.getLongitudeM180P180(0) == 0); assertTrue(CoordinateUtils.getLongitudeM180P180(180) == 180); assertTrue(CoordinateUtils.getLongitudeM180P180(181.5) == -178.5); assertTrue(CoordinateUtils.getLongitudeM180P180(200) == -160); assertTrue(CoordinateUtils.getLongitudeM180P180(360) == 0); assertTrue(CoordinateUtils.getLongitudeM180P180(380) == 20); }