Skip to content
Snippets Groups Projects
Commit f3049018 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

a working version with formal refinement loop

parent f6f1194b
No related branches found
No related tags found
No related merge requests found
......@@ -294,6 +294,8 @@ int plot_curve_refine(CPlot* plot, const COlc* fc, int k, int j, int cstyle)
}
return ret;
};
auto pt_order = [](const CPt a, const CPt b) -> bool { return a.xd<=b.xd; };
vector<CPt> pp;
// start with equidistant grid:
......@@ -305,6 +307,7 @@ int plot_curve_refine(CPlot* plot, const COlc* fc, int k, int j, int cstyle)
// refinement loop:
for (int iref=0; iref<20; ++iref) {
vector<CPt> pnew = x2p(xnew);
pp = triv::merge_sorted(pp, pnew, pt_order);
}
// divide into segments, and plot
......
......@@ -25,9 +25,8 @@ namespace triv
std::string indices_to_s(const std::vector<int>& v);
template <class T> bool contains(const std::vector<T>& v, const T e);
template <class T> std::vector<T> merge_sorted(
const std::vector<T>& a, const std::vector<T>& b,
std::function<bool(const T, const T)> a_before_b);
template <class T, class Pred> std::vector<T> merge_sorted(
const std::vector<T>& a, const std::vector<T>& b, Pred a_before_b);
//**************************************************************************************************
// Template implementation
......@@ -38,16 +37,18 @@ namespace triv
return std::find(v.begin(), v.end(), e) != v.end();
}
template <class T>
std::vector<T> merge_sorted(
const std::vector<T>& a, const std::vector<T>& b,
std::function<bool(const T, const T)> a_before_b)
template <class T, class Pred>
std::vector<T> merge_sorted(const std::vector<T>& a, const std::vector<T>& b, Pred a_before_b)
{
std::vector<T> ret;
auto ia=a.begin();
auto ib=b.begin();
for (;;ia!=a.end() || ib!=ib.end())
for (;ia!=a.end() && ib!=b.end();)
ret.push_back( a_before_b(*ia,*ib) ? *(ia++) : *(ib++) );
for (;ia!=a.end();)
ret.push_back( *(ia++) );
for (;ib!=b.end();)
ret.push_back( *(ib++) );
return ret;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment