@@ -373,7 +373,7 @@ class PlotDataBase
373373 }
374374
375375
376- void mergeWith (PlotDataBase<TypeX, Value>& other) {
376+ virtual void mergeWith (PlotDataBase<TypeX, Value>& other) {
377377 if (other._points .empty ())
378378 return ;
379379
@@ -396,17 +396,16 @@ class PlotDataBase
396396 }
397397
398398 if constexpr (std::is_arithmetic_v<TypeX>) {
399+ // new points are all before this->_points
400+ if (other._points .back ().x < this ->_points .front ().x ) {
401+ this ->_points .swap (other._points );
402+ }
399403
400404 // new points are all after this->_points
401405 if (other._points .front ().x > this ->_points .back ().x ) {
402406 std::move (other._points .begin (), other._points .end (), std::back_inserter (this ->_points ));
403-
404- // new points are all before this->_points
405- } else if (other._points .back ().x < this ->_points .front ().x ) {
406- std::move (this ->_points .begin (), this ->_points .end (), std::back_inserter (other._points ));
407- this ->_points .swap (other._points );
408407 } else {
409- // Fallback to standard merging with move where possible
408+ // Overlap: fallback to standard merging with move where possible
410409 std::deque<Point> result;
411410 std::merge (std::make_move_iterator (this ->_points .begin ()), std::make_move_iterator (this ->_points .end ()),
412411 std::make_move_iterator (other._points .begin ()), std::make_move_iterator (other._points .end ()),
0 commit comments