@Test public final void testCalculateLineBearing() { Map<Lines, Line> lines = mockBearingTestLines(); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L1), BearingDirection.IN_DIRECTION, BEARING_DISTANCE, 0), BEARING_L1_IN_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L2), BearingDirection.AGAINST_DIRECTION, BEARING_DISTANCE, Lines.L2.lenght), BEARING_L2_AGAINST_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L3), BearingDirection.IN_DIRECTION, BEARING_DISTANCE, 0), BEARING_L3_IN_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L4), BearingDirection.AGAINST_DIRECTION, BEARING_DISTANCE, Lines.L4.lenght), BEARING_L4_AGAINST_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(null, null, BEARING_DISTANCE, 0), EXPECTED_BEARING_ERROR); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L1), BearingDirection.IN_DIRECTION, BEARING_DISTANCE, PAL_DISTANCE_LONG), BEARING_L1_PAL_IN_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L2), BearingDirection.AGAINST_DIRECTION, BEARING_DISTANCE, PAL_DISTANCE_LONG), BEARING_L2_PAL_AGAINST_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L3), BearingDirection.IN_DIRECTION, BEARING_DISTANCE, PAL_DISTANCE_SHORT), BEARING_L3_PAL_IN_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.L4), BearingDirection.AGAINST_DIRECTION, BEARING_DISTANCE, PAL_DISTANCE_SHORT), BEARING_L4_PAL_AGAINST_DIRECTION); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.VERTICAL_LINE), BearingDirection.IN_DIRECTION, BEARING_DISTANCE, 0), BEARING_180); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.VERTICAL_LINE), BearingDirection.AGAINST_DIRECTION, BEARING_DISTANCE, 0), BEARING_0); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.VERTICAL_LINE), BearingDirection.IN_DIRECTION, BEARING_DISTANCE, PAL_DISTANCE_SHORT), BEARING_180); assertEquals(GeometryUtils.calculateLineBearing(lines.get(Lines.VERTICAL_LINE), BearingDirection.AGAINST_DIRECTION, BEARING_DISTANCE, PAL_DISTANCE_SHORT), BEARING_0); }
public static double calculateLineBearing(final Line line, final BearingDirection dir, final int pointDistance, final int projectionAlongLine) { if (line == null || projectionAlongLine < 0 || projectionAlongLine > line.getLineLength()) { return -1.0; } GeoCoordinates p1 = line.getGeoCoordinateAlongLine(projectionAlongLine); GeoCoordinates p2; if (dir == BearingDirection.IN_DIRECTION) { p2 = bearingPointCalculator.calculateBearingDestinationInDirection(line, pointDistance, projectionAlongLine); } else { p2 = bearingPointCalculator.calculateBearingDestinationAgainstDirection(line, pointDistance, projectionAlongLine); } return bearing(p1, p2); }
GeometryUtils { public static double calculateLineBearing(final Line line, final BearingDirection dir, final int pointDistance, final int projectionAlongLine) { if (line == null || projectionAlongLine < 0 || projectionAlongLine > line.getLineLength()) { return -1.0; } GeoCoordinates p1 = line.getGeoCoordinateAlongLine(projectionAlongLine); GeoCoordinates p2; if (dir == BearingDirection.IN_DIRECTION) { p2 = bearingPointCalculator.calculateBearingDestinationInDirection(line, pointDistance, projectionAlongLine); } else { p2 = bearingPointCalculator.calculateBearingDestinationAgainstDirection(line, pointDistance, projectionAlongLine); } return bearing(p1, p2); } }
GeometryUtils { public static double calculateLineBearing(final Line line, final BearingDirection dir, final int pointDistance, final int projectionAlongLine) { if (line == null || projectionAlongLine < 0 || projectionAlongLine > line.getLineLength()) { return -1.0; } GeoCoordinates p1 = line.getGeoCoordinateAlongLine(projectionAlongLine); GeoCoordinates p2; if (dir == BearingDirection.IN_DIRECTION) { p2 = bearingPointCalculator.calculateBearingDestinationInDirection(line, pointDistance, projectionAlongLine); } else { p2 = bearingPointCalculator.calculateBearingDestinationAgainstDirection(line, pointDistance, projectionAlongLine); } return bearing(p1, p2); } private  GeometryUtils(); }
GeometryUtils { public static double calculateLineBearing(final Line line, final BearingDirection dir, final int pointDistance, final int projectionAlongLine) { if (line == null || projectionAlongLine < 0 || projectionAlongLine > line.getLineLength()) { return -1.0; } GeoCoordinates p1 = line.getGeoCoordinateAlongLine(projectionAlongLine); GeoCoordinates p2; if (dir == BearingDirection.IN_DIRECTION) { p2 = bearingPointCalculator.calculateBearingDestinationInDirection(line, pointDistance, projectionAlongLine); } else { p2 = bearingPointCalculator.calculateBearingDestinationAgainstDirection(line, pointDistance, projectionAlongLine); } return bearing(p1, p2); } private  GeometryUtils(); static double distance(final GeoCoordinates coord1,
                                  final GeoCoordinates coord2); static double distance(final double longitude1,
                                  final double latitude1, final double longitude2,
                                  final double latitude2); static double bearing(final GeoCoordinates coord1,
                                 final GeoCoordinates coord2); static double bearing(final double p1Longitude,
                                 final double p1Latitude, final double p2Longitude,
                                 final double p2Latitude); static double calculateLineBearing(final Line line,
                                              final BearingDirection dir, final int pointDistance,
                                              final int projectionAlongLine); static boolean checkCoordinateBounds(final double lon,
                                                final double lat); static GeoCoordinates intersectStraights(
            final GeoCoordinates coord1, final double bear1,
            final GeoCoordinates coord2, final double bear2); static GeoCoordinates intersectStraights(final double longitude1,
                                                    final double latitude1, final double bear1,
                                                    final double longitude2, final double latitude2, final double bear2); static boolean lineIntersection(final GeoCoordinates gc1Start,
                                           final GeoCoordinates gc1End, final GeoCoordinates gc2Start,
                                           final GeoCoordinates gc2End); static GeoCoordinates pointAlongLine(final GeoCoordinates coord1,
                                                final GeoCoordinates coord2, final double offset); static GeoCoordinates pointAlongLine(final double longitudeA,
                                                final double latitudeA, final double longitudeB,
                                                final double latitudeB, final double offset); static GeoCoordinates scaleUpperRightCoordinate(
            final GeoCoordinates lowerLeft, final GeoCoordinates upperRight,
            final double xfactor, final double yfactor); static GeoCoordinates scaleUpperRightCoordinate(
            final double lowerLeftLon, final double lowerLeftLat,
            final double upperRightLon, final double upperRightLat,
            final double xfactor, final double yfactor); static double round(final double val); static double round(final double val, final int decimalPlaces); static GeoCoordinates determineCoordinateInDistance(
            final GeoCoordinates coord, final int angle, final double distanceKm); static GeoCoordinates determineCoordinateInDistance(
            final double lon, final double lat, final int angle,
            final double distanceKm); static double bearingDifference(double firstBearing, double secondBearing); }
