* Check for NORTH, SOUTH, EAST, EAST-NORTH-EAST, etc.
* Checked first because this is the most common case.
*/
int c = AxisDirections.angleForCompass(source, target);
if (c != Integer.MIN_VALUE) {
return new Angle(c * (360.0 / AxisDirections.COMPASS_COUNT));
}
/*
* Check for GEOCENTRIC_X, GEOCENTRIC_Y, GEOCENTRIC_Z.
*/
c = AxisDirections.angleForGeocentric(source, target);
if (c != Integer.MIN_VALUE) {
return new Angle(c * 90);
}
/*
* Check for DISPLAY_UP, DISPLAY_DOWN, etc. assuming a flat screen.
* Note that we do not check for grid directions (COLUMN_POSITIVE,
* ROW_POSITIVE, etc.) because the grid geometry may be anything.
*/
c = AxisDirections.angleForDisplay(source, target);
if (c != Integer.MIN_VALUE) {
return new Angle(c * (360 / AxisDirections.DISPLAY_COUNT));
}
/*
* Check for "South along 90° East", etc. directions. Note that this
* check may perform a relatively costly parsing of axis direction name.
* (NOTE: the check for 'isUserDefined' is performed outside DirectionAlongMeridian for
* avoiding class initialization of the later in the common case where we do not need it).
*/
final DirectionAlongMeridian srcMeridian, tgtMeridian;
srcMeridian = AxisDirections.isUserDefined(source) ? DirectionAlongMeridian.parse(source) : null;
tgtMeridian = AxisDirections.isUserDefined(target) ? DirectionAlongMeridian.parse(target) : null;
if (srcMeridian != null && tgtMeridian != null) {
return new Angle(srcMeridian.angle(tgtMeridian));
}
/*
* Check for UP and DOWN, with special case if one of the direction is horizontal
* (either a compass direction of a direction along a meridian).
*/
final boolean srcVrt = AxisDirections.isVertical(source);
final boolean tgtVrt = AxisDirections.isVertical(target);
if (tgtVrt) {
if (srcVrt) {
return new Angle(source.equals(target) ? 0 : target.equals(AxisDirection.UP) ? 180 : -180);
} else if (AxisDirections.isCompass(source) || srcMeridian != null) {
return target.equals(AxisDirection.UP) ? ElevationAngle.ZENITH : ElevationAngle.NADIR;
}
} else if (srcVrt) {
if (AxisDirections.isCompass(target) || tgtMeridian != null) {