From f3049018c111f918dde9652a6b5c460e263ab9fc Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Wed, 8 Mar 2017 15:49:43 +0100 Subject: [PATCH] a working version with formal refinement loop --- pub/lib/plot.cpp | 3 +++ pub/trivia/vector_ops.hpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pub/lib/plot.cpp b/pub/lib/plot.cpp index a7161cca..cbf04327 100644 --- a/pub/lib/plot.cpp +++ b/pub/lib/plot.cpp @@ -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 diff --git a/pub/trivia/vector_ops.hpp b/pub/trivia/vector_ops.hpp index da19ecfc..894f6b4b 100644 --- a/pub/trivia/vector_ops.hpp +++ b/pub/trivia/vector_ops.hpp @@ -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; } } -- GitLab