Improve readability.
This commit is contained in:
parent
e208685f85
commit
11995c1350
|
@ -78,6 +78,7 @@ DP_PRIMITIVE_PAIR& DP_PRIMITIVE_PAIR::operator=( const DP_PRIMITIVE_PAIR& aOther
|
||||||
{
|
{
|
||||||
if( aOther.m_primP )
|
if( aOther.m_primP )
|
||||||
m_primP = aOther.m_primP->Clone();
|
m_primP = aOther.m_primP->Clone();
|
||||||
|
|
||||||
if( aOther.m_primN )
|
if( aOther.m_primN )
|
||||||
m_primN = aOther.m_primN->Clone();
|
m_primN = aOther.m_primN->Clone();
|
||||||
|
|
||||||
|
@ -178,11 +179,9 @@ static DIRECTION_45::AngleType angle( const VECTOR2I &a, const VECTOR2I &b )
|
||||||
|
|
||||||
static bool checkGap( const SHAPE_LINE_CHAIN &p, const SHAPE_LINE_CHAIN &n, int gap )
|
static bool checkGap( const SHAPE_LINE_CHAIN &p, const SHAPE_LINE_CHAIN &n, int gap )
|
||||||
{
|
{
|
||||||
int i, j;
|
for( int i = 0; i < p.SegmentCount(); i++ )
|
||||||
|
|
||||||
for( i = 0; i < p.SegmentCount(); i++ )
|
|
||||||
{
|
{
|
||||||
for( j = 0; j < n.SegmentCount() ; j++ )
|
for( int j = 0; j < n.SegmentCount() ; j++ )
|
||||||
{
|
{
|
||||||
int dist = p.CSegment( i ).Distance( n.CSegment( j ) );
|
int dist = p.CSegment( i ).Distance( n.CSegment( j ) );
|
||||||
|
|
||||||
|
@ -205,10 +204,10 @@ void DP_GATEWAY::Reverse()
|
||||||
bool DIFF_PAIR::BuildInitial( const DP_GATEWAY& aEntry, const DP_GATEWAY &aTarget,
|
bool DIFF_PAIR::BuildInitial( const DP_GATEWAY& aEntry, const DP_GATEWAY &aTarget,
|
||||||
bool aPrefDiagonal )
|
bool aPrefDiagonal )
|
||||||
{
|
{
|
||||||
SHAPE_LINE_CHAIN p = DIRECTION_45().BuildInitialTrace ( aEntry.AnchorP(), aTarget.AnchorP(),
|
SHAPE_LINE_CHAIN p = DIRECTION_45().BuildInitialTrace( aEntry.AnchorP(), aTarget.AnchorP(),
|
||||||
aPrefDiagonal );
|
aPrefDiagonal );
|
||||||
SHAPE_LINE_CHAIN n = DIRECTION_45().BuildInitialTrace ( aEntry.AnchorN(), aTarget.AnchorN(),
|
SHAPE_LINE_CHAIN n = DIRECTION_45().BuildInitialTrace( aEntry.AnchorN(), aTarget.AnchorN(),
|
||||||
aPrefDiagonal );
|
aPrefDiagonal );
|
||||||
|
|
||||||
int mask = aEntry.AllowedAngles() | DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_OBTUSE;
|
int mask = aEntry.AllowedAngles() | DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_OBTUSE;
|
||||||
|
|
||||||
|
@ -239,7 +238,7 @@ bool DIFF_PAIR::BuildInitial( const DP_GATEWAY& aEntry, const DP_GATEWAY &aTarge
|
||||||
|
|
||||||
if( aTarget.HasEntryLines() )
|
if( aTarget.HasEntryLines() )
|
||||||
{
|
{
|
||||||
DP_GATEWAY t(aTarget) ;
|
DP_GATEWAY t( aTarget );
|
||||||
t.Reverse();
|
t.Reverse();
|
||||||
|
|
||||||
if( !CheckConnectionAngle( t.Entry(), mask ) )
|
if( !CheckConnectionAngle( t.Entry(), mask ) )
|
||||||
|
@ -252,7 +251,7 @@ bool DIFF_PAIR::BuildInitial( const DP_GATEWAY& aEntry, const DP_GATEWAY &aTarge
|
||||||
m_p = sum_p;
|
m_p = sum_p;
|
||||||
m_n = sum_n;
|
m_n = sum_n;
|
||||||
|
|
||||||
if( !checkGap ( p, n, m_gapConstraint ) )
|
if( !checkGap( p, n, m_gapConstraint ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( p.SelfIntersecting() || n.SelfIntersecting() )
|
if( p.SelfIntersecting() || n.SelfIntersecting() )
|
||||||
|
@ -270,7 +269,9 @@ bool DIFF_PAIR::CheckConnectionAngle( const DIFF_PAIR& aOther, int aAllowedAngle
|
||||||
bool checkP, checkN;
|
bool checkP, checkN;
|
||||||
|
|
||||||
if( m_p.SegmentCount() == 0 || aOther.m_p.SegmentCount() == 0 )
|
if( m_p.SegmentCount() == 0 || aOther.m_p.SegmentCount() == 0 )
|
||||||
|
{
|
||||||
checkP = true;
|
checkP = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DIRECTION_45 p0( m_p.CSegment( -1 ) );
|
DIRECTION_45 p0( m_p.CSegment( -1 ) );
|
||||||
|
@ -340,7 +341,6 @@ bool DP_GATEWAYS::FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget, bool a
|
||||||
{
|
{
|
||||||
DP_CANDIDATE best;
|
DP_CANDIDATE best;
|
||||||
|
|
||||||
int n = 0;
|
|
||||||
int bestScore = -1000;
|
int bestScore = -1000;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
|
@ -348,26 +348,24 @@ bool DP_GATEWAYS::FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget, bool a
|
||||||
{
|
{
|
||||||
for( const DP_GATEWAY& g_target : aTarget.Gateways() )
|
for( const DP_GATEWAY& g_target : aTarget.Gateways() )
|
||||||
{
|
{
|
||||||
n++;
|
for( bool preferred : { false, true } )
|
||||||
|
|
||||||
for( int attempt = 0; attempt < 2; attempt++ )
|
|
||||||
{
|
{
|
||||||
int score = ( attempt == 1 ? -3 : 0 );
|
int score = preferred ? 0 : -3;
|
||||||
score += g_entry.Priority();
|
score += g_entry.Priority();
|
||||||
score += g_target.Priority();
|
score += g_target.Priority();
|
||||||
|
|
||||||
if( score < bestScore )
|
if( score >= bestScore )
|
||||||
continue;
|
|
||||||
|
|
||||||
DIFF_PAIR l( m_gap );
|
|
||||||
|
|
||||||
if( l.BuildInitial( g_entry, g_target,
|
|
||||||
aPrefDiagonal ^ ( attempt ? true : false ) ) )
|
|
||||||
{
|
{
|
||||||
best.p = l.CP();
|
DIFF_PAIR l( m_gap );
|
||||||
best.n = l.CN();
|
|
||||||
bestScore = score;
|
if( l.BuildInitial( g_entry, g_target, preferred ? aPrefDiagonal
|
||||||
found = true;
|
: !aPrefDiagonal ) )
|
||||||
|
{
|
||||||
|
best.p = l.CP();
|
||||||
|
best.n = l.CN();
|
||||||
|
bestScore = score;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,16 +391,14 @@ bool DP_GATEWAYS::checkDiagonalAlignment( const VECTOR2I& a, const VECTOR2I& b )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DP_GATEWAYS::FilterByOrientation ( int aAngleMask, DIRECTION_45 aRefOrientation )
|
void DP_GATEWAYS::FilterByOrientation( int aAngleMask, DIRECTION_45 aRefOrientation )
|
||||||
{
|
{
|
||||||
m_gateways.erase(
|
alg::delete_if( m_gateways,
|
||||||
std::remove_if( m_gateways.begin(), m_gateways.end(),
|
[aAngleMask, aRefOrientation]( const DP_GATEWAY& dp )
|
||||||
[aAngleMask, aRefOrientation]( const DP_GATEWAY& dp)
|
{
|
||||||
{
|
DIRECTION_45 orient( dp.AnchorP() - dp.AnchorN() );
|
||||||
DIRECTION_45 orient( dp.AnchorP() - dp.AnchorN() );
|
return ( orient.Angle( aRefOrientation ) & aAngleMask );
|
||||||
return ( orient.Angle( aRefOrientation ) & aAngleMask );
|
} );
|
||||||
} ), m_gateways.end()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VECTOR2I makeGapVector( VECTOR2I dir, int length )
|
static VECTOR2I makeGapVector( VECTOR2I dir, int length )
|
||||||
|
@ -681,7 +677,7 @@ void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool
|
||||||
{
|
{
|
||||||
VECTOR2I dir = makeGapVector( p0_n - p0_p, m_gap / 2 );
|
VECTOR2I dir = makeGapVector( p0_n - p0_p, m_gap / 2 );
|
||||||
VECTOR2I m = ( p0_p + p0_n ) / 2;
|
VECTOR2I m = ( p0_p + p0_n ) / 2;
|
||||||
int prio = ( padDist > padToGapThreshold * m_gap ? 2 : 1);
|
int prio = ( padDist > padToGapThreshold * m_gap ) ? 2 : 1;
|
||||||
|
|
||||||
if( !aViaMode )
|
if( !aViaMode )
|
||||||
{
|
{
|
||||||
|
@ -735,7 +731,7 @@ void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool
|
||||||
ips[0] = st_n[i].IntersectLines( d_p[j] );
|
ips[0] = st_n[i].IntersectLines( d_p[j] );
|
||||||
ips[1] = st_p[i].IntersectLines( d_n[j] );
|
ips[1] = st_p[i].IntersectLines( d_n[j] );
|
||||||
|
|
||||||
// diagonal-straight cases: 8 possibilities of "weirder" exists
|
// diagonal-straight cases: 8 possibilities of "weirder" exists
|
||||||
for( int k = 0; k < 2; k++ )
|
for( int k = 0; k < 2; k++ )
|
||||||
{
|
{
|
||||||
if( ips[k] )
|
if( ips[k] )
|
||||||
|
@ -901,8 +897,8 @@ double DIFF_PAIR::CoupledLength() const
|
||||||
|
|
||||||
double l = 0.0;
|
double l = 0.0;
|
||||||
|
|
||||||
for( unsigned int i = 0; i < pairs.size(); i++ )
|
for( const COUPLED_SEGMENTS& pair : pairs )
|
||||||
l += pairs[i].coupledP.Length();
|
l += pair.coupledP.Length();
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
@ -933,9 +929,11 @@ int DIFF_PAIR::CoupledLength ( const SEG& aP, const SEG& aN ) const
|
||||||
SEG p_clip, n_clip;
|
SEG p_clip, n_clip;
|
||||||
int64_t dist = std::abs( aP.Distance( aN ) - m_width );
|
int64_t dist = std::abs( aP.Distance( aN ) - m_width );
|
||||||
|
|
||||||
if( aP.ApproxParallel( aN ) && m_gapConstraint.Matches( dist ) &&
|
if( aP.ApproxParallel( aN ) && m_gapConstraint.Matches( dist )
|
||||||
commonParallelProjection ( aP, aN, p_clip, n_clip ) )
|
&& commonParallelProjection ( aP, aN, p_clip, n_clip ) )
|
||||||
|
{
|
||||||
return p_clip.Length();
|
return p_clip.Length();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue