Ticket #24956: 24956-v2.patch
| File 24956-v2.patch, 6.5 KB (added by , 3 weeks ago) |
|---|
-
src/org/openstreetmap/josm/data/osm/Way.java
From Mon Sep 17 00:00:00 2001 From: Matt McCutchen <matt@mattmccutchen.net> Date: Fri, 30 Oct 2026 13:46:16 -0400 fix #24956 - Way "modified" flag should be based on node IDs, not coordinates Change Way.hasEqualSemanticAttributes to compare node IDs for non-new nodes. Keep the existing behavior of comparing semantic attributes of new nodes. --- src/org/openstreetmap/josm/data/osm/Way.java | 23 ++++- .../josm/data/osm/DataSetMergerTest.java | 110 +++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/src/org/openstreetmap/josm/data/osm/Way.java b/src/org/openstreetmap/josm/data/osm/Way.java index 85501abef5..6a492a782f 100644
a b public final class Way extends OsmPrimitive implements IWay<Node> { 318 318 return "{Way id=" + getUniqueId() + " version=" + getVersion()+ ' ' + getFlagsAsString() + ' ' + nodesDesc + '}'; 319 319 } 320 320 321 private static boolean memberNodesAreEquivalent(Node n1, Node n2) { 322 /* 323 * This logic attempts to serve at least the following use cases: 324 * 325 * 1. Determining whether a way is modified with respect to the OSM server and 326 * uploading it will have an effect. The data model stores only the node IDs, 327 * so this should be based only on whether the IDs are equal (see #24956). 328 * Since the server never contains "new" nodes, we will always use the ID 329 * comparison. 330 * 2. Merging layers. If both nodes are "new", then they will typically have 331 * different IDs, but we want to consider them equivalent for the purpose of 332 * comparing the ways if all other semantic attributes of the nodes are 333 * equal. See DataSetMergerTest.testWaySimpleTwoWaysWithNoIdNodesWithoutId. 334 * (TODO: What is the *end to end* use case that requires this behavior?) 335 */ 336 if (n1.isNew() && n2.isNew()) 337 return n1.hasEqualSemanticAttributes(n2); 338 else 339 return (n1.getId() == n2.getId()); 340 } 341 321 342 @Override 322 343 public boolean hasEqualSemanticAttributes(OsmPrimitive other, boolean testInterestingTagsOnly) { 323 344 if (!(other instanceof Way)) … … public final class Way extends OsmPrimitive implements IWay<Node> { 327 348 if (!super.hasEqualSemanticAttributes(other, testInterestingTagsOnly)) 328 349 return false; 329 350 return IntStream.range(0, getNodesCount()) 330 .allMatch(i -> getNode(i).hasEqualSemanticAttributes(w.getNode(i)));351 .allMatch(i -> memberNodesAreEquivalent(getNode(i), w.getNode(i))); 331 352 } 332 353 333 354 /** -
test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java
diff --git a/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java b/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java index 1c50e89a4b..902f64c5d6 100644
a b class DataSetMergerTest { 720 720 assertFalse(merged.isModified()); 721 721 } 722 722 723 /* 724 * The next two tests relate to the ability of re-downloading a way to reset the 725 * "modified" flag if the way has no difference compared to the server, which 726 * can happen if a change was made and then manually reverted. (See #3384 and 727 * #24956.) This behavior should be based on whether the list of node IDs is 728 * identical and is implemented in Way.memberNodesAreEquivalent. 729 */ 730 731 /** 732 * Non-regression test 1 for 733 * <a href="https://josm.openstreetmap.de/ticket/24956">Bug #24956</a>. A moved 734 * node should not prevent the way's "modified" flag from being cleared. 735 */ 736 @Test 737 void testWayWithMovedNodeResetModified() { 738 739 // -- my data set 740 741 Node n1 = new Node(LatLon.ZERO); 742 n1.setOsmId(1, 1); 743 my.addPrimitive(n1); 744 745 // Different coordinates than n4. 746 Node n2 = new Node(new LatLon(2, 2)); 747 n2.setOsmId(2, 1); 748 n2.setModified(true); 749 my.addPrimitive(n2); 750 751 Way myWay = new Way(); 752 myWay.setOsmId(3, 1); 753 myWay.setModified(true); 754 myWay.addNode(n1); 755 myWay.addNode(n2); 756 my.addPrimitive(myWay); 757 758 // -- their data set 759 760 Node n3 = new Node(LatLon.ZERO); 761 n3.setOsmId(1, 1); 762 their.addPrimitive(n3); 763 764 Node n4 = new Node(new LatLon(1, 1)); 765 n4.setOsmId(2, 1); 766 their.addPrimitive(n4); 767 768 Way theirWay = new Way(); 769 theirWay.setOsmId(3, 1); 770 theirWay.addNode(n3); 771 theirWay.addNode(n4); 772 their.addPrimitive(theirWay); 773 774 DataSetMerger visitor = new DataSetMerger(my, their); 775 visitor.merge(); 776 777 // -- tests 778 Way merged = (Way) my.getWays().toArray()[0]; 779 assertFalse(merged.isModified()); 780 } 781 782 /** 783 * Non-regression test 2 for 784 * <a href="https://josm.openstreetmap.de/ticket/24956">Bug #24956</a>. 785 * Replacement of a node with a new duplicate node with identical coordinates is 786 * a modification at the OSM data model level and should prevent the way's 787 * "modified" flag from being cleared. 788 */ 789 @Test 790 void testWayWithNewDuplicateNodeDontResetModified() { 791 792 // -- my data set 793 794 Node n1 = new Node(LatLon.ZERO); 795 n1.setOsmId(1, 1); 796 my.addPrimitive(n1); 797 798 // Same coordinates as n4, but new, without an ID. 799 Node n2 = new Node(new LatLon(1, 1)); 800 my.addPrimitive(n2); 801 802 Way myWay = new Way(); 803 myWay.setOsmId(3, 1); 804 myWay.setModified(true); 805 myWay.addNode(n1); 806 myWay.addNode(n2); 807 my.addPrimitive(myWay); 808 809 // -- their data set 810 811 Node n3 = new Node(LatLon.ZERO); 812 n3.setOsmId(1, 1); 813 their.addPrimitive(n3); 814 815 Node n4 = new Node(new LatLon(1, 1)); 816 n4.setOsmId(2, 1); 817 their.addPrimitive(n4); 818 819 Way theirWay = new Way(); 820 theirWay.setOsmId(3, 1); 821 theirWay.addNode(n3); 822 theirWay.addNode(n4); 823 their.addPrimitive(theirWay); 824 825 DataSetMerger visitor = new DataSetMerger(my, their); 826 visitor.merge(); 827 828 // -- tests 829 Way merged = (Way) my.getWays().toArray()[0]; 830 assertTrue(merged.isModified()); 831 } 832 723 833 /** 724 834 * My dataset includes a deleted node. 725 835 * Their dataset includes a way with three nodes, the first one being my node.
