diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ArrayLongLongMapMmap.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ArrayLongLongMapMmap.java index e208248b25..17791e6ef8 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ArrayLongLongMapMmap.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/collection/ArrayLongLongMapMmap.java @@ -95,7 +95,7 @@ private static int guessPendingChunkLimit(long chunkSize) { int minChunks = 1; int maxChunks = (int) (MAX_BYTES_TO_USE / chunkSize); int targetChunks = (int) (ProcessInfo.getMaxMemoryBytes() * 0.5d / chunkSize); - return Math.min(maxChunks, Math.max(minChunks, targetChunks)); + return Math.clamp(targetChunks, minChunks, maxChunks); } public void init() { diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java index c71dbd6e68..35f32587e3 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java @@ -416,7 +416,7 @@ public static Geometry createGeometryCollection(List polygonGroup) { /** Returns a point approximately {@code ratio} of the way from start to end and {@code offset} units to the right. */ public static Point pointAlongOffset(LineString lineString, double ratio, double offset) { int numPoints = lineString.getNumPoints(); - int middle = Math.max(0, Math.min(numPoints - 2, (int) (numPoints * ratio))); + int middle = Math.clamp((int) (numPoints * ratio), 0, numPoints - 2); Coordinate a = lineString.getCoordinateN(middle); Coordinate b = lineString.getCoordinateN(middle + 1); LineSegment segment = new LineSegment(a, b); diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/TileExtents.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/TileExtents.java index f6313cf28d..911be3c76e 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/TileExtents.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/TileExtents.java @@ -21,11 +21,11 @@ private TileExtents(ForZoom[] zoomExtents) { } private static int quantizeDown(double value, int levels) { - return Math.max(0, Math.min(levels, (int) Math.floor(value * levels))); + return Math.clamp((int) Math.floor(value * levels), 0, levels); } private static int quantizeUp(double value, int levels) { - return Math.max(0, Math.min(levels, (int) Math.ceil(value * levels))); + return Math.clamp((int) Math.ceil(value * levels), 0, levels); } /** Returns a filter to tiles that intersect {@code worldBounds} (specified in world web mercator coordinates). */ diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/SortKey.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/SortKey.java index 3cb9a843cb..abdffdad7e 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/SortKey.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/SortKey.java @@ -13,7 +13,7 @@ * To sort by a field descending, specify its range from high to low. *

* For example this SQL ordering: - * + * *

  * {@code
  * ORDER BY rank ASC,
@@ -23,7 +23,7 @@
  * 
*

* would become: - * + * *

  * {@code
  * feature.setSortKey(
@@ -125,7 +125,7 @@ public SortKey thenByInt(int value, int start, int end) {
     }
     int levels = end + 1 - start;
     if (value < start || value > end) {
-      value = Math.max(start, Math.min(end, value));
+      value = Math.clamp(value, start, end);
     }
     return accumulate(value, start, levels);
   }
@@ -141,7 +141,7 @@ public SortKey thenByDouble(double value, double start, double end, int levels)
       return thenByDouble(start - value, end, start, levels);
     }
     if (value < start || value > end) {
-      value = Math.max(start, Math.min(end, value));
+      value = Math.clamp(value, start, end);
     }
 
     int intVal = doubleRangeToInt(value, start, end, levels);
@@ -160,7 +160,7 @@ public SortKey thenByLog(double value, double start, double end, int levels) {
     }
     assert start > 0 : "log thresholds must be > 0 got [" + start + ", " + end + "]";
     if (value < start || value > end) {
-      value = Math.max(start, Math.min(end, value));
+      value = Math.clamp(value, start, end);
     }
 
     int intVal = doubleRangeToInt(Math.log(value), Math.log(start), Math.log(end), levels);