codac 2.0.0
Loading...
Searching...
No Matches
codac2_CtcInter.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <type_traits>
13#include "codac2_CtcWrapper.h"
14#include "codac2_Collection.h"
16
17namespace codac2
18{
19 template<typename... X>
20 class CtcInter : public Ctc<CtcInter<X...>,X...>
21 {
22 public:
23
24 explicit CtcInter(Index n)
25 : Ctc<CtcInter<X...>,X...>(n)
26 {
27 if constexpr(std::is_same_v<X...,Interval>)
28 {
29 assert(n == 1);
30 }
31 }
32
33 template<typename C>
34 requires (IsCtcBaseOrPtr<C,X...> && !std::is_same_v<CtcInter<X...>,C>)
35 CtcInter(const C& c)
36 : Ctc<CtcInter<X...>,X...>(size_of(c)), _ctcs(c)
37 { }
38
39 template<typename... C>
40 requires (IsCtcBaseOrPtr<C,X...> && ...)
41 CtcInter(const C&... c)
42 : Ctc<CtcInter<X...>,X...>(size_first_item(c...)), _ctcs(c...)
43 {
44 assert_release(all_same_size(c...));
45 }
46
47 size_t nb() const
48 {
49 return _ctcs.size();
50 }
51
52 template<typename X_> // single type
53 void contract_impl(X_& x) const
54 {
55 for(const auto& ci : _ctcs)
56 {
57 ci->contract(x);
58 if(x.is_empty())
59 return;
60 }
61 }
62
63 void contract(X&... x) const
64 {
65 // contract_impl(..) method for multiple types is not yet implemented
66 contract_impl(x...);
67 }
68
69 template<typename C>
70 requires IsCtcBaseOrPtr<C,X...>
71 CtcInter<X...>& operator&=(const C& c)
72 {
73 assert_release(size_of(c) == this->size());
74 _ctcs.push_back(c);
75 return *this;
76 }
77
78 protected:
79
80 Collection<CtcBase<X...>> _ctcs;
81 };
82
83 template <>
84 class CtcInter<> : public CtcInter<IntervalVector>
85 { };
86
87 template<typename Tuple>
88 struct CtcInterType;
89
90 template<typename... T>
91 struct CtcInterType<std::tuple<T...>> {
92 using Ctc = CtcInter<T...>;
93 };
94
95 template<typename C1,typename C2>
96 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const C1& c1, const C2& c2)
97 {
98 return { c1, c2 };
99 }
100
101 template<typename C1,typename C2>
102 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const std::shared_ptr<C2>& c2)
103 {
104 return { c1, c2 };
105 }
106
107 template<typename C1,typename C2>
108 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const C2& c2)
109 {
110 return { c1, c2 };
111 }
112
113 template<typename C1,typename C2>
114 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const C1& c1, const std::shared_ptr<C2>& c2)
115 {
116 return { c1, c2 };
117 }
118
119 template<typename C2>
120 requires std::is_base_of_v<CtcBase<IntervalVector>,C2>
121 inline CtcInter<IntervalVector> operator&(const IntervalVector& c1, const C2& c2)
122 {
123 assert_release(c1.size() == c2.size());
124 return CtcInter<IntervalVector>(CtcWrapper(c1),c2);
125 }
126
127 template<typename C1>
128 requires std::is_base_of_v<CtcBase<IntervalVector>,C1>
129 inline CtcInter<IntervalVector> operator&(const C1& c1, const IntervalVector& c2)
130 {
131 assert_release(c1.size() == c2.size());
132 return CtcInter<IntervalVector>(c1,CtcWrapper(c2));
133 }
134
135 // Template deduction guides
136 CtcInter(Index) -> CtcInter<IntervalVector>;
137}
Definition codac2_OctaSym.h:21
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25