clamp static method
Rescale the heightmap of a terrain to keep it within the maximum range.
Float32List g
The geometry's z-positions to modify with heightmap data.
TerrainOptions options
A map of settings that control how the terrain is constructed and
displayed. Valid values are the same as those for the options parameter
of {@link THREE.Terrain}() but only maxHeight, minHeight, and easing
are used.
Implementation
static void clamp(Float32List g, TerrainOptions options) {
double min = double.infinity,
max = -double.infinity;
int l = g.length;
options.easing = options.easing;
for (int i = 0; i < l; i++) {
if (g[i] < min) min = g[i];
if (g[i] > max) max = g[i];
}
double actualRange = max - min,
optMax = options.maxHeight ?? max,
optMin = options.minHeight ?? min,
targetMax = options.stretch ? optMax : (max < optMax ? max : optMax),
targetMin = options.stretch ? optMin : (min > optMin ? min : optMin),
range = targetMax - targetMin;
if (targetMax < targetMin) {
targetMax = optMax;
range = targetMax - targetMin;
}
for (int i = 0; i < l; i++) {
g[i] = options.easing.call((g[i] - min) / actualRange)*range + optMin;
}
}