Skip to content

Commit 6d87284

Browse files
committed
[GEO] Removing unnecessary orientation enumerators
PR elastic#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 elastic#9035
1 parent 77a7ef2 commit 6d87284

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public Coordinate[][][] coordinates() {
129129

130130
Edge[] edges = new Edge[numEdges];
131131
Edge[] holeComponents = new Edge[holes.size()];
132-
int offset = createEdges(0, orientation.getValue(), shell, null, edges, 0);
132+
int offset = createEdges(0, orientation, shell, null, edges, 0);
133133
for (int i = 0; i < holes.size(); i++) {
134-
int length = createEdges(i+1, orientation.getValue(), shell, this.holes.get(i), edges, offset);
134+
int length = createEdges(i+1, orientation, shell, this.holes.get(i), edges, offset);
135135
holeComponents[i] = edges[offset];
136136
offset += length;
137137
}
@@ -457,14 +457,15 @@ private static void connect(Edge in, Edge out) {
457457
}
458458
}
459459

460-
private static int createEdges(int component, boolean orientation, BaseLineStringBuilder<?> shell,
460+
private static int createEdges(int component, Orientation orientation, BaseLineStringBuilder<?> shell,
461461
BaseLineStringBuilder<?> hole,
462462
Edge[] edges, int offset) {
463463
// inner rings (holes) have an opposite direction than the outer rings
464-
boolean direction = (component != 0) ? !orientation : orientation;
464+
// XOR will invert the orientation for outer ring cases (Truth Table:, T/T = F, T/F = T, F/T = T, F/F = F)
465+
boolean direction = (component != 0 ^ orientation == Orientation.RIGHT);
465466
// set the points array accordingly (shell or hole)
466467
Coordinate[] points = (hole != null) ? hole.coordinates(false) : shell.coordinates(false);
467-
Edge.ring(component, direction, orientation, shell, points, 0, edges, offset, points.length-1);
468+
Edge.ring(component, direction, orientation == Orientation.LEFT, shell, points, 0, edges, offset, points.length-1);
468469
return points.length-1;
469470
}
470471

src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -640,28 +640,13 @@ public int compare(Edge o1, Edge o2) {
640640
}
641641

642642
public static enum Orientation {
643-
LEFT("left", true),
644-
CLOCKWISE("clockwise", true),
645-
CW("cw", true),
646-
RIGHT("right", false),
647-
COUNTERCLOCKWISE("counterclockwise", false),
648-
CCW("ccw", false);
643+
LEFT,
644+
RIGHT;
649645

650-
protected String name;
651-
protected boolean orientation;
652-
653-
private Orientation(String name, boolean orientation) {
654-
this.orientation = orientation;
655-
this.name = name;
656-
}
657-
658-
public static Orientation forName(String name) {
659-
return Orientation.valueOf(name.toUpperCase(Locale.ROOT));
660-
}
661-
662-
public boolean getValue() {
663-
return orientation;
664-
}
646+
public static final Orientation CLOCKWISE = Orientation.LEFT;
647+
public static final Orientation COUNTER_CLOCKWISE = Orientation.RIGHT;
648+
public static final Orientation CW = Orientation.LEFT;
649+
public static final Orientation CCW = Orientation.RIGHT;
665650
}
666651

667652
public static final String FIELD_TYPE = "type";

0 commit comments

Comments
 (0)