diff --git a/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java b/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java index 126cd0e18fb..921c645b2a0 100644 --- a/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java +++ b/src/main/java/org/elasticsearch/common/geo/builders/BasePolygonBuilder.java @@ -129,9 +129,9 @@ public abstract class BasePolygonBuilder> 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> 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; } diff --git a/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java b/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java index c0fd9f804e9..a1c7f917ed4 100644 --- a/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java +++ b/src/main/java/org/elasticsearch/common/geo/builders/ShapeBuilder.java @@ -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";