Sitelet https://github.com/Esri/geometry-api-java/pull/99/commits/6c3d5955ac99dff5e39adedce49b32414f8b8fba
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix a bug in generalize for large deviations
  • Loading branch information
stolstov committed Dec 18, 2015
commit 6c3d5955ac99dff5e39adedce49b32414f8b8fba
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ private Geometry Generalize(Geometry geom) {
if (geom.isEmpty())
return geom;
MultiPath mp = (MultiPath) geom;
if (mp == null)
throw GeometryException.GeometryInternalError();
MultiPath dstmp = (MultiPath) geom.createInstance();
Line line = new Line();
for (int ipath = 0, npath = mp.getPathCount(); ipath < npath; ipath++) {
Expand Down Expand Up @@ -113,7 +111,9 @@ private void GeneralizePath(MultiPathImpl mpsrc, int ipath,
if (!bClosed)
resultStack.add(stack.get(0));

if (resultStack.size() == stack.size()) {
int rs_size = resultStack.size();
int path_size = mpsrc.getPathSize(ipath);
if (rs_size == path_size && rs_size == stack.size()) {
mpdst.addPath(mpsrc, ipath, true);
} else {
if (resultStack.size() >= 2) {
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/esri/core/geometry/TestGeneralize.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.esri.core.geometry;

import junit.framework.TestCase;

import org.junit.Test;

public class TestGeneralize extends TestCase {
Expand Down Expand Up @@ -90,4 +91,24 @@ public static void test2() {
assertTrue(points[0].x == 0 && points[0].y == 0);
assertTrue(points[1].x == 0 && points[1].y == 10);
}

@Test
public static void testLargeDeviation() {
{
Polygon input_polygon = new Polygon();
input_polygon
.addEnvelope(Envelope2D.construct(0, 0, 20, 10), false);
Geometry densified_geom = OperatorDensifyByLength.local().execute(
input_polygon, 1, null);
Geometry geom = OperatorGeneralize.local().execute(densified_geom,
1, true, null);
int pc = ((MultiPath) geom).getPointCount();
assertTrue(pc == 4);

Geometry large_dev = OperatorGeneralize.local().execute(
densified_geom, 40, true, null);
int pc1 = ((MultiPath) large_dev).getPointCount();
assertTrue(pc1 == 0);
}
}
}