summaryrefslogtreecommitdiff
path: root/lib/core/c++/math/n_linear.hpp
blob: 62906cd10832c4e07b728627d8e04cde34bc3b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once

#include "../common.hpp"

namespace kel {
namespace lbm {

template<typename FieldSchema, typename T, uint64_t D>
void n_linear_interpolate(const saw::data<FieldSchema>& field, const saw::data<sch::FixedArray<T,D>>& pos){

	auto pos_bound = pos;
	auto meta = field.dims();
	saw::data<sch::UInt64> ind;
	for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{D}; ++i){
		pos_bound.at(i).set(
			std::max(
				std::min(
					meta.at(i).template cast_to<T>().get(),
					pos.at(i).get() + 1.5
				),
				1,
			)
			-1
		);
		ind.at(i) = pos_bound.at(i).template cast_to<sch::UInt64>();
	}
}
}
}