GeometryUtils { public static double calculateLineBearing(final Line line, final BearingDirection dir, final int pointDistance, final int projectionAlongLine) { if (line == null || projectionAlongLine < 0 || projectionAlongLine > line.getLineLength()) { return -1.0; } GeoCoordinates p1 = line.getGeoCoordinateAlongLine(projectionAlongLine); GeoCoordinates p2; if (dir == BearingDirection.IN_DIRECTION) { p2 = bearingPointCalculator.calculateBearingDestinationInDirection(line, pointDistance, projectionAlongLine); } else { p2 = bearingPointCalculator.calculateBearingDestinationAgainstDirection(line, pointDistance, projectionAlongLine); } return bearing(p1, p2); } private  GeometryUtils(); static double distance(final GeoCoordinates coord1,
                                  final GeoCoordinates coord2); static double distance(final double longitude1,
                                  final double latitude1, final double longitude2,
                                  final double latitude2); static double bearing(final GeoCoordinates coord1,
                                 final GeoCoordinates coord2); static double bearing(final double p1Longitude,
                                 final double p1Latitude, final double p2Longitude,
                                 final double p2Latitude); static double calculateLineBearing(final Line line,
                                              final BearingDirection dir, final int pointDistance,
                                              final int projectionAlongLine); static boolean checkCoordinateBounds(final double lon,
                                                final double lat); static GeoCoordinates intersectStraights(
            final GeoCoordinates coord1, final double bear1,
            final GeoCoordinates coord2, final double bear2); static GeoCoordinates intersectStraights(final double longitude1,
                                                    final double latitude1, final double bear1,
                                                    final double longitude2, final double latitude2, final double bear2); static boolean lineIntersection(final GeoCoordinates gc1Start,
                                           final GeoCoordinates gc1End, final GeoCoordinates gc2Start,
                                           final GeoCoordinates gc2End); static GeoCoordinates pointAlongLine(final GeoCoordinates coord1,
                                                final GeoCoordinates coord2, final double offset); static GeoCoordinates pointAlongLine(final double longitudeA,
                                                final double latitudeA, final double longitudeB,
                                                final double latitudeB, final double offset); static GeoCoordinates scaleUpperRightCoordinate(
            final GeoCoordinates lowerLeft, final GeoCoordinates upperRight,
            final double xfactor, final double yfactor); static GeoCoordinates scaleUpperRightCoordinate(
            final double lowerLeftLon, final double lowerLeftLat,
            final double upperRightLon, final double upperRightLat,
            final double xfactor, final double yfactor); static double round(final double val); static double round(final double val, final int decimalPlaces); static GeoCoordinates determineCoordinateInDistance(
            final GeoCoordinates coord, final int angle, final double distanceKm); static GeoCoordinates determineCoordinateInDistance(
            final double lon, final double lat, final int angle,
            final double distanceKm); static double bearingDifference(double firstBearing, double secondBearing); static final float MAX_LAT; static final float MIN_LAT; static final float MAX_LON; static final float MIN_LON; static final double ZERO_CIRCLE; static final double HALF_CIRCLE; static final double QUARTER_CIRCLE; static final double FULL_CIRCLE; static final double THREE_QUARTER_CIRCLE; static final int FULL_CIRCLE_DEGREE; }