19 map.
data().size() <= size_t(std::numeric_limits<int>::max()) &&
21 std::all_of(map.
data().begin(), map.
data().end(), [](
float v) { return std::isfinite(v); });
33 return std::isfinite(
value) && std::abs(
value) <= std::numeric_limits<float>::max();
39 const double x = std::clamp(
u * map.
getWidth() - 0.5, 0.0,
double(map.
getWidth() - 1));
41 const int x0 = int(
x), z0 = int(
z), x1 = std::min(x0 + 1, map.
getWidth() - 1),
42 z1 = std::min(z0 + 1, map.
getHeight() - 1);
44 return std::lerp(std::lerp(
double(map.
height(x0, z0)),
double(map.
height(x1, z0)),
x - x0),
46 std::lerp(
double(map.
height(x0, z1)),
double(map.
height(x1, z1)),
x - x0),
z - z0);
53 const int x0 = int(
x), y0 = int(
y);
54 const int x1 = std::min(x0 + 1, map.
getWidth() - 1), y1 = std::min(y0 + 1, map.
getHeight() - 1);
55 const double top = std::lerp(
double(map.
height(x0, y0)),
double(map.
height(x1, y0)),
x - x0);
56 const double bottom = std::lerp(
double(map.
height(x0, y1)),
double(map.
height(x1, y1)),
x - x0);
64 for (
size_t i = 0; i < candidate.size(); ++i) changed += candidate[i] !=
target.data()[i];
65 target.data().swap(candidate);
73 const double pixel = std::clamp(
value *
curve.getWidth() - 0.5, 0.0,
double(
curve.getWidth() - 1));
Move-only, checked operation results for the common layer.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
In-memory terrain heightmap: a dense float grid (row-major, index = y * width + x) materialized from ...
int getHeight() const
Returns the height.
const std::vector< float > & data() const
Data.
float height(int x, int y) const
Height.
int getWidth() const
Returns the width.
double textureSample(const Heightmap &map, double u, double v)
Texture sample.
double curveSample(const Heightmap &curve, double value)
Curve sample.
double sample(const Heightmap &map, double u, double v)
Sample.
Result< int > publish(Heightmap &target, std::vector< float > candidate)
Publish.
bool validRaster(const Heightmap &map)
Valid raster.
Result< int > invalid(std::string message)
Invalid.
bool isRepresentable(double value)
True when representable.