Lodestar
An integrated real-time control package in C++
SetComplement.hpp
1 //
2 // Created by Hamza El-Kebir on 6/24/21.
3 //
4 
5 #ifndef LODESTAR_SETCOMPLEMENT_HPP
6 #define LODESTAR_SETCOMPLEMENT_HPP
7 
8 #include "SetExpression.hpp"
9 #include <type_traits>
10 #include <algorithm>
11 
12 namespace ls {
13  namespace primitives {
14  namespace sets {
27  template<typename TTypeLeft, typename TTypeRight>
28  class SetComplement : public SetExpression<SetComplement<TTypeLeft, TTypeRight>> {
29  public:
31 
32  using ltype = TTypeLeft;
33  using rtype = TTypeRight;
35 
50  SetComplement(const TTypeLeft &left, const TTypeRight &right, bool empty = false) : left_(left),
51  right_(right),
52  empty_(empty)
53  {
54 // if (std::is_same<TTypeLeft, TTypeRight>::value)
55 // Base::sEnum_ = static_cast<TTypeLeft const &>(left).getEnum();
56 // else
57  this->sEnum_ = SetEnum::Complement;
58  }
59 
65  bool isEmpty() const
66  {
67  return empty_;
68  }
69 
79  template<typename TElementType>
80  bool contains(const TElementType &el) const
81  {
82  return left_.contains(el) && (!right_.contains(el));
83  }
84 
94  template<typename TExpression>
96  {
97  return SetUnion<type, TExpression>(*this, *static_cast<const TExpression *>(&expr));
98  }
99 
120  template<typename TDerived>
121  double sdf(Eigen::MatrixBase<TDerived> &p) const
122  {
123  if (isEmpty())
124  return std::numeric_limits<double>::infinity();
125  else
126  return -std::min(-left_.sdf(p), right_.sdf(p));
127  }
128 
129 // template<typename TLeft, typename TRight>
130 // SetUnion<TLeft, TRight> unionize(const TLeft &left, const TRight &right) const
131 // {
132 // return SetUnion<TLeft, TRight>(left, right);
133 // }
134 
140  const TTypeLeft &getLeft() const
141  {
142  return left_;
143  }
144 
150  const TTypeRight &getRight() const
151  {
152  return right_;
153  }
154 
155  protected:
156  const TTypeLeft &left_;
157  const TTypeRight &right_;
158  bool empty_;
159  };
160  }
161  }
162 }
163 
164 #endif //LODESTAR_SETCOMPLEMENT_HPP
ls::primitives::sets::SetComplement::getLeft
const TTypeLeft & getLeft() const
Gets the left expression.
Definition: SetComplement.hpp:140
ls::primitives::sets::SetExpression
Definition: SetExpression.hpp:15
ls::primitives::sets::SetComplement::contains
bool contains(const TElementType &el) const
Returns true if this expression contains el.
Definition: SetComplement.hpp:80
ls::primitives::sets::SetComplement
Relative complement of two SetExpressions.
Definition: SetComplement.hpp:28
ls
Main Lodestar code.
Definition: BilinearTransformation.hpp:12
ls::primitives::sets::SetComplement::getRight
const TTypeRight & getRight() const
Gets the right expression.
Definition: SetComplement.hpp:150
ls::primitives::sets::SetComplement::sdf
double sdf(Eigen::MatrixBase< TDerived > &p) const
Returns signed distance to p.
Definition: SetComplement.hpp:121
ls::primitives::sets::SetComplement::rtype
TTypeRight rtype
Left type.
Definition: SetComplement.hpp:33
ls::primitives::sets::SetComplement::right_
const TTypeRight & right_
Left constant reference.
Definition: SetComplement.hpp:157
ls::primitives::sets::SetUnion
Union of two SetExpressions.
Definition: SetUnion.hpp:28
ls::primitives::sets::SetComplement::ltype
TTypeLeft ltype
Base class.
Definition: SetComplement.hpp:32
ls::primitives::sets::SetComplement::unionize
SetUnion< type, TExpression > unionize(const SetExpression< TExpression > &expr)
Creates a union between this expression and another SetExpression.
Definition: SetComplement.hpp:95
ls::primitives::sets::SetComplement::SetComplement
SetComplement(const TTypeLeft &left, const TTypeRight &right, bool empty=false)
Expression type.
Definition: SetComplement.hpp:50
ls::primitives::sets::SetComplement::isEmpty
bool isEmpty() const
Returns true if the expression is the empty set.
Definition: SetComplement.hpp:65
ls::primitives::sets::SetComplement::empty_
bool empty_
Right constant reference.
Definition: SetComplement.hpp:158