Line data Source code
1 : // SPDX-License-Identifier: BSD-3-Clause 2 : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 3 : /// @file 4 : /// @author Owen Arnold 5 : #pragma once 6 : 7 : #include "scipp/common/overloaded.h" 8 : #include "scipp/core/eigen.h" 9 : #include "scipp/core/element/arg_list.h" 10 : #include "scipp/core/transform_common.h" 11 : 12 : /// Operators to be used with transform and transform_in_place to implement 13 : /// geometric operations for Variable. 14 : namespace scipp::core::element::geometry { 15 : 16 : constexpr auto position = overloaded{ 17 : arg_list<double>, 18 : transform_flags::expect_no_variance_arg<0>, 19 : transform_flags::expect_no_variance_arg<1>, 20 : transform_flags::expect_no_variance_arg<2>, 21 17 : [](const auto &x, const auto &y, const auto &z) { 22 : using T = double; // currently only double precision support 23 17 : return Eigen::Matrix<T, 3, 1>(x, y, z); 24 : }, 25 11 : [](const units::Unit &x, const units::Unit &y, const units::Unit &z) { 26 15 : expect::equals(x, y); 27 10 : expect::equals(x, z); 28 8 : return x; 29 : }}; 30 : 31 : namespace detail { 32 : template <int N> 33 : static constexpr auto component = 34 : overloaded{arg_list<Eigen::Vector3d>, 35 : [](const auto &pos) { return pos[N]; }, 36 : [](const units::Unit &u) { return u; }}; 37 : } // namespace detail 38 : constexpr auto x = detail::component<0>; 39 : constexpr auto y = detail::component<1>; 40 : constexpr auto z = detail::component<2>; 41 : 42 : } // namespace scipp::core::element::geometry