@@ -382,7 +382,7 @@ class PlotDataBase
382382 }
383383
384384
385- void mergeWith (PlotDataBase<TypeX, Value>& other) {
385+ virtual void mergeWith (PlotDataBase<TypeX, Value>& other) {
386386 if (other._points .empty ())
387387 return ;
388388
@@ -405,17 +405,16 @@ class PlotDataBase
405405 }
406406
407407 if constexpr (std::is_arithmetic_v<TypeX>) {
408+ // new points are all before this->_points
409+ if (other._points .back ().x < this ->_points .front ().x ) {
410+ this ->_points .swap (other._points );
411+ }
408412
409413 // new points are all after this->_points
410414 if (other._points .front ().x > this ->_points .back ().x ) {
411415 std::move (other._points .begin (), other._points .end (), std::back_inserter (this ->_points ));
412-
413- // new points are all before this->_points
414- } else if (other._points .back ().x < this ->_points .front ().x ) {
415- std::move (this ->_points .begin (), this ->_points .end (), std::back_inserter (other._points ));
416- this ->_points .swap (other._points );
417416 } else {
418- // Fallback to standard merging with move where possible
417+ // Overlap: fallback to standard merging with move where possible
419418 std::deque<Point> result;
420419 std::merge (std::make_move_iterator (this ->_points .begin ()), std::make_move_iterator (this ->_points .end ()),
421420 std::make_move_iterator (other._points .begin ()), std::make_move_iterator (other._points .end ()),
0 commit comments