`interpolate_baked` was renamed `sample_baked`

master
Marc Gilleron 2022-09-01 01:32:21 +01:00
parent 45d57bd0e5
commit d323b54270
4 changed files with 16 additions and 17 deletions

View File

@ -11,12 +11,12 @@ using namespace math;
void get_curve_monotonic_sections(Curve &curve, std::vector<CurveMonotonicSection> &sections) {
const int res = curve.get_bake_resolution();
float prev_y = curve.interpolate_baked(0.f);
float prev_y = curve.sample_baked(0.f);
sections.clear();
CurveMonotonicSection section;
section.x_min = 0.f;
section.y_min = curve.interpolate_baked(0.f);
section.y_min = curve.sample_baked(0.f);
float prev_x = 0.f;
bool current_stationary = true;
@ -24,7 +24,7 @@ void get_curve_monotonic_sections(Curve &curve, std::vector<CurveMonotonicSectio
for (int i = 1; i < res; ++i) {
const float x = static_cast<float>(i) / res;
const float y = curve.interpolate_baked(x);
const float y = curve.sample_baked(x);
// Curve can sometimes appear flat but it still oscillates by very small amounts due to float imprecision
// which occurred during bake(). Attempting to workaround that by taking the error into account
const bool increasing = y > prev_y + CURVE_RANGE_MARGIN;
@ -65,21 +65,21 @@ Interval get_curve_range(Curve &curve, const std::vector<CurveMonotonicSection>
unsigned int i = 0;
if (x.min < sections[0].x_min) {
// X range starts before the curve's minimum X
y = Interval::from_single_value(curve.interpolate_baked(0.f));
y = Interval::from_single_value(curve.sample_baked(0.f));
} else {
// Find section from where the range starts
for (; i < sections.size(); ++i) {
const CurveMonotonicSection &section = sections[i];
if (x.min >= section.x_min) {
const float begin_y = curve.interpolate_baked(x.min);
const float begin_y = curve.sample_baked(x.min);
if (x.max < section.x_max) {
// X range starts and ends in that section
return Interval::from_unordered_values(begin_y, curve.interpolate_baked(x.max))
return Interval::from_unordered_values(begin_y, curve.sample_baked(x.max))
.padded(CURVE_RANGE_MARGIN);
} else {
// X range starts in that section, and continues after it.
// Will need to keep iterating, starting from here
y = Interval::from_unordered_values(begin_y, curve.interpolate_baked(section.x_max));
y = Interval::from_unordered_values(begin_y, curve.sample_baked(section.x_max));
++i;
break;
}
@ -93,7 +93,7 @@ Interval get_curve_range(Curve &curve, const std::vector<CurveMonotonicSection>
y.add_interval(Interval::from_unordered_values(section.y_min, section.y_max));
} else {
// X range ends in that section
y.add_interval(Interval::from_unordered_values(section.y_min, curve.interpolate_baked(x.max)));
y.add_interval(Interval::from_unordered_values(section.y_min, curve.sample_baked(x.max)));
break;
}
}
@ -104,12 +104,12 @@ Interval get_curve_range(Curve &curve, bool &is_monotonic_increasing) {
// TODO Would be nice to have the cache directly
const int res = curve.get_bake_resolution();
Interval range;
float prev_v = curve.interpolate_baked(0.f);
if (curve.interpolate_baked(1.f) > prev_v) {
float prev_v = curve.sample_baked(0.f);
if (curve.sample_baked(1.f) > prev_v) {
is_monotonic_increasing = true;
}
for (int i = 0; i < res; ++i) {
const float v = curve.interpolate_baked(static_cast<float>(i) / res);
const float v = curve.sample_baked(static_cast<float>(i) / res);
range.add_point(v);
if (v < prev_v) {
is_monotonic_increasing = false;

View File

@ -1033,14 +1033,14 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
VoxelGraphRuntime::Buffer &out = ctx.get_output(0);
const Params p = ctx.get_params<Params>();
for (uint32_t i = 0; i < out.size; ++i) {
out.data[i] = p.curve->interpolate_baked(a.data[i]);
out.data[i] = p.curve->sample_baked(a.data[i]);
}
};
t.range_analysis_func = [](RangeAnalysisContext &ctx) {
const Interval a = ctx.get_input(0);
const Params p = ctx.get_params<Params>();
if (a.is_single_value()) {
const float v = p.curve->interpolate_baked(a.min);
const float v = p.curve->sample_baked(a.min);
ctx.set_output(0, Interval::from_single_value(v));
} else {
const Interval r = get_curve_range(*p.curve, p.curve_range_data->sections, a);

View File

@ -81,8 +81,7 @@ VoxelGenerator::Result VoxelGeneratorNoise2D::generate_block(VoxelGenerator::Vox
Curve &curve = **params.curve;
result = VoxelGeneratorHeightmap::generate(
out_buffer,
[&noise, &curve](
int x, int z) { return curve.interpolate_baked(0.5 + 0.5 * noise.get_noise_2d(x, z)); },
[&noise, &curve](int x, int z) { return curve.sample_baked(0.5 + 0.5 * noise.get_noise_2d(x, z)); },
input.origin_in_voxels, input.lod);
}
@ -114,7 +113,7 @@ void VoxelGeneratorNoise2D::generate_series(Span<const float> positions_x, Span<
Curve &curve = **params.curve;
generate_series_template(
[&noise, &curve](float x, float z) { //
return curve.interpolate_baked(0.5 + 0.5 * noise.get_noise_2d(x, z));
return curve.sample_baked(0.5 + 0.5 * noise.get_noise_2d(x, z));
},
positions_x, positions_y, positions_z, channel, out_values, min_pos, max_pos);
}

View File

@ -1190,7 +1190,7 @@ void test_get_curve_monotonic_sections() {
{
math::Interval xi(0.2f, 0.8f);
math::Interval yi = get_curve_range(**curve, sections, xi);
math::Interval yi_expected(curve->interpolate_baked(xi.min), curve->interpolate_baked(xi.max));
math::Interval yi_expected(curve->sample_baked(xi.min), curve->sample_baked(xi.max));
ZYLANN_TEST_ASSERT(L::is_equal_approx(yi.min, yi_expected.min));
ZYLANN_TEST_ASSERT(L::is_equal_approx(yi.max, yi_expected.max));
}