/** * Tests for angle on compass only (do not tests angle between direction along meridians). * Returns {@link Integer#MIN_VALUE} if the angle can't be computed. */ static int getCompassAngle(final AxisDirection source, final AxisDirection target) { final int base = AxisDirection.NORTH.ordinal(); final int src = source.ordinal() - base; if (src >= 0 && src < COMPASS_DIRECTION_COUNT) { int tgt = target.ordinal() - base; if (tgt >= 0 && tgt < COMPASS_DIRECTION_COUNT) { tgt = src - tgt; if (tgt < -COMPASS_DIRECTION_COUNT / 2) { tgt += COMPASS_DIRECTION_COUNT; } else if (tgt > COMPASS_DIRECTION_COUNT / 2) { tgt -= COMPASS_DIRECTION_COUNT; } return tgt; } } return Integer.MIN_VALUE; }
/** * Returns {@code true} if the specified direction is a compass direction. Compass directions * include "<cite>North</cite>", "<cite>North-North-East</cite>", "<cite>North-East</cite>", * <cite>etc.</cite> * * @param direction The axis direction to test. * @return {@code true} if the given direction is a compass direction. * @since 2.4 */ public static boolean isCompassDirection(final AxisDirection direction) { ensureNonNull("direction", direction); final int n = direction.ordinal() - AxisDirection.NORTH.ordinal(); return n >= 0 && n < COMPASS_DIRECTION_COUNT; }
/** * Returns the rank for the specified axis. Any axis that were not specified at construction * time will ordered after all known axis. */ private final int rank(final CoordinateSystemAxis axis) { int c = axis.getDirection().absolute().ordinal(); c = (c >= 0 && c < directionRanks.length) ? directionRanks[c] : directionRanks.length; return c; }
final int ordinal = axisOrder[i].absolute().ordinal() + 1; if (ordinal > length) { length = ordinal; Arrays.fill(directionRanks, length); for (int i = 0; i < axisOrder.length; i++) { final int ordinal = axisOrder[i].absolute().ordinal(); final int previous = directionRanks[ordinal]; if (previous != length) {
/** * Returns {@code true} if the specified direction is an inter-cardinal direction. * Inter-cardinal directions are {@code NORTH_EAST}, {@code SOUTH_SOUTH_EAST}, etc. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the given direction is an inter-cardinal direction. */ public static boolean isIntercardinal(final AxisDirection dir) { if (dir == null) return false; final int n = dir.ordinal() - NORTH.ordinal(); return n >= 0 && n < COMPASS_COUNT && (n & 3) != 0; }
/** * Returns {@code true} if the given direction is {@code GEOCENTRIC_X}, {@code GEOCENTRIC_Y} * or {@code GEOCENTRIC_Z}. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the given direction is one of geocentric directions. */ public static boolean isGeocentric(final AxisDirection dir) { if (dir == null) return false; final int ordinal = dir.ordinal(); return ordinal >= GEOCENTRIC_X.ordinal() && ordinal <= GEOCENTRIC_Z.ordinal(); }
/** * Returns {@code true} if the given direction is a user-defined direction (i.e. is not defined by GeoAPI). * * @param dir the direction to test, or {@code null}. * @return {@code true} if the given direction is user-defined. */ public static boolean isUserDefined(final AxisDirection dir) { return (dir != null) && dir.ordinal() > LAST_ORDINAL; }
/** * Returns {@code true} if the given direction is {@code UP} or {@code DOWN}. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the direction is vertical, or {@code false} otherwise. */ public static boolean isVertical(final AxisDirection dir) { if (dir == null) return false; return ((dir.ordinal() - UP.ordinal()) & ~1) == 0; }
/** * Returns {@code true} if the given direction is {@code UP} or {@code DOWN}. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the direction is vertical, or {@code false} otherwise. */ public static boolean isVertical(final AxisDirection dir) { if (dir == null) return false; return ((dir.ordinal() - UP.ordinal()) & ~1) == 0; }
/** * Returns {@code true} if the given direction is {@code FUTURE} or {@code PAST}. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the direction is temporal, or {@code false} otherwise. */ public static boolean isTemporal(final AxisDirection dir) { if (dir == null) return false; return ((dir.ordinal() - FUTURE.ordinal()) & ~1) == 0; }
/** * Returns {@code true} if the specified direction is an inter-cardinal direction. * Inter-cardinal directions are {@code NORTH_EAST}, {@code SOUTH_SOUTH_EAST}, etc. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the given direction is an inter-cardinal direction. */ public static boolean isIntercardinal(final AxisDirection dir) { if (dir == null) return false; final int n = dir.ordinal() - NORTH.ordinal(); return n >= 0 && n < COMPASS_COUNT && (n & 3) != 0; }
/** * Returns {@code true} if the given direction is {@code GEOCENTRIC_X}, {@code GEOCENTRIC_Y} * or {@code GEOCENTRIC_Z}. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the given direction is one of geocentric directions. */ public static boolean isGeocentric(final AxisDirection dir) { if (dir == null) return false; final int ordinal = dir.ordinal(); return ordinal >= GEOCENTRIC_X.ordinal() && ordinal <= GEOCENTRIC_Z.ordinal(); }
}; assertEquals(compass.length, COMPASS_DIRECTION_COUNT); final int base = AxisDirection.NORTH.ordinal(); final int h = compass.length / 2; for (int i = 0; i < compass.length; i++) { angle -= 360; assertEquals(index, base + i, c.ordinal()); assertEquals(index, base + i + (i < h ? h : -h), c.opposite().ordinal()); assertEquals(index, 0, getAngle(c, c), EPS); assertEquals(index, 180, Math.abs(getAngle(c, c.opposite())), EPS);
/** * Returns the order of the given axis direction. */ private static int order(final AxisDirection dir) { final Integer p = ORDER.get(dir); return (p != null) ? p : (dir.ordinal() << SHIFT); }
/** * Returns the order of the given axis direction. */ private static int order(final AxisDirection dir) { final Integer p = ORDER.get(dir); return (p != null) ? p : (dir.ordinal() << SHIFT); }
/** * Returns {@code true} if the given direction is an "opposite" direction. * If the given argument is {@code null} or is not a known direction, then * this method conservatively returns {@code false}. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the given direction is an "opposite". */ public static boolean isOpposite(final AxisDirection dir) { final AxisDirection opposite = opposite(dir); return (opposite != null) && opposite.ordinal() < dir.ordinal(); }
/** * Returns {@code true} if the given direction is an "opposite" direction. * If the given argument is {@code null} or is not a known direction, then * this method conservatively returns {@code false}. * * @param dir the direction to test, or {@code null}. * @return {@code true} if the given direction is an "opposite". */ public static boolean isOpposite(final AxisDirection dir) { final AxisDirection opposite = opposite(dir); return (opposite != null) && opposite.ordinal() < dir.ordinal(); }
/** * Creates a code list of an other kind. The returned set contains a code list having * the same ordinal value than {@link AxisDirection#NORTH}, so we can detect if the * {@code SortedSet} confuses the code list types. */ private CodeListSet<OnLineFunction> createOtherKind() { // For the validity of the tests, ordinal value must be the same. assertEquals(NORTH.ordinal(), OnLineFunction.INFORMATION.ordinal()); final CodeListSet<OnLineFunction> c = new CodeListSet<>(OnLineFunction.class); assertTrue(c.add(OnLineFunction.INFORMATION)); return c; }