From 14320632fbf39237b5f2254ec1d312ce3c12d879 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 20 Mar 2026 18:33:31 +0100 Subject: Wanted to finish n linearity today, but I guess I should be happy with this --- lib/core/c++/math/n_linear.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/core/c++') diff --git a/lib/core/c++/math/n_linear.hpp b/lib/core/c++/math/n_linear.hpp index ac02da8..8fb0600 100644 --- a/lib/core/c++/math/n_linear.hpp +++ b/lib/core/c++/math/n_linear.hpp @@ -43,6 +43,25 @@ auto floor_index_from_position(const saw::data>& pos){ return position_to_index_and_fraction(pos).template get<0u>(); } +template +saw::data,sch::Vector>> position_to_index_and_fraction_bounded( + const saw::data>& pos, + const saw::data>& bound) +{ + auto infr = position_to_index_and_fraction(pos); + auto& ind = infr.template get<0u>(); + auto& fra = infr.template get<1u>(); + for(uint64_t i = 0u; i < D; ++i){ + // If index is higher than bound. Set to bound and reset fraction + if((ind.at({{i}}).get()+1u) >= bound.at({{i}}).get()){ + ind.at({{i}}).set(bound.at({{i}}).get()-1u); + fra.at({{i}}) = {}; + } + } + return infr; +} + + template auto n_linear_interpolate( const saw::data& field, const saw::data>& pos){ -- cgit v1.2.3