Skip to content

Commit

Permalink
If everything else is the same, select older element as merge target
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Dec 6, 2024
1 parent 32e6743 commit cf1987f
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 69 deletions.
7 changes: 5 additions & 2 deletions src/main/java/de/blau/android/osm/MergeAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Set;
import java.util.TreeMap;

import android.icu.math.MathContext;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -66,8 +67,10 @@ public MergeAction(final @NonNull StorageDelegator delegator, @NonNull OsmElemen
public MergeAction(final @NonNull StorageDelegator delegator, @NonNull OsmElement mergeInto, @NonNull OsmElement mergeFrom, boolean swappable) {
this.delegator = delegator;
// first determine if one of the elements already has a valid id, if it is not and other node has valid id swap
// else check version numbers, the point of this is to preserve as much history as possible
if (swappable && (((mergeInto.getOsmId() < 0) && (mergeFrom.getOsmId() > 0)) || mergeInto.getOsmVersion() < mergeFrom.getOsmVersion())) {
// else check version numbers, then choose the older element. The point of this is to preserve as much history
// as possible
if (swappable && ((mergeInto.getOsmId() < 0 && mergeFrom.getOsmId() > 0) || mergeInto.getOsmVersion() < mergeFrom.getOsmVersion()
|| Math.abs(mergeInto.getOsmId()) > Math.abs(mergeFrom.getOsmId()))) {
// swap
Log.d(DEBUG_TAG, "swap into #" + mergeInto.getOsmId() + " with from #" + mergeFrom.getOsmId());
OsmElement tmpElement = mergeInto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void polgonsToMultiPolygonMergeTest1() {
final Way inner2 = (Way) inners.get(1).getElement();
assertTrue(inner2.isClosed());
assertEquals(5, inner2.getNodes().size());
assertEquals(-9, outer.getOsmId());
assertEquals(-8, outer.getOsmId());
}

/**
Expand Down
Loading

0 comments on commit cf1987f

Please sign in to comment.