From 3760b6820ffa7fca2466edfa629ca28c34ef5f96 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 28 Feb 2018 16:34:48 -0800 Subject: [PATCH] pcbnew: align centers to the top and left When aligning module centers, it can be hard to determine which item will be chosen for the alignment target when it chooses based on the median of the center values. Instead, this patch chooses the alignment target as the top and left most items of the Y and X centering, respectively --- pcbnew/tools/placement_tool.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 54fd089a34..c4c742e12f 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -457,8 +457,9 @@ int ALIGN_DISTRIBUTE_TOOL::AlignCenterX( const TOOL_EVENT& aEvent ) BOARD_COMMIT commit( frame ); commit.StageItems( selection, CHT_MODIFY ); - // after sorting use the x coordinate of the middle item as a target for all other items - const int targetX = itemsToAlign.at( itemsToAlign.size() / 2 ).second.GetCenter().x; + // after sorting use the center x coordinate of the leftmost item as a target + // for all other items + const int targetX = itemsToAlign.begin()->second.GetCenter().x; // Move the selected items for( auto& i : itemsToAlign ) @@ -497,8 +498,9 @@ int ALIGN_DISTRIBUTE_TOOL::AlignCenterY( const TOOL_EVENT& aEvent ) BOARD_COMMIT commit( frame ); commit.StageItems( selection, CHT_MODIFY ); - // after sorting use the y coordinate of the middle item as a target for all other items - const int targetY = itemsToAlign.at( itemsToAlign.size() / 2 ).second.GetCenter().y; + // after sorting use the center y coordinate of the top-most item as a target + // for all other items + const int targetY = itemsToAlign.begin()->second.GetCenter().y; // Move the selected items for( auto& i : itemsToAlign )