fixed java.lang.IndexOutOfBoundsException when first way was without any

nodes.
This commit is contained in:
Pavol Zibrita 2012-07-17 02:00:44 +02:00
parent 13fda484e5
commit 41be54750f
2 changed files with 22 additions and 13 deletions

View file

@ -168,6 +168,13 @@ public class MultipolygonTest {
assertFalse(testee.hasOpenedPolygons());
}
@Test
public void test_firstEmptyWayThanOpenedWay()
{
testee.addOuterWay(new Way(111));
testee.addOuterWay(poly1_1_of_2);
assertEquals(1, testee.countOuterPolygons());
assertTrue(testee.hasOpenedPolygons());
}
}

View file

@ -32,18 +32,20 @@ public class Multipolygon {
protected IdentityHashMap<Way,List<Way>> outerInnerMapping;
private void addNewPolygonPart(List<Way> polygons, List<Way> closedPolygons, Way newPoly) {
if (isClosed(newPoly)) {
closedPolygons.add(newPoly); //if closed, put directly to closed polygons
} else if (polygons.isEmpty()) {
polygons.add(newPoly); //if open, and first, put to polygons..
} else {
// now we try to merge the ways to form bigger polygons
Stack<Way> wayStack = new Stack<Way>();
wayStack.push(newPoly);
addAndMergePolygon(polygons, closedPolygons, wayStack);
}
//reset the mapping
outerInnerMapping = null;
if (!newPoly.getNodes().isEmpty()) {
if (isClosed(newPoly)) {
closedPolygons.add(newPoly); //if closed, put directly to closed polygons
} else if (polygons.isEmpty()) {
polygons.add(newPoly); //if open, and first, put to polygons..
} else {
// now we try to merge the ways to form bigger polygons
Stack<Way> wayStack = new Stack<Way>();
wayStack.push(newPoly);
addAndMergePolygon(polygons, closedPolygons, wayStack);
}
//reset the mapping
outerInnerMapping = null;
} //else do nothing
}
private boolean isClosed(Way newPoly) {