Skip to content

Commit 90d56ae

Browse files
committed
Geo: Change order of parameter in Geometries to lon, lat
Changes the order of parameters in Geometries from lat, lon to lon, lat and moves all Geometry classes are moved to the org.elasticsearch.geomtery package. Closes elastic#45048
1 parent de8b9f3 commit 90d56ae

File tree

94 files changed

+1127
-1027
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1127
-1027
lines changed

libs/geo/src/main/java/org/elasticsearch/geo/geometry/Circle.java renamed to libs/geo/src/main/java/org/elasticsearch/geometry/Circle.java

+41-27
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,37 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.geo.geometry;
20+
package org.elasticsearch.geometry;
21+
22+
import org.elasticsearch.geometry.utils.WellKnownText;
2123

2224
/**
2325
* Circle geometry (not part of WKT standard, but used in elasticsearch) defined by lat/lon coordinates of the center in degrees
2426
* and optional altitude in meters.
2527
*/
2628
public class Circle implements Geometry {
2729
public static final Circle EMPTY = new Circle();
28-
private final double lat;
29-
private final double lon;
30-
private final double alt;
30+
private final double y;
31+
private final double x;
32+
private final double z;
3133
private final double radiusMeters;
3234

3335
private Circle() {
34-
lat = 0;
35-
lon = 0;
36-
alt = Double.NaN;
36+
y = 0;
37+
x = 0;
38+
z = Double.NaN;
3739
radiusMeters = -1;
3840
}
3941

40-
public Circle(final double lat, final double lon, final double radiusMeters) {
41-
this(lat, lon, Double.NaN, radiusMeters);
42+
public Circle(final double x, final double y, final double radiusMeters) {
43+
this(x, y, Double.NaN, radiusMeters);
4244
}
4345

44-
public Circle(final double lat, final double lon, final double alt, final double radiusMeters) {
45-
this.lat = lat;
46-
this.lon = lon;
46+
public Circle(final double x, final double y, final double z, final double radiusMeters) {
47+
this.y = y;
48+
this.x = x;
4749
this.radiusMeters = radiusMeters;
48-
this.alt = alt;
50+
this.z = z;
4951
if (radiusMeters < 0 ) {
5052
throw new IllegalArgumentException("Circle radius [" + radiusMeters + "] cannot be negative");
5153
}
@@ -56,20 +58,32 @@ public ShapeType type() {
5658
return ShapeType.CIRCLE;
5759
}
5860

59-
public double getLat() {
60-
return lat;
61+
public double getY() {
62+
return y;
6163
}
6264

63-
public double getLon() {
64-
return lon;
65+
public double getX() {
66+
return x;
6567
}
6668

6769
public double getRadiusMeters() {
6870
return radiusMeters;
6971
}
7072

73+
public double getZ() {
74+
return z;
75+
}
76+
77+
public double getLat() {
78+
return y;
79+
}
80+
81+
public double getLon() {
82+
return x;
83+
}
84+
7185
public double getAlt() {
72-
return alt;
86+
return z;
7387
}
7488

7589
@Override
@@ -78,23 +92,23 @@ public boolean equals(Object o) {
7892
if (o == null || getClass() != o.getClass()) return false;
7993

8094
Circle circle = (Circle) o;
81-
if (Double.compare(circle.lat, lat) != 0) return false;
82-
if (Double.compare(circle.lon, lon) != 0) return false;
95+
if (Double.compare(circle.y, y) != 0) return false;
96+
if (Double.compare(circle.x, x) != 0) return false;
8397
if (Double.compare(circle.radiusMeters, radiusMeters) != 0) return false;
84-
return (Double.compare(circle.alt, alt) == 0);
98+
return (Double.compare(circle.z, z) == 0);
8599
}
86100

87101
@Override
88102
public int hashCode() {
89103
int result;
90104
long temp;
91-
temp = Double.doubleToLongBits(lat);
105+
temp = Double.doubleToLongBits(y);
92106
result = (int) (temp ^ (temp >>> 32));
93-
temp = Double.doubleToLongBits(lon);
107+
temp = Double.doubleToLongBits(x);
94108
result = 31 * result + (int) (temp ^ (temp >>> 32));
95109
temp = Double.doubleToLongBits(radiusMeters);
96110
result = 31 * result + (int) (temp ^ (temp >>> 32));
97-
temp = Double.doubleToLongBits(alt);
111+
temp = Double.doubleToLongBits(z);
98112
result = 31 * result + (int) (temp ^ (temp >>> 32));
99113
return result;
100114
}
@@ -111,11 +125,11 @@ public boolean isEmpty() {
111125

112126
@Override
113127
public String toString() {
114-
return "lat=" + lat + ", lon=" + lon + ", radius=" + radiusMeters + (Double.isNaN(alt) ? ", alt=" + alt : "");
128+
return WellKnownText.INSTANCE.toWKT(this);
115129
}
116130

117131
@Override
118-
public boolean hasAlt() {
119-
return Double.isNaN(alt) == false;
132+
public boolean hasZ() {
133+
return Double.isNaN(z) == false;
120134
}
121135
}

libs/geo/src/main/java/org/elasticsearch/geo/geometry/Geometry.java renamed to libs/geo/src/main/java/org/elasticsearch/geometry/Geometry.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.geo.geometry;
20+
package org.elasticsearch.geometry;
2121

2222
/**
2323
* Base class for all Geometry objects supported by elasticsearch
@@ -30,7 +30,11 @@ public interface Geometry {
3030

3131
boolean isEmpty();
3232

33-
default boolean hasAlt() {
33+
default boolean hasZ() {
3434
return false;
3535
}
36+
37+
default boolean hasAlt() {
38+
return hasZ();
39+
}
3640
}

libs/geo/src/main/java/org/elasticsearch/geo/geometry/GeometryCollection.java renamed to libs/geo/src/main/java/org/elasticsearch/geometry/GeometryCollection.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.geo.geometry;
19+
package org.elasticsearch.geometry;
20+
21+
import org.elasticsearch.geometry.utils.WellKnownText;
2022

2123
import java.util.Collections;
2224
import java.util.Iterator;
2325
import java.util.List;
24-
import java.util.Locale;
2526
import java.util.Objects;
2627

2728
/**
@@ -42,9 +43,9 @@ public GeometryCollection(List<G> shapes) {
4243
if (shapes == null || shapes.isEmpty()) {
4344
throw new IllegalArgumentException("the list of shapes cannot be null or empty");
4445
}
45-
hasAlt = shapes.get(0).hasAlt();
46+
hasAlt = shapes.get(0).hasZ();
4647
for (G shape : shapes) {
47-
if (shape.hasAlt() != hasAlt) {
48+
if (shape.hasZ() != hasAlt) {
4849
throw new IllegalArgumentException("all elements of the collection should have the same number of dimension");
4950
}
5051
}
@@ -93,16 +94,12 @@ public Iterator<G> iterator() {
9394
}
9495

9596
@Override
96-
public boolean hasAlt() {
97+
public boolean hasZ() {
9798
return hasAlt;
9899
}
99100

100101
@Override
101102
public String toString() {
102-
StringBuilder sb = new StringBuilder();
103-
sb.append(type().name().toLowerCase(Locale.ROOT)).append("(shapes=");
104-
sb.append(shapes);
105-
sb.append(")");
106-
return sb.toString();
103+
return WellKnownText.INSTANCE.toWKT(this);
107104
}
108105
}

libs/geo/src/main/java/org/elasticsearch/geo/geometry/GeometryVisitor.java renamed to libs/geo/src/main/java/org/elasticsearch/geometry/GeometryVisitor.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.geo.geometry;
20+
package org.elasticsearch.geometry;
21+
22+
import org.elasticsearch.geometry.utils.WellKnownText;
2123

2224
/**
2325
* Support class for creating Geometry Visitors.
@@ -40,7 +42,7 @@
4042
* The Visitor Pattern replaces this structure with Interface inheritance making it easier to identify all places that are using this
4143
* structure, and making a shape a compile-time failure instead of runtime.
4244
* <p>
43-
* See {@link org.elasticsearch.geo.utils.WellKnownText#toWKT(Geometry, StringBuilder)} for an example of how this interface is used.
45+
* See {@link WellKnownText#toWKT(Geometry, StringBuilder)} for an example of how this interface is used.
4446
*
4547
* @see <a href="https://en.wikipedia.org/wiki/Visitor_pattern">Visitor Pattern</a>
4648
*/

0 commit comments

Comments
 (0)