OpenKalman
is_uniform_pattern_component_of.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) 2020-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_IS_UNIFORM_COMPONENT_OF_HPP
17 #define OPENKALMAN_IS_UNIFORM_COMPONENT_OF_HPP
18 
26 
28 {
35 #ifdef __cpp_concepts
36  template<pattern A, pattern B>
37  constexpr OpenKalman::internal::boolean_testable auto
38 #else
39  template<typename A, typename B, std::enable_if_t<pattern<A> and pattern<B>, int> = 0>
40  constexpr auto
41 #endif
42  is_uniform_pattern_component_of(const A& a, const B& b)
43  {
44  if constexpr (not uniform_pattern<B, applicability::permitted>)
45  {
46  return std::false_type {};
47  }
48  else if constexpr (euclidean_pattern<B>)
49  {
50  return compare(a, Dimensions<1>{});;
51  }
52  else
53  {
54  using C = common_descriptor_type_t<B>;
55  if constexpr (compares_with<A, C, &stdex::is_eq, applicability::guaranteed>)
56  {
57  return values::operation(std::equal_to{}, get_dimension(a), std::integral_constant<std::size_t, 1>{});
58  }
59  else if constexpr (compares_with<A, C, &stdex::is_neq, applicability::guaranteed> or
60  (dimension_of_v<C> != stdex::dynamic_extent and dimension_of_v<C> != 1))
61  {
62  return std::false_type {};
63  }
64  else if (get_dimension(a) != 1)
65  {
66  return false;
67  }
68  else if (get_is_euclidean(b))
69  {
70  return get_is_euclidean(a);
71  }
72  else
73  {
74  if constexpr (descriptor<B>)
75  {
76  return compare(a, b);
77  }
78  else
79  {
80  for (const auto& x : collections::views::all(b))
81  {
82  if (get_dimension(x) == 0) continue;
83  if (get_is_euclidean(x) and get_is_euclidean(a)) continue;
84  if (not compare(a, x)) return false;
85  }
86  return true;
87  }
88  }
89  }
90  }
91 
92 }
93 
94 #endif
Definition for compares_with.
constexpr auto compare(const A &a, const B &b)
Compare two coordinates::pattern objects lexicographically.
Definition: compare.hpp:40
Definition for uniform_pattern_type.
Definition for coordinates::pattern.
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg.
Definition: get_dimension.hpp:54
Definition of coordinates::compare.
constexpr auto get_is_euclidean(const Arg &arg)
Determine, whether coordinates::pattern Arg is euclidean.
Definition: get_is_euclidean.hpp:65
The namespace for features relating to coordinates::pattern object.
Definition: compares_with.hpp:25
constexpr detail::all_closure all
a std::ranges::range_adaptor_closure which returns a view to all members of its collection argument...
Definition: all.hpp:72
Inclusion file for collections.
Definition for uniform_pattern.
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98