Skip to content

Commit

Permalink
[GEO] Removing unnecessary orientation enumerators
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nknize committed Dec 23, 2014
1 parent 77a7ef2 commit 6d87284
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
Expand Up @@ -129,9 +129,9 @@ public Coordinate[][][] coordinates() {

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;
}
Expand Down Expand Up @@ -457,14 +457,15 @@ private static void connect(Edge in, Edge out) {
}
}

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;
}

Expand Down
Expand Up @@ -640,28 +640,13 @@ public int compare(Edge o1, Edge o2) {
}

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";
Expand Down

0 comments on commit 6d87284

Please sign in to comment.