Skip to content

Commit

Permalink
Don't return null buffer polygon (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
stolstov authored Aug 15, 2019
1 parent 48b9cbb commit 7812fd3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/esri/core/geometry/Bufferer.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ private Geometry bufferPolygon_() {
generateCircleTemplate_();
m_geometry = simplify.execute(m_geometry, null, false,
m_progress_tracker);
if(m_geometry.isEmpty()) {
return m_geometry;
}

if (m_distance < 0) {
Polygon poly = (Polygon) (m_geometry);
Expand All @@ -600,7 +603,12 @@ private Geometry bufferPolygon_() {
.getInstance().getOperator(Operator.Type.Union)).execute(
cursor, m_spatialReference, m_progress_tracker);
Geometry result = union_cursor.next();
return result;
if (result != null) {
return result;
} else {
//never return empty.
return new Polygon(m_geometry.getDescription());
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/esri/core/geometry/TestBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import junit.framework.TestCase;
import org.junit.Test;

import com.esri.core.geometry.ogc.OGCGeometry;

public class TestBuffer extends TestCase {
@Override
protected void setUp() throws Exception {
Expand Down Expand Up @@ -389,4 +391,27 @@ public void testBufferPolygon() {
assertTrue(simplify.isSimpleAsFeature(result, sr, null));
}
}

@Test
public static void testTinyBufferOfPoint() {
{
Geometry result1 = OperatorBuffer.local().execute(new Point(0, 0), SpatialReference.create(4326), 1e-9, null);
assertTrue(result1 != null);
assertTrue(result1.isEmpty());
Geometry geom1 = OperatorImportFromWkt.local().execute(0, Geometry.Type.Unknown, "POLYGON ((177.0 64.0, 177.0000000001 64.0, 177.0000000001 64.0000000001, 177.0 64.0000000001, 177.0 64.0))", null);
Geometry result2 = OperatorBuffer.local().execute(geom1, SpatialReference.create(4326), 0.01, null);
assertTrue(result2 != null);
assertTrue(result2.isEmpty());

}

{
OGCGeometry p = OGCGeometry.fromText(
"POLYGON ((177.0 64.0, 177.0000000001 64.0, 177.0000000001 64.0000000001, 177.0 64.0000000001, 177.0 64.0))");
OGCGeometry buffered = p.buffer(0.01);
assertTrue(buffered != null);
}


}
}

0 comments on commit 7812fd3

Please sign in to comment.