12#include <unordered_set>
26 class Subpaving :
public std::list<IntervalVector>
30 Subpaving(std::initializer_list<IntervalVector> l)
33 assert_release(!this->empty());
36 Subpaving(
const std::list<IntervalVector>& l)
39 assert_release(!this->empty());
45 for(
const auto& bi : *
this)
50 std::list<IntervalVector> boxes()
const
56 std::list<IntervalVector> contour(
bool sort =
false)
const
58 if constexpr(std::is_same_v<PavingOut,P>)
59 return contour(PavingOut::outer_complem, sort);
61 else if constexpr(std::is_same_v<PavingInOut,P>)
62 return contour(PavingInOut::outer_complem, sort);
66 assert_release_constexpr(
false &&
67 "cannot find a default complementary \"node value\" function for such Subaving class");
72 std::list<IntervalVector> contour(
const P::NodeValue_& node_complementary_value =
nullptr,
bool sort =
false)
const
74 std::list<IntervalVector> l_bound;
76 for(
const auto& xi : *
this)
78 auto x_boxes = _node_value(xi);
79 auto neighb_nodes = this->front()->paving().neighbours(xi, _node_value, node_complementary_value);
80 std::list<IntervalVector> neighb_boxes;
82 for(
const auto& neighb_ni : neighb_nodes)
83 neighb_boxes.splice(neighb_boxes.end(), node_complementary_value(neighb_ni));
85 for(
const auto& x_bi : x_boxes)
86 for(
const auto& neighb_bi : neighb_boxes)
88 auto inter = x_bi & neighb_bi;
89 if(!inter.is_empty() && !inter.is_degenerated())
90 l_bound.push_back(inter);
95 remove_duplicates_from_list(l_bound);
97 assert([&]() ->
bool {
for(
const auto& bi : l_bound) {
if(!bi.is_flat())
return false; }
return true; } ()
98 &&
"boundary boxes should be flat");
99 return sort ? sort_contour(l_bound) : l_bound;
102 static Vector next_pt(
const IntervalVector& x,
const Vector& pt)
104 assert(!x.is_degenerated());
105 assert(x.size() == 2 && pt.size() == 2);
107 assert(x.lb() == pt || x.ub() == pt);
108 return pt == x.lb() ? x.ub() : x.lb();
111 std::list<IntervalVector> sort_contour(std::list<IntervalVector> l)
const
113 assert_release(!l.empty());
114 assert_release(l.front().size() == 2 &&
"only 2d contours can be sorted");
116 const Index nl = l.size();
118 Vector current_pt = l.front().ub(), first_pt = current_pt;
119 std::list<IntervalVector> s { l.front() };
124 std::list<IntervalVector>::iterator it = l.begin();
127 if(it->contains(current_pt))
130 current_pt = Subpaving<P>::next_pt(*it, current_pt);
139 if(current_pt == first_pt)
143 assert(nl == s.size());
149 using SubpavingOut = Subpaving<PavingOut>;
150 using SubpavingInOut = Subpaving<PavingInOut>;
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25
Eigen::Matrix< double,-1, 1 > Vector
Alias for a dynamically-sized column vector of doubles.
Definition codac2_Vector.h:24