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) ...@@ -294,6 +294,8 @@ int plot_curve_refine(CPlot* plot, const COlc* fc, int k, int j, int cstyle)
} }
return ret; return ret;
}; };
auto pt_order = [](const CPt a, const CPt b) -> bool { return a.xd<=b.xd; };
vector<CPt> pp; vector<CPt> pp;
// start with equidistant grid: // start with equidistant grid:
...@@ -305,6 +307,7 @@ int plot_curve_refine(CPlot* plot, const COlc* fc, int k, int j, int cstyle) ...@@ -305,6 +307,7 @@ int plot_curve_refine(CPlot* plot, const COlc* fc, int k, int j, int cstyle)
// refinement loop: // refinement loop:
for (int iref=0; iref<20; ++iref) { for (int iref=0; iref<20; ++iref) {
vector<CPt> pnew = x2p(xnew); vector<CPt> pnew = x2p(xnew);
pp = triv::merge_sorted(pp, pnew, pt_order);
} }
// divide into segments, and plot // divide into segments, and plot
......
...@@ -25,9 +25,8 @@ namespace triv ...@@ -25,9 +25,8 @@ namespace triv
std::string indices_to_s(const std::vector<int>& v); 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> bool contains(const std::vector<T>& v, const T e);
template <class T> std::vector<T> merge_sorted( template <class T, class Pred> std::vector<T> merge_sorted(
const std::vector<T>& a, const std::vector<T>& b, const std::vector<T>& a, const std::vector<T>& b, Pred a_before_b);
std::function<bool(const T, const T)> a_before_b);
//************************************************************************************************** //**************************************************************************************************
// Template implementation // Template implementation
...@@ -38,16 +37,18 @@ namespace triv ...@@ -38,16 +37,18 @@ namespace triv
return std::find(v.begin(), v.end(), e) != v.end(); return std::find(v.begin(), v.end(), e) != v.end();
} }
template <class T> template <class T, class Pred>
std::vector<T> merge_sorted( std::vector<T> merge_sorted(const std::vector<T>& a, const std::vector<T>& b, Pred a_before_b)
const std::vector<T>& a, const std::vector<T>& b,
std::function<bool(const T, const T)> a_before_b)
{ {
std::vector<T> ret; std::vector<T> ret;
auto ia=a.begin(); auto ia=a.begin();
auto ib=b.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++) ); 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; 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