From 6490070f45a2073acb80bdb8c4132702d8d6c2ee Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Thu, 14 Nov 2019 10:18:43 -0700 Subject: [PATCH] Fix a bug where connected ways would be deleted Signed-off-by: Taylor Smock --- .../mapwithai/backend/GetDataRunnable.java | 6 +++-- .../backend/GetDataRunnableTest.java | 25 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java index 7315cb6..63064ef 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java @@ -257,8 +257,10 @@ public class GetDataRunnable extends RecursiveTask 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); } } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java index 72b5c11..7e5c336 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java @@ -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()); + } + }