router: implement area constraint in optimizer

This commit is contained in:
Tomasz Wlostowski 2020-10-18 22:58:48 +02:00
parent 64cf593ee9
commit 14ce7a0ad7
2 changed files with 51 additions and 18 deletions

View File

@ -237,8 +237,7 @@ bool PRESERVE_VERTEX_CONSTRAINT::Check( int aVertex1, int aVertex2, const LINE*
for( int i = aVertex1; i < aVertex2; i++ )
{
SEG::ecoord dist = aCurrentPath.CSegment(i).SquaredDistance( m_v );
int dist = aCurrentPath.CSegment(i).Distance( m_v );
if ( dist <= 1 )
{
cv = true;
@ -254,7 +253,9 @@ bool PRESERVE_VERTEX_CONSTRAINT::Check( int aVertex1, int aVertex2, const LINE*
SEG::ecoord dist = aReplacement.CSegment(i).SquaredDistance( m_v );
if ( dist <= 1 )
{
return true;
}
}
return false;
@ -306,9 +307,9 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
result = 1 - result;
else
{
double d = static_cast<double>( ip.x - aP.x ) *
double d = static_cast<double>( ip.x - aP.x ) *
static_cast<double>( ipNext.y - aP.y ) -
static_cast<double>( ipNext.x - aP.x ) *
static_cast<double>( ipNext.x - aP.x ) *
static_cast<double>( ip.y - aP.y );
if( !d )
@ -592,7 +593,7 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult )
auto c = new PRESERVE_VERTEX_CONSTRAINT( m_world, m_preservedVertex );
AddConstraint( c );
}
if( m_effortLevel & RESTRICT_VERTEX_RANGE )
{
auto c = new RESTRICT_VERTEX_RANGE_CONSTRAINT( m_world, m_restrictedVertexRange.first,
@ -600,6 +601,13 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult )
AddConstraint( c );
}
if ( m_effortLevel & RESTRICT_AREA )
{
auto c = new AREA_CONSTRAINT( m_world, m_restrictArea );
AddConstraint( c );
}
if( m_effortLevel & KEEP_TOPOLOGY )
{
auto c = new KEEP_TOPOLOGY_CONSTRAINT( m_world );

View File

@ -100,10 +100,11 @@ public:
SMART_PADS = 0x02, ///< Reroute pad exits
MERGE_OBTUSE = 0x04, ///< Reduce corner cost by merging obtuse segments
FANOUT_CLEANUP = 0x08, ///< Simplify pad-pad and pad-via connections if possible
KEEP_TOPOLOGY = 0x10,
PRESERVE_VERTEX = 0x20,
KEEP_TOPOLOGY = 0x10,
PRESERVE_VERTEX = 0x20,
RESTRICT_VERTEX_RANGE = 0x40,
MERGE_COLINEAR = 0x80 ///< Merge co-linear segments
MERGE_COLINEAR = 0x80, ///< Merge co-linear segments
RESTRICT_AREA = 0x100
};
OPTIMIZER( NODE* aWorld );
@ -194,17 +195,19 @@ private:
ITEM* findPadOrVia( int aLayer, int aNet, const VECTOR2I& aP ) const;
private:
SHAPE_INDEX_LIST<ITEM*> m_cache;
SHAPE_INDEX_LIST<ITEM*> m_cache;
std::vector<OPT_CONSTRAINT*> m_constraints;
std::unordered_map<ITEM*, CACHED_ITEM> m_cacheTags;
NODE* m_world;
int m_collisionKindMask;
int m_effortLevel;
NODE* m_world;
int m_collisionKindMask;
int m_effortLevel;
bool m_keepPostures;
VECTOR2I m_preservedVertex;
VECTOR2I m_preservedVertex;
std::pair<int, int> m_restrictedVertexRange;
BOX2I m_restrictArea;
BOX2I m_restrictArea;
};
@ -213,9 +216,9 @@ class OPT_CONSTRAINT
public:
OPT_CONSTRAINT( NODE* aWorld ) :
m_world( aWorld )
{
m_priority = 0;
};
{
m_priority = 0;
};
virtual ~OPT_CONSTRAINT()
{
@ -230,9 +233,28 @@ public:
protected:
NODE* m_world;
int m_priority;
int m_priority;
};
class ANGLE_CONSTRAINT_45: public OPT_CONSTRAINT
{
public:
ANGLE_CONSTRAINT_45( NODE* aWorld, int aEntryDirectionMask = -1, int aExitDirectionMask = -1 ) :
OPT_CONSTRAINT( aWorld ),
m_entryDirectionMask( aEntryDirectionMask ),
m_exitDirectionMask( aExitDirectionMask )
{
}
virtual ~ANGLE_CONSTRAINT_45() {};
virtual bool Check ( int aVertex1, int aVertex2, LINE* aOriginLine, const SHAPE_LINE_CHAIN& aCurrentPath, const SHAPE_LINE_CHAIN& aReplacement ) override;
private:
int m_entryDirectionMask;
int m_exitDirectionMask;
};
class AREA_CONSTRAINT : public OPT_CONSTRAINT
{
@ -249,6 +271,7 @@ public:
private:
BOX2I m_allowedArea;
};
@ -279,6 +302,7 @@ public:
const SHAPE_LINE_CHAIN& aCurrentPath,
const SHAPE_LINE_CHAIN& aReplacement ) override;
private:
VECTOR2I m_v;
};
@ -297,6 +321,7 @@ public:
const SHAPE_LINE_CHAIN& aCurrentPath,
const SHAPE_LINE_CHAIN& aReplacement ) override;
private:
int m_start;
int m_end;
};