Skip to content

Commit 559fe2f

Browse files
committed
Fixed a couple of review comments
1 parent 13c1fa3 commit 559fe2f

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎src/main/java/com/esri/core/geometry/ogc/OGCConcreteGeometryCollection.java‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ public int hashCode() {
522522

523523
@Override
524524
public double distance(OGCGeometry another) {
525-
double minD = 0;
525+
double minD = Double.NaN;
526526
for (int i = 0, n = numGeometries(); i < n; ++i) {
527527
double d = geometryN(i).distance(another);
528-
if (d < minD) {
528+
if (d < minD || Double.isNaN(minD)) {
529529
minD = d;
530530
if (minD == 0) {
531531
break;
@@ -612,6 +612,7 @@ public boolean isFlattened() {
612612
if (n > 3)
613613
return false;
614614

615+
int dimension = -1;
615616
for (int i = 0; i < n; ++i) {
616617
OGCGeometry g = geometryN(i);
617618
if (g.isEmpty())
@@ -620,6 +621,13 @@ public boolean isFlattened() {
620621
String t = g.geometryType();
621622
if (t != OGCMultiPoint.TYPE && t != OGCMultiPolygon.TYPE && t != OGCMultiLineString.TYPE)
622623
return false;
624+
625+
//check strict order of geometry dimensions
626+
int d = g.dimension();
627+
if (d <= dimension)
628+
return false;
629+
630+
dimension = d;
623631
}
624632

625633
return true;

‎src/main/java/com/esri/core/geometry/ogc/OGCGeometry.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ public boolean equals(OGCGeometry another) {
270270
}
271271

272272
public boolean disjoint(OGCGeometry another) {
273+
if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
274+
return another.disjoint(this);
275+
}
276+
273277
com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
274278
com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
275279
return com.esri.core.geometry.GeometryEngine.disjoint(geom1, geom2,
@@ -299,6 +303,10 @@ public boolean within(OGCGeometry another) {
299303
}
300304

301305
public boolean contains(OGCGeometry another) {
306+
if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
307+
return another.contains(this);
308+
}
309+
302310
com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
303311
com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
304312
return com.esri.core.geometry.GeometryEngine.contains(geom1, geom2,

‎src/test/java/com/esri/core/geometry/TestOGC.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,25 @@ public void testContainsOnGeometryCollection() {
10041004
public void testIntersectsOnGeometryCollection() {
10051005
OGCGeometry ogcGeometry = OGCGeometry.fromText("GEOMETRYCOLLECTION (POINT (1 1))");
10061006
assertTrue(ogcGeometry.intersects(OGCGeometry.fromText("POINT (1 1)")));
1007+
ogcGeometry = OGCGeometry.fromText("POINT (1 1)");
1008+
assertTrue(ogcGeometry.intersects(OGCGeometry.fromText("GEOMETRYCOLLECTION (POINT (1 1))")));
10071009
}
10081010

10091011
@Test
10101012
public void testDistanceOnGeometryCollection() {
10111013
OGCGeometry ogcGeometry = OGCGeometry.fromText("GEOMETRYCOLLECTION (POINT (1 1))");
10121014
assertTrue(ogcGeometry.distance(OGCGeometry.fromText("POINT (1 1)")) == 0);
1015+
1016+
//distance to empty is NAN
1017+
ogcGeometry = OGCGeometry.fromText("GEOMETRYCOLLECTION (POINT (1 1))");
1018+
assertTrue(Double.isNaN(ogcGeometry.distance(OGCGeometry.fromText("POINT EMPTY"))));
1019+
}
1020+
1021+
@Test
1022+
public void testFlattened() {
1023+
OGCConcreteGeometryCollection ogcGeometry = (OGCConcreteGeometryCollection)OGCGeometry.fromText("GEOMETRYCOLLECTION (MULTILINESTRING ((1 2, 3 4)), MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2))), MULTIPOINT (1 1))");
1024+
assertFalse(ogcGeometry.isFlattened());
1025+
ogcGeometry = (OGCConcreteGeometryCollection)OGCGeometry.fromText("GEOMETRYCOLLECTION (MULTIPOINT (1 1), MULTILINESTRING ((1 2, 3 4)), MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2))))");
1026+
assertTrue(ogcGeometry.isFlattened());
10131027
}
10141028
}

0 commit comments

Comments
 (0)