diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-03-02 17:28:48 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-03-02 17:28:48 +0100 |
| commit | e9624b172bc5946a25847dc71f16f1a684892708 (patch) | |
| tree | 4e98f4dce364a205a9cb75f3b38a3a945c8a8616 /modules/codec/c++/math.hpp | |
| parent | 90f0b055c093d8194d219d49f082c47544cec770 (diff) | |
| download | forstio-forstio-e9624b172bc5946a25847dc71f16f1a684892708.tar.gz | |
Added rotation, scale and sqrt
Diffstat (limited to 'modules/codec/c++/math.hpp')
| -rw-r--r-- | modules/codec/c++/math.hpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/codec/c++/math.hpp b/modules/codec/c++/math.hpp index a227b46..34c64c7 100644 --- a/modules/codec/c++/math.hpp +++ b/modules/codec/c++/math.hpp @@ -107,5 +107,47 @@ data<schema::Scalar<T>,Encoding> cross( return cross_prod; } + +template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> +data<schema::Scalar<T>,Encoding> cos( + const data<schema::Scalar<T>,Encoding>& val +){ + data<schema::Scalar<T>,Encoding> ret; + ret.at({}).set(std::cos(val.at({}).get())); + return ret; +} + +template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> +data<schema::Scalar<T>,Encoding> sin( + const data<schema::Scalar<T>,Encoding>& val +){ + data<schema::Scalar<T>,Encoding> ret; + ret.at({}).set(std::sin(val.at({}).get())); + return ret; +} + + +template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> +data<schema::Vector<T,2u>,Encoding> rotate( + const data<schema::Vector<T,2u>, Encoding> vec, + const data<schema::Scalar<T>, Encoding> rot +){ + data<schema::Vector<T,2u>, Encoding> rot_vec; + rot_vec.at({{0u}}) = vec.at({{0u}}) * cos(rot); + rot_vec.at({{1u}}) = vec.at({{1u}}) * sin(rot); + return rot_vec; +} + +template<typename T, uint64_t D, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> +data<schema::Vector<T,D>,Encoding> scale( + const data<schema::Vector<T,D>, Encoding> vec, + const data<schema::Scalar<T>, Encoding> scale +){ + data<schema::Vector<T,D>, Encoding> sc_vec; + for(uint64_t i = 0u; i< D; ++i){ + sc_vec.at({{i}}) = vec.at({{i}}) * scale; + } + return sc_vec; +} } } |
