Fix a bug where connected ways would be deleted

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-11-14 10:18:43 -07:00
rodzic 20ac384229
commit 6490070f45
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 27 dodań i 4 usunięć

Wyświetl plik

@ -257,8 +257,10 @@ public class GetDataRunnable extends RecursiveTask<DataSet> implements CancelLis
BBox tBBox = new BBox();
tBBox.addPrimitive(way, 0.001);
if (way.getDataSet().searchWays(tBBox).parallelStream()
.filter(tWay -> !way.equals(tWay) && !tWay.isDeleted()).anyMatch(
tWay -> Geometry.getDistance(way, tWay) < MapWithAIPreferenceHelper.getMaxNodeDistance())) {
.filter(tWay -> !way.equals(tWay) && !tWay.isDeleted())
.anyMatch(tWay -> way.getNodes().parallelStream().filter(
tNode -> Geometry.getDistance(tNode, tWay) < MapWithAIPreferenceHelper.getMaxNodeDistance())
.count() == way.getNodesCount())) {
way.setDeleted(true);
}
}

Wyświetl plik

@ -8,11 +8,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.data.osm.WaySegment;
@ -23,7 +23,6 @@ public class GetDataRunnableTest {
public JOSMTestRules rule = new JOSMTestRules().projection();
@Test
@Ignore("Failing on GitLab CI")
public void testAddMissingElement() {
Way way1 = TestUtils.newWay("", new Node(new LatLon(-5.7117803, 34.5011898)),
new Node(new LatLon(-5.7111915, 34.5013994)), new Node(new LatLon(-5.7104175, 34.5016354)));
@ -49,4 +48,26 @@ public class GetDataRunnableTest {
assertTrue(way1.getNodes().containsAll(way2.getNodes()));
}
@Test
public void testCleanupArtifacts() {
Way way1 = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 1)));
Way way2 = TestUtils.newWay("", way1.firstNode(), new Node(new LatLon(-1, -1)));
DataSet ds = new DataSet();
way1.getNodes().forEach(ds::addPrimitive);
ds.addPrimitive(way1);
way2.getNodes().stream().filter(node -> node.getDataSet() == null).forEach(ds::addPrimitive);
ds.addPrimitive(way2);
GetDataRunnable.cleanupArtifacts(way1);
assertEquals(2, ds.getWays().parallelStream().filter(way -> !way.isDeleted()).count());
Node tNode = new Node(way1.lastNode(), true);
ds.addPrimitive(tNode);
way2.addNode(tNode);
GetDataRunnable.cleanupArtifacts(way1);
assertEquals(1, ds.getWays().parallelStream().filter(way -> !way.isDeleted()).count());
}
}