Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions src/main/java/com/esri/core/geometry/OperatorGeneralizeCursor.java
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,19 +111,23 @@ 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) {
if (m_bRemoveDegenerateParts && resultStack.size() == 2) {
if (bClosed)
if (resultStack.size() > 0) {
if (m_bRemoveDegenerateParts && resultStack.size() <= 2) {
if (bClosed || resultStack.size() == 1)
return;

double d = Point2D.distance(
mpsrc.getXY(resultStack.get(0)),
mpsrc.getXY(resultStack.get(1)));
if (d <= m_maxDeviation)
return;
}

Point point = new Point();
for (int i = 0, n = resultStack.size(); i < n; i++) {
mpsrc.getPointByVal(resultStack.get(i), point);
Expand All @@ -136,8 +138,9 @@ private void GeneralizePath(MultiPathImpl mpsrc, int ipath,
}

if (bClosed) {
if (!m_bRemoveDegenerateParts && resultStack.size() == 2)
for (int i = resultStack.size(); i < 3; i++)
mpdst.lineTo(point);

mpdst.closePathWithLine();
}
}
Expand Down
26 changes: 26 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,29 @@ 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_dev1 = OperatorGeneralize.local().execute(
densified_geom, 40, true, null);
int pc1 = ((MultiPath) large_dev1).getPointCount();
assertTrue(pc1 == 0);

Geometry large_dev2 = OperatorGeneralize.local().execute(
densified_geom, 40, false, null);
int pc2 = ((MultiPath) large_dev2).getPointCount();
assertTrue(pc2 == 3);
}
}
}