Math and I don't get along. So just be pedantic about text rotation.

Fixes https://gitlab.com/kicad/code/kicad/issues/11247
This commit is contained in:
Jeff Young 2022-03-30 19:53:41 +01:00
parent eac1ab3d1f
commit bb43a3926a
2 changed files with 57 additions and 17 deletions

View File

@ -78,20 +78,40 @@ std::vector<VECTOR2I> FP_TEXTBOX::GetAnchorAndOppositeCorner() const
{
std::vector<VECTOR2I> pts;
std::vector<VECTOR2I> corners = GetCorners();
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 ) )
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
{
if( corners[1].x >= corners[0].x )
pts.emplace_back( corners[1] );
else
pts.emplace_back( corners[3] );
}
return pts;
}

View File

@ -60,22 +60,42 @@ int PCB_TEXTBOX::GetTextMargin() const
std::vector<VECTOR2I> 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<VECTOR2I> pts;
std::vector<VECTOR2I> 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 )
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
{
if( corners[1].x >= corners[0].x )
pts.emplace_back( corners[1] );
else
pts.emplace_back( corners[3] );
}
return pts;
}