Lodestar
An integrated real-time control package in C++
SetUnion.hpp
1 //
2 // Created by Hamza El-Kebir on 6/21/21.
3 //
4 
5 #ifndef LODESTAR_SETUNION_HPP
6 #define LODESTAR_SETUNION_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 SetUnion : public SetExpression<SetUnion<TTypeLeft, TTypeRight>> {
29  public:
31 
32  using ltype = TTypeLeft;
33  using rtype = TTypeRight;
35 
50  SetUnion(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::Union;
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 TOtherExpr>
96  {
97  return SetUnion<type, TOtherExpr>(*this, *static_cast<const TOtherExpr *>(&expr),
98  isEmpty() && expr.isEmpty());
99  }
100 
110  template<typename Derived>
111  double sdf(Eigen::MatrixBase<Derived> &p) const
112  {
113  if (isEmpty())
114  return std::numeric_limits<double>::infinity();
115  else
116  return std::min(left_.sdf(p), right_.sdf(p));
117  }
118 
124  const TTypeLeft &getLeft() const
125  {
126  return left_;
127  }
128 
134  const TTypeRight &getRight() const
135  {
136  return right_;
137  }
138 
139  protected:
140  const TTypeLeft &left_;
141  const TTypeRight &right_;
142  bool empty_;
143  };
144  }
145  }
146 }
147 
148 #endif //LODESTAR_SETUNION_HPP
ls::primitives::sets::SetUnion::getRight
const TTypeRight & getRight() const
Gets the right expression.
Definition: SetUnion.hpp:134
ls::primitives::sets::SetUnion::isEmpty
bool isEmpty() const
Returns true if the expression is the empty set.
Definition: SetUnion.hpp:65
ls::primitives::sets::SetExpression
Definition: SetExpression.hpp:15
ls::primitives::sets::SetUnion::right_
const TTypeRight & right_
Left constant reference.
Definition: SetUnion.hpp:141
ls
Main Lodestar code.
Definition: BilinearTransformation.hpp:12
ls::primitives::sets::SetUnion::unionize
SetUnion< type, TOtherExpr > unionize(const SetExpression< TOtherExpr > &expr)
Creates a union between this expression and another SetExpression.
Definition: SetUnion.hpp:95
ls::primitives::sets::SetUnion::ltype
TTypeLeft ltype
Base class.
Definition: SetUnion.hpp:32
ls::primitives::sets::SetUnion::sdf
double sdf(Eigen::MatrixBase< Derived > &p) const
Returns signed distance to p.
Definition: SetUnion.hpp:111
ls::primitives::sets::SetUnion
Union of two SetExpressions.
Definition: SetUnion.hpp:28
ls::primitives::sets::SetUnion::getLeft
const TTypeLeft & getLeft() const
Gets the left expression.
Definition: SetUnion.hpp:124
ls::primitives::sets::SetUnion::SetUnion
SetUnion(const TTypeLeft &left, const TTypeRight &right, bool empty=false)
Expression type.
Definition: SetUnion.hpp:50
ls::primitives::sets::SetUnion::rtype
TTypeRight rtype
Left type.
Definition: SetUnion.hpp:33
ls::primitives::sets::SetUnion::empty_
bool empty_
Right constant reference.
Definition: SetUnion.hpp:142
ls::primitives::sets::SetUnion::contains
bool contains(const TElementType &el) const
Returns true if this expression contains el.
Definition: SetUnion.hpp:80