kopia lustrzana https://github.com/onthegomap/planetiler
Math.clamp
rodzic
b108f88453
commit
e461fcd3fd
|
@ -95,7 +95,7 @@ class ArrayLongLongMapMmap implements LongLongMap.ParallelWrites {
|
|||
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() {
|
||||
|
|
|
@ -416,7 +416,7 @@ public class GeoUtils {
|
|||
/** 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);
|
||||
|
|
|
@ -21,11 +21,11 @@ public class TileExtents implements Predicate<TileCoord> {
|
|||
}
|
||||
|
||||
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). */
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.onthegomap.planetiler.collection.FeatureGroup;
|
|||
* To sort by a field descending, specify its range from high to low.
|
||||
* <p>
|
||||
* For example this SQL ordering:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* ORDER BY rank ASC,
|
||||
|
@ -23,7 +23,7 @@ import com.onthegomap.planetiler.collection.FeatureGroup;
|
|||
* </pre>
|
||||
* <p>
|
||||
* would become:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* {@code
|
||||
* feature.setSortKey(
|
||||
|
@ -125,7 +125,7 @@ public class SortKey {
|
|||
}
|
||||
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 class SortKey {
|
|||
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 class SortKey {
|
|||
}
|
||||
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);
|
||||
|
|
Ładowanie…
Reference in New Issue