diff --git a/pcbnew/fp_textbox.cpp b/pcbnew/fp_textbox.cpp index af8d6fe228..b48d3b3da8 100644 --- a/pcbnew/fp_textbox.cpp +++ b/pcbnew/fp_textbox.cpp @@ -78,20 +78,40 @@ std::vector FP_TEXTBOX::GetAnchorAndOppositeCorner() const { std::vector pts; std::vector corners = GetCorners(); + EDA_ANGLE textAngle( GetDrawRotation() ); - EDA_ANGLE toCorner1( corners[0] - corners[1] ); - EDA_ANGLE toCorner3( corners[0] - corners[3] ); - EDA_ANGLE textAngle( GetDrawRotation() ); - toCorner1.Normalize(); - toCorner3.Normalize(); textAngle.Normalize(); pts.emplace_back( corners[0] ); - if( std::abs( toCorner1 - textAngle ) < std::abs( toCorner3 - textAngle ) ) - pts.emplace_back( corners[1] ); + if( textAngle < ANGLE_90 ) + { + if( corners[1].y <= corners[0].y ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } + else if( textAngle < ANGLE_180 ) + { + if( corners[1].x <= corners[0].x ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } + else if( textAngle < ANGLE_270 ) + { + if( corners[1].y >= corners[0].y ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } else - pts.emplace_back( corners[3] ); + { + if( corners[1].x >= corners[0].x ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } return pts; } diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index a99d293412..e0beea3f34 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -60,22 +60,42 @@ int PCB_TEXTBOX::GetTextMargin() const std::vector PCB_TEXTBOX::GetAnchorAndOppositeCorner() const { - EDA_ANGLE epsilon( 1.0, DEGREES_T ); // Yeah, it's a pretty coarse epsilon, but anything - // under 45° will work for our purposes. - std::vector pts; std::vector corners = GetCorners(); + EDA_ANGLE textAngle( GetDrawRotation() ); - EDA_ANGLE textAngle = GetDrawRotation().Normalize(); - EDA_ANGLE toCorner1 = EDA_ANGLE( corners[1] - corners[0] ).Normalize(); - EDA_ANGLE fromCorner1 = ( toCorner1 + ANGLE_180 ).Normalize(); + textAngle.Normalize(); pts.emplace_back( corners[0] ); - if( std::abs( toCorner1 - textAngle ) < epsilon || std::abs( fromCorner1 - textAngle ) < epsilon ) - pts.emplace_back( corners[1] ); + if( textAngle < ANGLE_90 ) + { + if( corners[1].y <= corners[0].y ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } + else if( textAngle < ANGLE_180 ) + { + if( corners[1].x <= corners[0].x ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } + else if( textAngle < ANGLE_270 ) + { + if( corners[1].y >= corners[0].y ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } else - pts.emplace_back( corners[3] ); + { + if( corners[1].x >= corners[0].x ) + pts.emplace_back( corners[1] ); + else + pts.emplace_back( corners[3] ); + } return pts; }