2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-18 00:29:54 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2016-05-28 16:46:29 +00:00
|
|
|
#include <cmath>
|
2015-02-18 00:29:54 +00:00
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
|
|
|
|
#include "pns_diff_pair.h"
|
|
|
|
#include "pns_router.h"
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class LINE;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR::DP_PRIMITIVE_PAIR( ITEM* aPrimP, ITEM* aPrimN )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_primP = aPrimP->Clone();
|
|
|
|
m_primN = aPrimN->Clone();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
m_anchorP = m_primP->Anchor( 0 );
|
|
|
|
m_anchorN = m_primN->Anchor( 0 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DP_PRIMITIVE_PAIR::SetAnchors( const VECTOR2I& aAnchorP, const VECTOR2I& aAnchorN )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_anchorP = aAnchorP;
|
|
|
|
m_anchorN = aAnchorN;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR::DP_PRIMITIVE_PAIR( const VECTOR2I& aAnchorP, const VECTOR2I& aAnchorN )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_anchorP = aAnchorP;
|
|
|
|
m_anchorN = aAnchorN;
|
2021-07-19 23:56:05 +00:00
|
|
|
m_primP = m_primN = nullptr;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR::DP_PRIMITIVE_PAIR( const DP_PRIMITIVE_PAIR& aOther )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
m_primP = m_primN = nullptr;
|
2015-06-15 14:01:43 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aOther.m_primP )
|
2015-02-18 00:29:54 +00:00
|
|
|
m_primP = aOther.m_primP->Clone();
|
2015-06-15 14:01:43 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aOther.m_primN )
|
2015-02-18 00:29:54 +00:00
|
|
|
m_primN = aOther.m_primN->Clone();
|
|
|
|
|
|
|
|
m_anchorP = aOther.m_anchorP;
|
|
|
|
m_anchorN = aOther.m_anchorN;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR& DP_PRIMITIVE_PAIR::operator=( const DP_PRIMITIVE_PAIR& aOther )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aOther.m_primP )
|
2015-02-18 00:29:54 +00:00
|
|
|
m_primP = aOther.m_primP->Clone();
|
2023-04-10 17:02:00 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aOther.m_primN )
|
2015-02-18 00:29:54 +00:00
|
|
|
m_primN = aOther.m_primN->Clone();
|
|
|
|
|
|
|
|
m_anchorP = aOther.m_anchorP;
|
|
|
|
m_anchorN = aOther.m_anchorN;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR::~DP_PRIMITIVE_PAIR()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
delete m_primP;
|
|
|
|
delete m_primN;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DP_PRIMITIVE_PAIR::Directional() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_primP )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2023-03-06 18:44:05 +00:00
|
|
|
return m_primP->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
DIRECTION_45 DP_PRIMITIVE_PAIR::anchorDirection( const ITEM* aItem, const VECTOR2I& aP ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
if( !aItem->OfKind ( ITEM::SEGMENT_T | ITEM::ARC_T ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return DIRECTION_45();
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
if( aItem->Anchor( 0 ) == aP )
|
|
|
|
return DIRECTION_45( aItem->Anchor( 0 ) - aItem->Anchor( 1 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
else
|
2019-05-17 00:13:21 +00:00
|
|
|
return DIRECTION_45( aItem->Anchor( 1 ) - aItem->Anchor( 0 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-04-13 00:34:44 +00:00
|
|
|
void DP_PRIMITIVE_PAIR::CursorOrientation( const VECTOR2I& aCursorPos, VECTOR2I& aMidpoint,
|
|
|
|
VECTOR2I& aDirection ) const
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
assert( m_primP && m_primN );
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2021-04-13 00:40:05 +00:00
|
|
|
VECTOR2I aP, aN;
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2021-04-13 00:34:44 +00:00
|
|
|
if( m_primP->OfKind( ITEM::SEGMENT_T ) && m_primN->OfKind( ITEM::SEGMENT_T ) )
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
2021-04-13 00:40:05 +00:00
|
|
|
aP = m_primP->Anchor( 1 );
|
|
|
|
aN = m_primN->Anchor( 1 );
|
2021-04-13 02:34:13 +00:00
|
|
|
|
|
|
|
// If both segments are parallel, use that as the direction. Otherwise, fall back on the
|
|
|
|
// direction perpendicular to the anchor points.
|
|
|
|
const SEG& segP = static_cast<SEGMENT*>( m_primP )->Seg();
|
|
|
|
const SEG& segN = static_cast<SEGMENT*>( m_primN )->Seg();
|
|
|
|
|
|
|
|
if( ( segP.B != segP.A ) && ( segN.B != segN.A ) && segP.ApproxParallel( segN ) )
|
|
|
|
{
|
|
|
|
aMidpoint = ( aP + aN ) / 2;
|
|
|
|
aDirection = segP.B - segP.A;
|
|
|
|
aDirection = aDirection.Resize( ( aP - aN ).EuclideanNorm() );
|
|
|
|
return;
|
|
|
|
}
|
2016-08-15 15:16:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-13 00:40:05 +00:00
|
|
|
aP = m_primP->Anchor( 0 );
|
|
|
|
aN = m_primN->Anchor( 0 );
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 00:40:05 +00:00
|
|
|
aMidpoint = ( aP + aN ) / 2;
|
|
|
|
aDirection = ( aP - aN ).Perpendicular();
|
|
|
|
|
|
|
|
if( aDirection.Dot( aCursorPos - aMidpoint ) < 0 )
|
|
|
|
aDirection = -aDirection;
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DIRECTION_45 DP_PRIMITIVE_PAIR::DirP() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return anchorDirection( m_primP, m_anchorP );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DIRECTION_45 DP_PRIMITIVE_PAIR::DirN() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return anchorDirection( m_primN, m_anchorN );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
static DIRECTION_45::AngleType angle( const VECTOR2I &a, const VECTOR2I &b )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
DIRECTION_45 dir_a( a );
|
|
|
|
DIRECTION_45 dir_b( b );
|
|
|
|
|
|
|
|
return dir_a.Angle( dir_b );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
static bool checkGap( const SHAPE_LINE_CHAIN &p, const SHAPE_LINE_CHAIN &n, int gap )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-04-10 21:21:20 +00:00
|
|
|
SEG::ecoord gap_sq = SEG::Square( gap - 100 );
|
|
|
|
|
2023-04-10 17:02:00 +00:00
|
|
|
for( int i = 0; i < p.SegmentCount(); i++ )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2023-04-10 17:02:00 +00:00
|
|
|
for( int j = 0; j < n.SegmentCount() ; j++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-04-10 21:21:20 +00:00
|
|
|
SEG::ecoord dist_sq = p.CSegment( i ).SquaredDistance( n.CSegment( j ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2023-04-10 21:21:20 +00:00
|
|
|
if( dist_sq < gap_sq )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DP_GATEWAY::Reverse()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_entryN = m_entryN.Reverse();
|
|
|
|
m_entryP = m_entryP.Reverse();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
bool DIFF_PAIR::BuildInitial( const DP_GATEWAY& aEntry, const DP_GATEWAY &aTarget,
|
|
|
|
bool aPrefDiagonal )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-04-10 17:02:00 +00:00
|
|
|
SHAPE_LINE_CHAIN p = DIRECTION_45().BuildInitialTrace( aEntry.AnchorP(), aTarget.AnchorP(),
|
|
|
|
aPrefDiagonal );
|
|
|
|
SHAPE_LINE_CHAIN n = DIRECTION_45().BuildInitialTrace( aEntry.AnchorN(), aTarget.AnchorN(),
|
|
|
|
aPrefDiagonal );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
int mask = aEntry.AllowedAngles() | DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_OBTUSE;
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN sum_n, sum_p;
|
|
|
|
m_p = p;
|
|
|
|
m_n = n;
|
|
|
|
|
|
|
|
if( aEntry.HasEntryLines() )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !aEntry.Entry().CheckConnectionAngle( *this, mask ) )
|
|
|
|
return false;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
sum_p = aEntry.Entry().CP();
|
|
|
|
sum_n = aEntry.Entry().CN();
|
2015-02-18 16:53:46 +00:00
|
|
|
sum_p.Append( p );
|
|
|
|
sum_n.Append( n );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
sum_p = p;
|
|
|
|
sum_n = n;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
mask = aTarget.AllowedAngles() | DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_OBTUSE;
|
|
|
|
|
|
|
|
m_p = sum_p;
|
|
|
|
m_n = sum_n;
|
|
|
|
|
|
|
|
if( aTarget.HasEntryLines() )
|
|
|
|
{
|
2023-04-10 17:02:00 +00:00
|
|
|
DP_GATEWAY t( aTarget );
|
2015-02-18 00:29:54 +00:00
|
|
|
t.Reverse();
|
|
|
|
|
|
|
|
if( !CheckConnectionAngle( t.Entry(), mask ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
sum_p.Append( t.Entry().CP() );
|
|
|
|
sum_n.Append( t.Entry().CN() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_p = sum_p;
|
|
|
|
m_n = sum_n;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2023-04-10 17:02:00 +00:00
|
|
|
if( !checkGap( p, n, m_gapConstraint ) )
|
2015-02-26 15:34:10 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( p.SelfIntersecting() || n.SelfIntersecting() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( p.Intersects( n ) )
|
|
|
|
return false;
|
2015-03-03 11:59:26 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR::CheckConnectionAngle( const DIFF_PAIR& aOther, int aAllowedAngles ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
bool checkP, checkN;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_p.SegmentCount() == 0 || aOther.m_p.SegmentCount() == 0 )
|
2023-04-10 17:02:00 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
checkP = true;
|
2023-04-10 17:02:00 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DIRECTION_45 p0( m_p.CSegment( -1 ) );
|
|
|
|
DIRECTION_45 p1( aOther.m_p.CSegment( 0 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
checkP = ( p0.Angle( p1 ) & aAllowedAngles ) != 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_n.SegmentCount() == 0 || aOther.m_n.SegmentCount() == 0 )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
checkN = true;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DIRECTION_45 n0( m_n.CSegment( -1 ) );
|
|
|
|
DIRECTION_45 n1( aOther.m_n.CSegment( 0 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
checkN = ( n0.Angle( n1 ) & aAllowedAngles ) != 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return checkP && checkN;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const DIFF_PAIR DP_GATEWAY::Entry() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
return DIFF_PAIR( m_entryP, m_entryN, 0 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
void DP_GATEWAYS::BuildOrthoProjections( DP_GATEWAYS& aEntries, const VECTOR2I& aCursorPos,
|
|
|
|
int aOrthoScore )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2017-09-24 18:11:58 +00:00
|
|
|
for( const DP_GATEWAY& g : aEntries.Gateways() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I midpoint( ( g.AnchorP() + g.AnchorN() ) / 2 );
|
2015-08-20 07:46:19 +00:00
|
|
|
SEG guide_s( midpoint, midpoint + VECTOR2I( 1, 0 ) );
|
|
|
|
SEG guide_d( midpoint, midpoint + VECTOR2I( 1, 1 ) );
|
|
|
|
|
|
|
|
VECTOR2I proj_s = guide_s.LineProject( aCursorPos );
|
|
|
|
VECTOR2I proj_d = guide_d.LineProject( aCursorPos );
|
|
|
|
|
|
|
|
int dist_s = ( proj_s - aCursorPos ).EuclideanNorm();
|
|
|
|
int dist_d = ( proj_d - aCursorPos ).EuclideanNorm();
|
|
|
|
|
|
|
|
VECTOR2I proj = ( dist_s < dist_d ? proj_s : proj_d );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_GATEWAYS targets( m_gap );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
targets.m_viaGap = m_viaGap;
|
|
|
|
targets.m_viaDiameter = m_viaDiameter;
|
|
|
|
targets.m_fitVias = m_fitVias;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
targets.BuildForCursor( proj );
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( DP_GATEWAY t : targets.Gateways() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
t.SetPriority( aOrthoScore );
|
|
|
|
m_gateways.push_back( t );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
bool DP_GATEWAYS::FitGateways( DP_GATEWAYS& aEntry, DP_GATEWAYS& aTarget, bool aPrefDiagonal,
|
|
|
|
DIFF_PAIR& aDp )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-15 15:16:49 +00:00
|
|
|
DP_CANDIDATE best;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
int bestScore = -1000;
|
|
|
|
bool found = false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const DP_GATEWAY& g_entry : aEntry.Gateways() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const DP_GATEWAY& g_target : aTarget.Gateways() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-04-10 17:02:00 +00:00
|
|
|
for( bool preferred : { false, true } )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-04-10 17:02:00 +00:00
|
|
|
int score = preferred ? 0 : -3;
|
2016-08-15 15:16:49 +00:00
|
|
|
score += g_entry.Priority();
|
|
|
|
score += g_target.Priority();
|
|
|
|
|
2023-04-10 17:02:00 +00:00
|
|
|
if( score >= bestScore )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-04-10 17:02:00 +00:00
|
|
|
DIFF_PAIR l( m_gap );
|
|
|
|
|
|
|
|
if( l.BuildInitial( g_entry, g_target, preferred ? aPrefDiagonal
|
|
|
|
: !aPrefDiagonal ) )
|
|
|
|
{
|
|
|
|
best.p = l.CP();
|
|
|
|
best.n = l.CN();
|
|
|
|
bestScore = score;
|
|
|
|
found = true;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( found )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
aDp.SetGap( m_gap );
|
2015-02-18 00:29:54 +00:00
|
|
|
aDp.SetShape( best.p, best.n );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DP_GATEWAYS::checkDiagonalAlignment( const VECTOR2I& a, const VECTOR2I& b ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
VECTOR2I dir( std::abs (a.x - b.x), std::abs ( a.y - b.y ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return (dir.x == 0 && dir.y != 0) || (dir.x == dir.y) || (dir.y == 0 && dir.x != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-10 17:02:00 +00:00
|
|
|
void DP_GATEWAYS::FilterByOrientation( int aAngleMask, DIRECTION_45 aRefOrientation )
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
2023-04-10 17:02:00 +00:00
|
|
|
alg::delete_if( m_gateways,
|
|
|
|
[aAngleMask, aRefOrientation]( const DP_GATEWAY& dp )
|
|
|
|
{
|
|
|
|
DIRECTION_45 orient( dp.AnchorP() - dp.AnchorN() );
|
|
|
|
return ( orient.Angle( aRefOrientation ) & aAngleMask );
|
|
|
|
} );
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:37:03 +00:00
|
|
|
static VECTOR2I makeGapVector( VECTOR2I dir, int length )
|
|
|
|
{
|
|
|
|
int l = length / 2;
|
|
|
|
VECTOR2I rv;
|
2017-07-06 08:40:52 +00:00
|
|
|
|
|
|
|
if( dir.EuclideanNorm() == 0 )
|
|
|
|
return dir;
|
|
|
|
|
2017-03-01 15:37:03 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
rv = dir.Resize( l );
|
|
|
|
l++;
|
|
|
|
} while( ( rv * 2 ).EuclideanNorm() < length );
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
void DP_GATEWAYS::BuildFromPrimitivePair( const DP_PRIMITIVE_PAIR& aPair, bool aPreferDiagonal )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I majorDirection;
|
|
|
|
VECTOR2I p0_p, p0_n;
|
|
|
|
int orthoFanDistance;
|
|
|
|
int diagFanDistance;
|
2021-07-19 23:56:05 +00:00
|
|
|
const SHAPE* shP = nullptr;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( aPair.PrimP() == nullptr )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
BuildGeneric( aPair.AnchorP(), aPair.AnchorN(), true );
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const int pvMask = ITEM::SOLID_T | ITEM::VIA_T;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aPair.PrimP()->OfKind( pvMask ) && aPair.PrimN()->OfKind( pvMask ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
p0_p = aPair.AnchorP();
|
|
|
|
p0_n = aPair.AnchorN();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
shP = aPair.PrimP()->Shape();
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2023-03-06 18:44:05 +00:00
|
|
|
else if( aPair.PrimP()->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T )
|
|
|
|
&& aPair.PrimN()->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
|
|
|
buildDpContinuation( aPair, aPreferDiagonal );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
majorDirection = ( p0_p - p0_n ).Perpendicular();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( shP == nullptr )
|
2015-03-10 14:38:27 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
switch( shP->Type() )
|
|
|
|
{
|
2023-04-08 22:25:53 +00:00
|
|
|
case SH_CIRCLE:
|
|
|
|
BuildGeneric ( p0_p, p0_n, true );
|
|
|
|
return;
|
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case SH_RECT:
|
|
|
|
{
|
|
|
|
int w = static_cast<const SHAPE_RECT*>( shP )->GetWidth();
|
|
|
|
int h = static_cast<const SHAPE_RECT*>( shP )->GetHeight();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
if( w < h )
|
|
|
|
std::swap( w, h );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2017-03-01 15:37:03 +00:00
|
|
|
orthoFanDistance = ( w + 1 )* 3 / 2;
|
|
|
|
diagFanDistance = ( w - h );
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case SH_SEGMENT:
|
|
|
|
{
|
|
|
|
int w = static_cast<const SHAPE_SEGMENT*>( shP )->GetWidth();
|
|
|
|
SEG s = static_cast<const SHAPE_SEGMENT*>( shP )->GetSeg();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2017-03-01 15:37:03 +00:00
|
|
|
orthoFanDistance = w + ( s.B - s.A ).EuclideanNorm();
|
|
|
|
diagFanDistance = ( s.B - s.A ).EuclideanNorm();
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-04-08 22:25:53 +00:00
|
|
|
case SH_SIMPLE:
|
|
|
|
case SH_COMPOUND:
|
|
|
|
{
|
|
|
|
BOX2I bbox = shP->BBox();
|
|
|
|
int w = bbox.GetWidth();
|
|
|
|
int h = bbox.GetHeight();
|
|
|
|
|
|
|
|
if( w < h )
|
|
|
|
std::swap( w, h );
|
|
|
|
|
|
|
|
orthoFanDistance = ( w + 1 )* 3 / 2;
|
|
|
|
diagFanDistance = ( w - h );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
2023-04-08 22:25:53 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Unsupported starting primitive: %d (%s)." ),
|
|
|
|
shP->Type(),
|
|
|
|
SHAPE_TYPE_asString( shP->Type() ) ) );
|
|
|
|
break;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( checkDiagonalAlignment( p0_p, p0_n ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
int padDist = ( p0_p - p0_n ).EuclideanNorm();
|
|
|
|
|
|
|
|
for( int k = 0; k < 2; k++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I dir, dp, dv;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( k == 0 )
|
2017-03-01 15:37:03 +00:00
|
|
|
dir = makeGapVector( majorDirection, orthoFanDistance );
|
2015-02-18 16:53:46 +00:00
|
|
|
else
|
2017-03-01 15:37:03 +00:00
|
|
|
dir = makeGapVector( majorDirection, diagFanDistance );
|
2021-11-27 19:03:08 +00:00
|
|
|
|
|
|
|
int d = std::max( 0, padDist - m_gap );
|
|
|
|
dp = makeGapVector( dir, d );
|
|
|
|
dv = makeGapVector( p0_n - p0_p, d );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int i = 0; i < 2; i++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int sign = i ? -1 : 1;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I gw_p( p0_p + sign * ( dir + dp ) + dv );
|
|
|
|
VECTOR2I gw_n( p0_n + sign * ( dir + dp ) - dv );
|
|
|
|
|
2019-03-24 13:54:56 +00:00
|
|
|
SHAPE_LINE_CHAIN entryP( { p0_p, p0_p + sign * dir, gw_p } );
|
|
|
|
SHAPE_LINE_CHAIN entryN( { p0_n, p0_n + sign * dir, gw_n } );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_GATEWAY gw( gw_p, gw_n, false );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
gw.SetEntryLines( entryP, entryN );
|
|
|
|
gw.SetPriority( 100 - k );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_gateways.push_back( gw );
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
BuildGeneric( p0_p, p0_n, true );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DP_GATEWAYS::BuildForCursor( const VECTOR2I& aCursorPos )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int gap = m_fitVias ? m_viaGap + m_viaDiameter : m_gap;
|
|
|
|
|
2023-04-08 14:06:17 +00:00
|
|
|
for( bool diagonal : { false, true } )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
VECTOR2I dir;
|
|
|
|
|
2023-04-08 14:06:17 +00:00
|
|
|
if( !diagonal )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2017-03-01 15:37:03 +00:00
|
|
|
dir = makeGapVector( VECTOR2I( gap, gap ), gap );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( i % 2 == 0 )
|
|
|
|
dir.x = -dir.x;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( i / 2 == 0 )
|
|
|
|
dir.y = -dir.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( i /2 == 0 )
|
2017-03-01 15:37:03 +00:00
|
|
|
dir = VECTOR2I( (gap + 1) / 2 * ( ( i % 2 ) ? -1 : 1 ), 0 );
|
2015-02-18 00:29:54 +00:00
|
|
|
else
|
2023-04-08 14:06:17 +00:00
|
|
|
dir = VECTOR2I( 0, (gap + 1) / 2 * ( ( i % 2 ) ? -1 : 1 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( m_fitVias )
|
|
|
|
BuildGeneric( aCursorPos + dir, aCursorPos - dir, true, true );
|
|
|
|
else
|
2023-04-08 14:06:17 +00:00
|
|
|
m_gateways.emplace_back( aCursorPos + dir, aCursorPos - dir, diagonal );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DP_GATEWAYS::buildEntries( const VECTOR2I& p0_p, const VECTOR2I& p0_n )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( DP_GATEWAY &g : m_gateways )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !g.HasEntryLines() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
SHAPE_LINE_CHAIN lead_p = DIRECTION_45().BuildInitialTrace ( g.AnchorP(), p0_p,
|
|
|
|
g.IsDiagonal() ).Reverse();
|
|
|
|
SHAPE_LINE_CHAIN lead_n = DIRECTION_45().BuildInitialTrace ( g.AnchorN(), p0_n,
|
|
|
|
g.IsDiagonal() ).Reverse();
|
2015-02-18 16:53:46 +00:00
|
|
|
g.SetEntryLines( lead_p, lead_n );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
void DP_GATEWAYS::buildDpContinuation( const DP_PRIMITIVE_PAIR& aPair, bool aIsDiagonal )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_GATEWAY gw( aPair.AnchorP(), aPair.AnchorN(), aIsDiagonal );
|
2015-02-18 00:29:54 +00:00
|
|
|
gw.SetPriority( 100 );
|
2015-02-18 16:53:46 +00:00
|
|
|
m_gateways.push_back( gw );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !aPair.Directional() )
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
|
2023-04-10 21:21:20 +00:00
|
|
|
// Add gateways that angle the anchor points by 22.5 degrees for connection to tracks which
|
|
|
|
// are at +/- 45 degrees from the existing direction.
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-04-10 21:21:20 +00:00
|
|
|
auto addAngledGateways =
|
|
|
|
[&]( int length, int priority )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN entryLineP;
|
|
|
|
entryLineP.Append( aPair.AnchorP() );
|
|
|
|
entryLineP.Append( aPair.AnchorP() + aPair.DirP().ToVector().Resize( length ) );
|
|
|
|
DP_GATEWAY gwExtendP( entryLineP.CLastPoint(), aPair.AnchorN(), aIsDiagonal );
|
|
|
|
gwExtendP.SetPriority( priority );
|
|
|
|
gwExtendP.SetEntryLines( entryLineP, SHAPE_LINE_CHAIN() );
|
|
|
|
m_gateways.push_back( gwExtendP );
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN entryLineN;
|
|
|
|
entryLineN.Append( aPair.AnchorN() );
|
|
|
|
entryLineN.Append( aPair.AnchorN() + aPair.DirN().ToVector().Resize( length ) );
|
|
|
|
DP_GATEWAY gwExtendN( aPair.AnchorP(), entryLineN.CLastPoint(), aIsDiagonal );
|
|
|
|
gwExtendN.SetPriority( priority );
|
|
|
|
gwExtendN.SetEntryLines( SHAPE_LINE_CHAIN(), entryLineN );
|
|
|
|
m_gateways.push_back( gwExtendN );
|
|
|
|
};
|
|
|
|
|
|
|
|
addAngledGateways( KiROUND( (double) m_gap * 0.38268 ), 20 );
|
|
|
|
|
|
|
|
// fixme; sin(22.5) doesn't always work, so we also add some lower priority ones with a bit
|
|
|
|
// of wiggle room. See https://gitlab.com/kicad/code/kicad/-/issues/12459.
|
|
|
|
addAngledGateways( KiROUND( (double) m_gap * 0.4 ), 5 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
void DP_GATEWAYS::BuildGeneric( const VECTOR2I& p0_p, const VECTOR2I& p0_n, bool aBuildEntries,
|
|
|
|
bool aViaMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
SEG st_p[2], st_n[2];
|
|
|
|
SEG d_n[2], d_p[2];
|
|
|
|
|
|
|
|
const int padToGapThreshold = 3;
|
2018-10-08 02:15:01 +00:00
|
|
|
int padDist = ( p0_n - p0_p ).EuclideanNorm();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
st_p[0] = SEG(p0_p + VECTOR2I( -100, 0 ), p0_p + VECTOR2I( 100, 0 ) );
|
|
|
|
st_n[0] = SEG(p0_n + VECTOR2I( -100, 0 ), p0_n + VECTOR2I( 100, 0 ) );
|
|
|
|
st_p[1] = SEG(p0_p + VECTOR2I( 0, -100 ), p0_p + VECTOR2I( 0, 100 ) );
|
|
|
|
st_n[1] = SEG(p0_n + VECTOR2I( 0, -100 ), p0_n + VECTOR2I( 0, 100 ) );
|
|
|
|
d_p[0] = SEG( p0_p + VECTOR2I( -100, -100 ), p0_p + VECTOR2I( 100, 100 ) );
|
|
|
|
d_p[1] = SEG( p0_p + VECTOR2I( 100, -100 ), p0_p + VECTOR2I( -100, 100 ) );
|
|
|
|
d_n[0] = SEG( p0_n + VECTOR2I( -100, -100 ), p0_n + VECTOR2I( 100, 100 ) );
|
|
|
|
d_n[1] = SEG( p0_n + VECTOR2I( 100, -100 ), p0_n + VECTOR2I( -100, 100 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
// midpoint exit & side-by exits
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int i = 0; i < 2; i++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
bool straightColl = st_p[i].Collinear( st_n[i] );
|
2015-02-18 00:29:54 +00:00
|
|
|
bool diagColl = d_p[i].Collinear( d_n[i] );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( straightColl || diagColl )
|
|
|
|
{
|
2017-03-01 15:37:03 +00:00
|
|
|
VECTOR2I dir = makeGapVector( p0_n - p0_p, m_gap / 2 );
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2I m = ( p0_p + p0_n ) / 2;
|
2023-04-10 17:02:00 +00:00
|
|
|
int prio = ( padDist > padToGapThreshold * m_gap ) ? 2 : 1;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !aViaMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
m_gateways.emplace_back( m - dir, m + dir, diagColl, DIRECTION_45::ANG_RIGHT,
|
|
|
|
prio );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2017-03-01 15:37:03 +00:00
|
|
|
dir = makeGapVector( p0_n - p0_p, 2 * m_gap );
|
2019-12-05 15:41:21 +00:00
|
|
|
m_gateways.emplace_back( p0_p - dir, p0_p - dir + dir.Perpendicular(), diagColl );
|
|
|
|
m_gateways.emplace_back( p0_p - dir, p0_p - dir - dir.Perpendicular(), diagColl );
|
|
|
|
m_gateways.emplace_back( p0_n + dir + dir.Perpendicular(), p0_n + dir, diagColl );
|
|
|
|
m_gateways.emplace_back( p0_n + dir - dir.Perpendicular(), p0_n + dir, diagColl );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
for( int j = 0; j < 2; j++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-24 07:42:46 +00:00
|
|
|
OPT_VECTOR2I ips[2];
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
ips[0] = d_n[i].IntersectLines( d_p[j] );
|
|
|
|
ips[1] = st_p[i].IntersectLines( st_n[j] );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( d_n[i].Collinear( d_p[j] ) )
|
2017-11-01 11:14:16 +00:00
|
|
|
ips[0] = OPT_VECTOR2I();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( st_p[i].Collinear( st_p[j] ) )
|
2017-11-01 11:14:16 +00:00
|
|
|
ips[1] = OPT_VECTOR2I();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
// diagonal-diagonal and straight-straight cases - the most typical case if the pads
|
|
|
|
// are on the same straight/diagonal line
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int k = 0; k < 2; k++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-24 07:42:46 +00:00
|
|
|
if( ips[k] )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-24 07:42:46 +00:00
|
|
|
const VECTOR2I m( *ips[k] );
|
|
|
|
|
2015-03-04 01:16:14 +00:00
|
|
|
if( m != p0_p && m != p0_n )
|
|
|
|
{
|
|
|
|
int prio = ( padDist > padToGapThreshold * m_gap ? 10 : 20 );
|
2017-03-01 15:37:03 +00:00
|
|
|
VECTOR2I g_p( ( p0_p - m ).Resize( ceil( (double) m_gap * M_SQRT1_2 ) ) );
|
|
|
|
VECTOR2I g_n( ( p0_n - m ).Resize( ceil( (double) m_gap * M_SQRT1_2 ) ) );
|
2015-03-04 01:16:14 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_gateways.emplace_back( m + g_p, m + g_n, k == 0 ? true : false,
|
|
|
|
DIRECTION_45::ANG_OBTUSE, prio );
|
2015-03-04 01:16:14 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ips[0] = st_n[i].IntersectLines( d_p[j] );
|
|
|
|
ips[1] = st_p[i].IntersectLines( d_n[j] );
|
|
|
|
|
2023-04-10 17:02:00 +00:00
|
|
|
// diagonal-straight cases: 8 possibilities of "weirder" exists
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int k = 0; k < 2; k++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-24 07:42:46 +00:00
|
|
|
if( ips[k] )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-24 07:42:46 +00:00
|
|
|
const VECTOR2I m( *ips[k] );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-07-24 07:42:46 +00:00
|
|
|
if( !aViaMode && m != p0_p && m != p0_n )
|
|
|
|
{
|
|
|
|
VECTOR2I g_p, g_n;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2017-03-01 15:37:03 +00:00
|
|
|
g_p = ( p0_p - m ).Resize( ceil( (double) m_gap * M_SQRT2 ) );
|
|
|
|
g_n = ( p0_n - m ).Resize( ceil( (double) m_gap ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-07-24 07:42:46 +00:00
|
|
|
if( angle( g_p, g_n ) != DIRECTION_45::ANG_ACUTE )
|
2019-12-05 15:41:21 +00:00
|
|
|
m_gateways.emplace_back( m + g_p, m + g_n, true );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-07-24 07:42:46 +00:00
|
|
|
g_p = ( p0_p - m ).Resize( m_gap );
|
2017-03-01 15:37:03 +00:00
|
|
|
g_n = ( p0_n - m ).Resize( ceil( (double) m_gap * M_SQRT2 ) );
|
2015-07-24 07:42:46 +00:00
|
|
|
|
|
|
|
if( angle( g_p, g_n ) != DIRECTION_45::ANG_ACUTE )
|
2019-12-05 15:41:21 +00:00
|
|
|
m_gateways.emplace_back( m + g_p, m + g_n, true );
|
2015-07-24 07:42:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aBuildEntries )
|
|
|
|
buildEntries( p0_p, p0_n );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR DIFF_PAIR::EndingPrimitives()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_hasVias )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
return DP_PRIMITIVE_PAIR( &m_via_p, &m_via_n );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
else
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE lP( PLine() );
|
|
|
|
const LINE lN( NLine() );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT sP( lP, lP.CSegment( -1 ) );
|
|
|
|
SEGMENT sN( lN, lN.CSegment( -1 ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR dpair( &sP, &sN );
|
2015-02-18 16:53:46 +00:00
|
|
|
dpair.SetAnchors( sP.Seg().B, sN.Seg().B );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return dpair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2018-10-08 14:30:17 +00:00
|
|
|
bool commonParallelProjection( SEG p, SEG n, SEG &pClip, SEG& nClip )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
SEG n_proj_p( p.LineProject( n.A ), p.LineProject( n.B ) );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int64_t t_a = 0;
|
2015-02-18 16:53:46 +00:00
|
|
|
int64_t t_b = p.TCoef( p.B );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
int64_t tproj_a = p.TCoef( n_proj_p.A );
|
|
|
|
int64_t tproj_b = p.TCoef( n_proj_p.B );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( t_b < t_a )
|
|
|
|
std::swap( t_b, t_a );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( tproj_b < tproj_a )
|
|
|
|
std::swap( tproj_b, tproj_a );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( t_b <= tproj_a )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( t_a >= tproj_b )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
int64_t t[4] = { 0, p.TCoef( p.B ), p.TCoef( n_proj_p.A ), p.TCoef( n_proj_p.B ) };
|
|
|
|
std::vector<int64_t> tv( t, t + 4 );
|
|
|
|
std::sort( tv.begin(), tv.end() ); // fixme: awful and disgusting way of finding 2 midpoints
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
int64_t pLenSq = p.SquaredLength();
|
|
|
|
|
|
|
|
VECTOR2I dp = p.B - p.A;
|
2015-02-18 16:53:46 +00:00
|
|
|
pClip.A.x = p.A.x + rescale( (int64_t)dp.x, tv[1], pLenSq );
|
|
|
|
pClip.A.y = p.A.y + rescale( (int64_t)dp.y, tv[1], pLenSq );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
pClip.B.x = p.A.x + rescale( (int64_t)dp.x, tv[2], pLenSq );
|
|
|
|
pClip.B.y = p.A.y + rescale( (int64_t)dp.y, tv[2], pLenSq );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
nClip.A = n.LineProject( pClip.A );
|
|
|
|
nClip.B = n.LineProject( pClip.B );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
double DIFF_PAIR::Skew() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_p.Length() - m_n.Length();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR::CoupledSegmentPairs( COUPLED_SEGMENTS_VEC& aPairs ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
SHAPE_LINE_CHAIN p( m_p );
|
|
|
|
SHAPE_LINE_CHAIN n( m_n );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
p.Simplify();
|
|
|
|
n.Simplify();
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int i = 0; i < p.SegmentCount(); i++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int j = 0; j < n.SegmentCount(); j++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2019-03-23 18:26:44 +00:00
|
|
|
SEG sp = p.Segment( i );
|
|
|
|
SEG sn = n.Segment( j );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
SEG p_clip, n_clip;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
int64_t dist = std::abs( sp.Distance( sn ) - m_width );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-12-12 18:05:26 +00:00
|
|
|
if( sp.ApproxParallel( sn, 2 ) && m_gapConstraint.Matches( dist ) &&
|
2021-07-19 23:56:05 +00:00
|
|
|
commonParallelProjection( sp, sn, p_clip, n_clip ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
const COUPLED_SEGMENTS spair( p_clip, sp, i, n_clip, sn, j );
|
2015-02-18 00:29:54 +00:00
|
|
|
aPairs.push_back( spair );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int64_t DIFF_PAIR::CoupledLength( const SHAPE_LINE_CHAIN& aP, const SHAPE_LINE_CHAIN& aN ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int64_t total = 0;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int i = 0; i < aP.SegmentCount(); i++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int j = 0; j < aN.SegmentCount(); j++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
SEG sp = aP.CSegment( i );
|
|
|
|
SEG sn = aN.CSegment( j );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
SEG p_clip, n_clip;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
int64_t dist = std::abs( sp.Distance(sn) - m_width );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( sp.ApproxParallel( sn ) && m_gapConstraint.Matches( dist ) &&
|
2021-07-19 23:56:05 +00:00
|
|
|
commonParallelProjection( sp, sn, p_clip, n_clip ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
total += p_clip.Length();
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
double DIFF_PAIR::CoupledLength() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
COUPLED_SEGMENTS_VEC pairs;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
CoupledSegmentPairs( pairs );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
double l = 0.0;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2023-04-10 17:02:00 +00:00
|
|
|
for( const COUPLED_SEGMENTS& pair : pairs )
|
|
|
|
l += pair.coupledP.Length();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
double DIFF_PAIR::CoupledLengthFactor() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
double t = TotalLength();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( t == 0.0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
return 0.0;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return CoupledLength() / t;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
double DIFF_PAIR::TotalLength() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
double lenP = m_p.Length();
|
|
|
|
double lenN = m_n.Length();
|
|
|
|
|
|
|
|
return (lenN + lenP ) / 2.0;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int DIFF_PAIR::CoupledLength ( const SEG& aP, const SEG& aN ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
SEG p_clip, n_clip;
|
2015-02-18 16:53:46 +00:00
|
|
|
int64_t dist = std::abs( aP.Distance( aN ) - m_width );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-04-10 17:02:00 +00:00
|
|
|
if( aP.ApproxParallel( aN ) && m_gapConstraint.Matches( dist )
|
|
|
|
&& commonParallelProjection ( aP, aN, p_clip, n_clip ) )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
return p_clip.Length();
|
2023-04-10 17:02:00 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|