Angle cleanup.

This commit is contained in:
Jeff Young 2022-01-20 21:26:04 +00:00
parent 95caf0eff9
commit 14006495d5
7 changed files with 39 additions and 27 deletions

View File

@ -18,6 +18,7 @@
*/
#include <geometry/direction45.h>
#include <trigo.h>
const SHAPE_LINE_CHAIN DIRECTION_45::BuildInitialTrace( const VECTOR2I& aP0, const VECTOR2I& aP1,
@ -168,8 +169,10 @@ const SHAPE_LINE_CHAIN DIRECTION_45::BuildInitialTrace( const VECTOR2I& aP0, con
}
else
{
int rotationSign = ( w > h ) ? ( sw * sh ) : ( sw * sh * -1 );
VECTOR2D centerDir( mp0.Rotate( M_PI_2 * rotationSign ) );
int rotationSign = ( w > h ) ? ( sw * sh * -1 ) : ( sw * sh );
VECTOR2D centerDir( mp0 );
RotatePoint( centerDir, ANGLE_90 * rotationSign );
if( tangentLength >= 0 )
{

View File

@ -410,7 +410,7 @@ void DRC_TEST_PROVIDER_MECHANICAL_CLEARANCE::testShapeLineChain( const SHAPE_LIN
if( seg.SquaredLength() > SEG::Square( epsilon * 2 ) )
{
angles.push_back( ( seg.B - seg.A ).Angle() );
angles.push_back( EDA_ANGLE( seg.B - seg.A ).AsRadians() );
}
else if( ii > 0 )
{
@ -424,7 +424,7 @@ void DRC_TEST_PROVIDER_MECHANICAL_CLEARANCE::testShapeLineChain( const SHAPE_LIN
if( following.SquaredLength() > SEG::Square( epsilon * 2 ) || jj == count - 1 )
{
angles.push_back( ( following.B - following.A ).Angle() );
angles.push_back( EDA_ANGLE( following.B - following.A ).AsRadians() );
break;
}
}

View File

@ -276,9 +276,9 @@ void MEANDER_SHAPE::forward( int aLength )
}
void MEANDER_SHAPE::turn( int aAngle )
void MEANDER_SHAPE::turn( const EDA_ANGLE& aAngle )
{
m_currentDir = m_currentDir.Rotate( (double) aAngle * M_PI / 180.0 );
RotatePoint( m_currentDir, aAngle );
}
@ -286,7 +286,7 @@ void MEANDER_SHAPE::miter( int aRadius, bool aSide )
{
if( aRadius <= 0 )
{
turn( aSide ? -90 : 90 );
turn( aSide ? ANGLE_90 : -ANGLE_90 );
return;
}
@ -294,7 +294,7 @@ void MEANDER_SHAPE::miter( int aRadius, bool aSide )
SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
m_currentPos = lc.CPoint( -1 );
m_currentDir = dir.Rotate( aSide ? -M_PI / 2.0 : M_PI / 2.0 );
turn( aSide ? ANGLE_90 : -ANGLE_90 );
m_currentTarget->Append( lc );
}
@ -359,7 +359,7 @@ SHAPE_LINE_CHAIN MEANDER_SHAPE::genMeanderShape( const VECTOR2D& aP, const VECTO
case MT_FINISH:
{
start( &lc, aP - dir_u_b, aDir );
turn( 90 );
turn( -ANGLE_90 );
forward( std::min( cr - offset, cr + offset ) );
forward( std::abs( offset ) );
uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr );
@ -370,7 +370,7 @@ SHAPE_LINE_CHAIN MEANDER_SHAPE::genMeanderShape( const VECTOR2D& aP, const VECTO
case MT_TURN:
{
start( &lc, aP - dir_u_b, aDir );
turn( 90 );
turn( -ANGLE_90 );
forward( std::abs( offset ) );
uShape( aAmpl - cr, cr + offset, spc - 2 * cr );
forward( std::abs( offset ) );

View File

@ -305,7 +305,7 @@ private:
void forward( int aLength );
///< Turn the turtle by \a aAngle
void turn( int aAngle );
void turn( const EDA_ANGLE& aAngle );
///< Tell the turtle to draw a mitered corner of given radius and turn direction.
void miter( int aRadius, bool aSide );

View File

@ -750,15 +750,17 @@ OPTIMIZER::BREAKOUT_LIST OPTIMIZER::circleBreakouts( int aWidth, const SHAPE* aS
{
BREAKOUT_LIST breakouts;
for( int angle = 0; angle < 360; angle += 45 )
for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += ANGLE_45 )
{
const SHAPE_CIRCLE* cir = static_cast<const SHAPE_CIRCLE*>( aShape );
SHAPE_LINE_CHAIN l;
VECTOR2I p0 = cir->GetCenter();
VECTOR2I v0( cir->GetRadius() * M_SQRT2, 0 );
RotatePoint( v0, -angle );
l.Append( p0 );
l.Append( p0 + v0.Rotate( angle * M_PI / 180.0 ) );
l.Append( p0 + v0 );
breakouts.push_back( l );
}
@ -776,11 +778,14 @@ OPTIMIZER::BREAKOUT_LIST OPTIMIZER::customBreakouts( int aWidth, const ITEM* aIt
VECTOR2I p0 = static_cast<const SOLID*>( aItem )->Pos();
// must be large enough to guarantee intersecting the convex polygon
int length = std::max( bbox.GetWidth(), bbox.GetHeight() ) / 2 + 5;
EDA_ANGLE increment = ( aPermitDiagonal ? ANGLE_45 : ANGLE_90 );
for( int angle = 0; angle < 360; angle += ( aPermitDiagonal ? 45 : 90 ) )
for( EDA_ANGLE angle = ANGLE_0; angle < ANGLE_360; angle += increment )
{
SHAPE_LINE_CHAIN l;
VECTOR2I v0( p0 + VECTOR2I( length, 0 ).Rotate( angle * M_PI / 180.0 ) );
VECTOR2I v0( p0 + VECTOR2I( length, 0 ) );
RotatePoint( v0, p0, -angle );
SHAPE_LINE_CHAIN::INTERSECTIONS intersections;
int n = convex->Vertices().Intersect( SEG( p0, v0 ), intersections );

View File

@ -1846,7 +1846,9 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
{
VECTOR2I offset = m_endSnapPoint - p;
BOARD_ITEM* previewItem;
wxPoint fp_offset = wxPoint( offset.Rotate( footprint->GetOrientation().AsRadians() ) );
VECTOR2I fp_offset( offset );
RotatePoint( fp_offset, -footprint->GetOrientation() );
view()->ClearPreview();

View File

@ -53,7 +53,9 @@ void TRACK_BUFFER::AddTrack( PCB_TRACK* aTrack, int aLayer, int aNetcode )
m_map_tracks[idxFromLayNet( aLayer, aNetcode )] = buffer;
}
else
{
buffer = (*item).second;
}
buffer->push_back( aTrack );
}
@ -72,7 +74,7 @@ VIAPAD::VIAPAD( PCB_VIA* aVia ) :
VIAPAD::VIAPAD( PAD* aPad ) :
m_Parent( aPad )
m_Parent( aPad )
{
m_Pos = aPad->GetPosition();
m_Width = std::min( aPad->GetSize().x, aPad->GetSize().y );
@ -86,7 +88,7 @@ VIAPAD::VIAPAD( PAD* aPad ) :
VIAPAD::VIAPAD( PCB_TRACK* aTrack, ENDPOINT_T aEndPoint ) :
m_Parent( aTrack )
m_Parent( aTrack )
{
m_Pos = aEndPoint == ENDPOINT_START ? aTrack->GetStart() : aTrack->GetEnd();
m_Width =aTrack->GetWidth();
@ -153,9 +155,7 @@ void TEARDROP_MANAGER::collectTeardrops( std::vector< ZONE* >& aList ) const
for( ZONE* zone : m_board->Zones() )
{
if( zone->IsTeardropArea() )
{
aList.push_back( zone );
}
}
}
@ -183,7 +183,9 @@ bool TEARDROP_MANAGER::isViaAndTrackInSameZone( VIAPAD& aViapad, PCB_TRACK* aTra
if( zone->GetPadConnection() == ZONE_CONNECTION::NONE
|| pad->GetZoneConnection() == ZONE_CONNECTION::NONE )
{
return false;
}
}
return true;
@ -205,7 +207,7 @@ PCB_TRACK* TEARDROP_MANAGER::findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_
PCB_TRACK* candidate = nullptr; // a reference to the track connected
std::vector<PCB_TRACK*>* currlist = aTrackLookupList.GetTrackList( aTrackRef->GetLayer(),
aTrackRef->GetNetCode() );
aTrackRef->GetNetCode() );
for( PCB_TRACK* curr_track: *currlist )
{
@ -346,11 +348,11 @@ void TEARDROP_MANAGER::computeCurvedForRectShape( TEARDROP_PARAMETERS* aCurrPar
int delta_effective = std::min( delta, side_length/8 );
// The move vector depend on the quadrant: it must be always defined to create a
// curve with a direction toward the track
double angle1 = side1.Angle();
int sign = std::abs( angle1 ) >= 90.0*M_PI/180 ? 1 : -1;
VECTOR2I bias( 0, sign * delta_effective );
EDA_ANGLE angle1( side1 );
int sign = std::abs( angle1 ) >= ANGLE_90 ? 1 : -1;
VECTOR2I bias( 0, sign * delta_effective );
bias.Rotate( angle1 );
RotatePoint( bias, -angle1 );
ctrl1.x += bias.x;
ctrl1.y += bias.y;
@ -694,9 +696,9 @@ bool TEARDROP_MANAGER::computeTeardropPolygonPoints( TEARDROP_PARAMETERS* aCurrP
// find the 2 points on the track, sharp end of the teardrop
int track_halfwidth = aTrack->GetWidth() / 2;
VECTOR2I pointB = start + VECTOR2I( vecT.x * track_stub_len + vecT.y * track_halfwidth,
vecT.y * track_stub_len - vecT.x * track_halfwidth );
vecT.y * track_stub_len - vecT.x * track_halfwidth );
VECTOR2I pointA = start + VECTOR2I( vecT.x * track_stub_len - vecT.y * track_halfwidth,
vecT.y * track_stub_len + vecT.x * track_halfwidth );
vecT.y * track_stub_len + vecT.x * track_halfwidth );
// To build a polygonal valid shape pointA and point B must be outside the pad
// It can be inside with some pad shapes having very different X and X sizes