OpenKalman
Distance.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2018-2025 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_DISTANCE_HPP
17 #define OPENKALMAN_DISTANCE_HPP
18 
19 #include <cmath>
20 #include "values/functions/internal/update_real_part.hpp"
22 #include "Any.hpp"
23 
25 {
31  struct Distance {};
32 
33 
34 }
35 
36 
37 namespace OpenKalman::interface
38 {
43  template<>
44  struct coordinate_descriptor_traits<coordinates::Distance>
45  {
46  private:
47 
48  using T = coordinates::Distance;
49 
50  public:
51 
52  static constexpr bool is_specialized = true;
53 
54 
55  static constexpr auto dimension = [](const T&) { return std::integral_constant<std::size_t, 1>{}; };
56 
57 
58  static constexpr auto stat_dimension = [](const T&) { return std::integral_constant<std::size_t, 1>{}; };
59 
60 
61  static constexpr auto is_euclidean = [](const T&) { return std::false_type{}; };
62 
63 
64  static constexpr auto hash_code = [](const T&)
65  {
66  constexpr auto bits = std::numeric_limits<std::size_t>::digits;
67  if constexpr (bits < 32)
68  return std::integral_constant<std::size_t, 0xBD0A_uz>{};
69  else if constexpr (bits < 64)
70  return std::integral_constant<std::size_t, 0xBD0A6689_uz>{};
71  else
72  return std::integral_constant<std::size_t, 0xBD0A668977D34578_uz>{};
73  };
74 
75 
79  static constexpr auto
80  to_stat_space = [](const T&, auto&& data_view)
81  {
82  decltype(auto) d = collections::get<0>(std::forward<decltype(data_view)>(data_view));
83  // The distance component is wrapped to the non-negative half of the real axis:
84  return std::array {values::internal::update_real_part(std::forward<decltype(d)>(d), values::abs(values::real(d)))};
85  };
86 
87 
88  /*
89  * \brief This is effectively an identity function.
90  * \details This value should be positive, but this performs no bounds checking.
91  */
92  static constexpr auto
93  from_stat_space = [](const T&, auto&& data_view) -> decltype(auto)
94  {
95  return std::forward<decltype(data_view)>(data_view);
96  };
97 
98 
99  /*
100  * \brief Wraps the argument so that its real part is non-negative.
101  */
102  static constexpr auto
104 
105  };
106 
107 }
108 
109 
110 namespace std
111 {
112  template<>
113  struct common_type<OpenKalman::coordinates::Distance, OpenKalman::coordinates::Distance>
114  {
116  };
117 
118 
119  template<typename Scalar>
120  struct common_type<OpenKalman::coordinates::Distance, OpenKalman::coordinates::Any<Scalar>>
121  : common_type<OpenKalman::coordinates::Any<Scalar>, OpenKalman::coordinates::Distance> {};
122 
123 
124  template<typename T>
125  struct common_type<OpenKalman::coordinates::Distance, T>
126  : std::conditional_t<
127  OpenKalman::coordinates::descriptor<T>,
128  OpenKalman::stdex::type_identity<OpenKalman::coordinates::Any<>>,
129  std::monostate> {};
130 }
131 
132 
133 #endif
Definition: basics.hpp:41
decltype(auto) constexpr to_stat_space(const T &t, R &&data_view)
Maps a range reflecting vector-space data to a corresponding range in a vector space for directional ...
Definition: to_stat_space.hpp:44
decltype(auto) constexpr wrap(const T &t, R &&data_view)
wraps a range reflecting vector-space data to its primary range.
Definition: wrap.hpp:59
A non-negative real or integral number, [0,∞], representing a distance.
Definition: Distance.hpp:31
The root namespace for OpenKalman.
Definition: basics.hpp:34
The namespace for features relating to coordinates::pattern object.
Definition: compares_with.hpp:25
Inclusion file for collections.
constexpr auto real(const Arg &arg)
A constexpr function to obtain the real part of a (complex) number.
Definition: real.hpp:40
Traits for coordinates::pattern objects.
Definition: coordinate_descriptor_traits.hpp:36
constexpr auto abs(const Arg &arg)
A constexpr alternative to std::abs.
Definition: abs.hpp:38
decltype(auto) constexpr from_stat_space(const T &t, R &&stat_data_view)
Maps a range in a vector space for directional-statistics back to a range reflecting vector-space dat...
Definition: from_stat_space.hpp:44
Definition: Any.hpp:42