[GEO] Removing unnecessary orientation enumerators

PR #8978 included 4 unnecessary enumeration values ('cw', 'clockwise', 'ccw', 'counterclockwise'). Since the ShapeBuilder.parse method handles these as strings and maps them to LEFT and RIGHT enumerators, respectively, their enumeration counterpart is unnecessary. This minor change adds 4 static convenience variables (COUNTER_CLOCKWISE, CLOCKWISE, CCW, CW) for purposes of the API and removes the unnecessary values from the Orientation Enum.

closes #9035
This commit is contained in:
Nicholas Knize 2014-12-22 14:41:13 -06:00
parent 77a7ef28b3
commit 6d872843bd
2 changed files with 12 additions and 26 deletions

View File

@ -129,9 +129,9 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
Edge[] edges = new Edge[numEdges];
Edge[] holeComponents = new Edge[holes.size()];
int offset = createEdges(0, orientation.getValue(), shell, null, edges, 0);
int offset = createEdges(0, orientation, shell, null, edges, 0);
for (int i = 0; i < holes.size(); i++) {
int length = createEdges(i+1, orientation.getValue(), shell, this.holes.get(i), edges, offset);
int length = createEdges(i+1, orientation, shell, this.holes.get(i), edges, offset);
holeComponents[i] = edges[offset];
offset += length;
}
@ -457,14 +457,15 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
}
}
private static int createEdges(int component, boolean orientation, BaseLineStringBuilder<?> shell,
private static int createEdges(int component, Orientation orientation, BaseLineStringBuilder<?> shell,
BaseLineStringBuilder<?> hole,
Edge[] edges, int offset) {
// inner rings (holes) have an opposite direction than the outer rings
boolean direction = (component != 0) ? !orientation : orientation;
// XOR will invert the orientation for outer ring cases (Truth Table:, T/T = F, T/F = T, F/T = T, F/F = F)
boolean direction = (component != 0 ^ orientation == Orientation.RIGHT);
// set the points array accordingly (shell or hole)
Coordinate[] points = (hole != null) ? hole.coordinates(false) : shell.coordinates(false);
Edge.ring(component, direction, orientation, shell, points, 0, edges, offset, points.length-1);
Edge.ring(component, direction, orientation == Orientation.LEFT, shell, points, 0, edges, offset, points.length-1);
return points.length-1;
}

View File

@ -640,28 +640,13 @@ public abstract class ShapeBuilder implements ToXContent {
}
public static enum Orientation {
LEFT("left", true),
CLOCKWISE("clockwise", true),
CW("cw", true),
RIGHT("right", false),
COUNTERCLOCKWISE("counterclockwise", false),
CCW("ccw", false);
LEFT,
RIGHT;
protected String name;
protected boolean orientation;
private Orientation(String name, boolean orientation) {
this.orientation = orientation;
this.name = name;
}
public static Orientation forName(String name) {
return Orientation.valueOf(name.toUpperCase(Locale.ROOT));
}
public boolean getValue() {
return orientation;
}
public static final Orientation CLOCKWISE = Orientation.LEFT;
public static final Orientation COUNTER_CLOCKWISE = Orientation.RIGHT;
public static final Orientation CW = Orientation.LEFT;
public static final Orientation CCW = Orientation.RIGHT;
}
public static final String FIELD_TYPE = "type";