Skip to content

Commit

Permalink
Merge da8e4af into 36977d5
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Jan 12, 2024
2 parents 36977d5 + da8e4af commit 1af6d6d
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.carrotsearch.hppc.LongLongHashMap;
import com.carrotsearch.hppc.LongObjectHashMap;
import com.carrotsearch.hppc.ObjectIntHashMap;
import com.carrotsearch.hppc.SortedIterationLongObjectHashMap;

/**
* Static factory method for <a href="https://github.com/carrotsearch/hppc">High Performance Primitive Collections</a>.
Expand Down Expand Up @@ -40,4 +41,8 @@ public static LongIntHashMap newLongIntHashMap() {
public static LongByteMap newLongByteHashMap() {
return new LongByteHashMap(10, 0.75);
}

public static <T> SortedIterationLongObjectHashMap<T> sortedView(LongObjectHashMap<T> input) {
return new SortedIterationLongObjectHashMap<>(input, Long::compare);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import java.util.OptionalLong;
import java.util.TreeMap;
import java.util.function.LongSupplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -147,7 +147,8 @@ public void finish(TileArchiveMetadata tileArchiveMetadata) {
}
try {
Directories directories = makeDirectories(entries);
var otherMetadata = new LinkedHashMap<>(tileArchiveMetadata.toMap());
// use treemap to ensure consistent ouput between runs
var otherMetadata = new TreeMap<>(tileArchiveMetadata.toMap());

// exclude keys included in top-level header
otherMetadata.remove(TileArchiveMetadata.CENTER_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
package com.onthegomap.planetiler.reader.osm;

import com.carrotsearch.hppc.LongArrayList;
import com.carrotsearch.hppc.LongObjectMap;
import com.carrotsearch.hppc.LongObjectHashMap;
import com.carrotsearch.hppc.ObjectIntMap;
import com.carrotsearch.hppc.cursors.LongObjectCursor;
import com.onthegomap.planetiler.collection.Hppc;
import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.locationtech.jts.geom.Coordinate;
Expand All @@ -41,8 +40,9 @@
* Multipolygon way members have an "inner" and "outer" role, but they can be incorrectly specified, so instead
* determine the nesting order and alternate outer/inner/outer/inner... from the outermost ring inwards.
* <p>
* This class is ported to Java from https://github.com/omniscale/imposm3/blob/master/geom/multipolygon.go and
* https://github.com/omniscale/imposm3/blob/master/geom/ring.go
* This class is ported to Java from
* <a href="https://github.com/omniscale/imposm3/blob/master/geom/multipolygon.go">imposm3 multipolygon.go</a> and
* <a href="https://github.com/omniscale/imposm3/blob/master/geom/ring.go">imposm3 ring.go</a>
*/
public class OsmMultipolygon {
/*
Expand All @@ -62,7 +62,8 @@ private static class Ring {
private final Polygon geom;
private final double area;
private Ring containedBy = null;
private final Set<Ring> holes = new HashSet<>();
// use linked hash set to ensure same input always produces same output
private final Set<Ring> holes = new LinkedHashSet<>();

private Ring(Polygon geom) {
this.geom = geom;
Expand Down Expand Up @@ -163,7 +164,7 @@ private static Geometry doBuild(
boolean fix
) throws GeometryException {
try {
if (rings.size() == 0) {
if (rings.isEmpty()) {
throw new GeometryException.Verbose("osm_invalid_multipolygon_empty",
"error building multipolygon " + osmId + ": no rings to process");
}
Expand All @@ -175,7 +176,7 @@ private static Geometry doBuild(
}
polygons.sort(BY_AREA_DESCENDING);
Set<Ring> shells = groupParentChildShells(polygons);
if (shells.size() == 0) {
if (shells.isEmpty()) {
throw new GeometryException.Verbose("osm_invalid_multipolygon_not_closed",
"error building multipolygon " + osmId + ": multipolygon not closed");
} else if (shells.size() == 1) {
Expand Down Expand Up @@ -227,7 +228,8 @@ private static void addPolygonRings(List<Ring> polygons, Geometry geom) {
}

private static Set<Ring> groupParentChildShells(List<Ring> polygons) {
Set<Ring> shells = new HashSet<>();
// use linked hash set to ensure the same input always produces the same output
Set<Ring> shells = new LinkedHashSet<>();
int numPolygons = polygons.size();
if (numPolygons == 0) {
return shells;
Expand Down Expand Up @@ -313,7 +315,7 @@ static LongArrayList prependToSkipLast(LongArrayList orig, LongArrayList toPrepe
}

static List<LongArrayList> connectPolygonSegments(List<LongArrayList> outer) {
LongObjectMap<LongArrayList> endpointIndex = Hppc.newLongObjectHashMap(outer.size() * 2);
LongObjectHashMap<LongArrayList> endpointIndex = Hppc.newLongObjectHashMap(outer.size() * 2);
List<LongArrayList> completeRings = new ArrayList<>(outer.size());

for (LongArrayList ids : outer) {
Expand Down Expand Up @@ -366,12 +368,11 @@ static List<LongArrayList> connectPolygonSegments(List<LongArrayList> outer) {
}
}

for (LongObjectCursor<LongArrayList> cursor : endpointIndex) {
LongArrayList value = cursor.value;
if (value.size() >= 4) {
if (value.get(0) == value.get(value.size() - 1) || cursor.key == value.get(0)) {
completeRings.add(value);
}
// iterate in sorted order to ensure the same input always produces the same output
for (var entry : Hppc.sortedView(endpointIndex)) {
LongArrayList value = entry.value;
if (value.size() >= 4 && (value.get(0) == value.get(value.size() - 1) || entry.key == value.get(0))) {
completeRings.add(value);
}
}
return completeRings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ default CoordinateSequence getWayGeometry(LongArrayList nodeIds) {
* @param role "role" of the relation member
* @param relation user-provided data about the relation from pass1
*/
public record RelationMember<T extends OsmRelationInfo> (String role, T relation) {}
public record RelationMember<T extends OsmRelationInfo>(String role, T relation) {}

/** Raw relation membership data that gets encoded/decoded into a long. */
private record RelationMembership(String role, long relationId) {}
Expand Down
Loading

0 comments on commit 1af6d6d

Please sign in to comment.