Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 26, 2023
1 parent 916f7e8 commit 8d80ba3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class FeatureMerge {

private static final Logger LOGGER = LoggerFactory.getLogger(FeatureMerge.class);
private static final BufferParameters bufferOps = new BufferParameters();
// this is slightly faster than Comparator.comparingInt
private static final Comparator<WithIndex<?>> BY_HILBERT_INDEX =
(o1, o2) -> Integer.compare(o1.hilbert, o2.hilbert);

static {
bufferOps.setJoinStyle(BufferParameters.JOIN_MITRE);
Expand Down Expand Up @@ -114,11 +117,6 @@ public static List<VectorTile.Feature> mergeMultiLineString(List<VectorTile.Feat
return mergeGeometries(features, GeometryType.LINE);
}

private static final Comparator<WithIndex<?>> BY_HILBERT_INDEX =
(o1, o2) -> Integer.compare(o1.hilbert(), o2.hilbert());

private record WithIndex<T> (T feature, int hilbert) {}

private static List<VectorTile.Feature> mergeGeometries(
List<VectorTile.Feature> features,
GeometryType geometryType
Expand Down Expand Up @@ -188,7 +186,7 @@ public static List<VectorTile.Feature> mergeLineStrings(List<VectorTile.Feature>
if (simplified instanceof LineString simpleLineString) {
line = simpleLineString;
} else {
LOGGER.warn("line string merge simplify emitted " + simplified.getGeometryType());
LOGGER.warn("line string merge simplify emitted {}", simplified.getGeometryType());
}
}
if (buffer >= 0) {
Expand Down Expand Up @@ -573,4 +571,6 @@ public static List<VectorTile.Feature> removePointsOutsideBuffer(List<VectorTile
}
return result;
}

private record WithIndex<T> (T feature, int hilbert) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public static VectorGeometryMerger newMerger(GeometryType geometryType) {
* Returns the hilbert index of the zig-zag-encoded first point of {@code geometry}.
* <p>
* This can be useful for sorting geometries to minimize encoded vector tile geometry command size since smaller
* values take fewer bytes using protobuf varint encoding.
* offsets take fewer bytes using protobuf varint encoding.
*/
public static int hilbertIndex(Geometry geometry) {
Coordinate coord = geometry.getCoordinate();
Expand Down Expand Up @@ -961,6 +961,12 @@ public VectorGeometry filterPointsOutsideBuffer(double buffer) {
}
}

/**
* Returns the hilbert index of the zig-zag-encoded first point of this feature.
* <p>
* This can be useful for sorting geometries to minimize encoded vector tile geometry command size since smaller
* offsets take fewer bytes using protobuf varint encoding.
*/
public int hilbertIndex() {
if (commands.length < 3) {
return 0;
Expand Down

0 comments on commit 8d80ba3

Please sign in to comment.