diff --git a/common/tool/selection.cpp b/common/tool/selection.cpp index 55dde50ee8..6200d88c42 100644 --- a/common/tool/selection.cpp +++ b/common/tool/selection.cpp @@ -219,8 +219,8 @@ bool SELECTION::OnlyContains( std::vector aList ) const } -const std::vector SELECTION::GetItemsSortedByTypeAndXY( bool leftBeforeRight, - bool topBeforeBottom ) const +std::vector SELECTION::GetItemsSortedByTypeAndXY( bool leftBeforeRight, + bool topBeforeBottom ) const { std::vector sorted_items = std::vector( m_items.begin(), m_items.end() ); @@ -229,24 +229,27 @@ const std::vector SELECTION::GetItemsSortedByTypeAndXY( bool leftBefo { if( a->Type() == b->Type() ) { - if( a->GetSortPosition().x == b->GetSortPosition().x ) + const VECTOR2I aPos = a->GetSortPosition(); + const VECTOR2I bPos = b->GetSortPosition(); + + if( aPos.x == bPos.x ) { // Ensure deterministic sort - if( a->GetSortPosition().y == b->GetSortPosition().y ) + if( aPos.y == bPos.y ) return a->m_Uuid < b->m_Uuid; if( topBeforeBottom ) - return a->GetSortPosition().y < b->GetSortPosition().y; + return aPos.y < bPos.y; else - return a->GetSortPosition().y > b->GetSortPosition().y; + return aPos.y > bPos.y; } else if( leftBeforeRight ) { - return a->GetSortPosition().x < b->GetSortPosition().x; + return aPos.x < bPos.x; } else { - return a->GetSortPosition().x > b->GetSortPosition().x; + return aPos.x > bPos.x; } } else @@ -254,12 +257,11 @@ const std::vector SELECTION::GetItemsSortedByTypeAndXY( bool leftBefo return a->Type() < b->Type(); } } ); - return sorted_items; } -const std::vector SELECTION::GetItemsSortedBySelectionOrder() const +std::vector SELECTION::GetItemsSortedBySelectionOrder() const { using pairedIterators = std::pair; diff --git a/include/tool/selection.h b/include/tool/selection.h index ba5ce5c95c..889657f70f 100644 --- a/include/tool/selection.h +++ b/include/tool/selection.h @@ -131,12 +131,12 @@ public: /** * Returns a copy of this selection of items sorted by their X then Y position. * - * @return Vector of sorted items + * @return std::vector of sorted items */ - const std::vector GetItemsSortedByTypeAndXY( bool leftBeforeRight = true, - bool topBeforeBottom = true ) const; + std::vector GetItemsSortedByTypeAndXY( bool leftBeforeRight = true, + bool topBeforeBottom = true ) const; - const std::vector GetItemsSortedBySelectionOrder() const; + std::vector GetItemsSortedBySelectionOrder() const; /// Returns the center point of the selection area bounding box. virtual VECTOR2I GetCenter() const;