router: implement area constraint in optimizer
This commit is contained in:
parent
64cf593ee9
commit
14ce7a0ad7
|
@ -237,8 +237,7 @@ bool PRESERVE_VERTEX_CONSTRAINT::Check( int aVertex1, int aVertex2, const LINE*
|
||||||
|
|
||||||
for( int i = aVertex1; i < aVertex2; i++ )
|
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 )
|
if ( dist <= 1 )
|
||||||
{
|
{
|
||||||
cv = true;
|
cv = true;
|
||||||
|
@ -254,8 +253,10 @@ bool PRESERVE_VERTEX_CONSTRAINT::Check( int aVertex1, int aVertex2, const LINE*
|
||||||
SEG::ecoord dist = aReplacement.CSegment(i).SquaredDistance( m_v );
|
SEG::ecoord dist = aReplacement.CSegment(i).SquaredDistance( m_v );
|
||||||
|
|
||||||
if ( dist <= 1 )
|
if ( dist <= 1 )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -600,6 +601,13 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult )
|
||||||
AddConstraint( c );
|
AddConstraint( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( m_effortLevel & RESTRICT_AREA )
|
||||||
|
{
|
||||||
|
auto c = new AREA_CONSTRAINT( m_world, m_restrictArea );
|
||||||
|
AddConstraint( c );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if( m_effortLevel & KEEP_TOPOLOGY )
|
if( m_effortLevel & KEEP_TOPOLOGY )
|
||||||
{
|
{
|
||||||
auto c = new KEEP_TOPOLOGY_CONSTRAINT( m_world );
|
auto c = new KEEP_TOPOLOGY_CONSTRAINT( m_world );
|
||||||
|
|
|
@ -103,7 +103,8 @@ public:
|
||||||
KEEP_TOPOLOGY = 0x10,
|
KEEP_TOPOLOGY = 0x10,
|
||||||
PRESERVE_VERTEX = 0x20,
|
PRESERVE_VERTEX = 0x20,
|
||||||
RESTRICT_VERTEX_RANGE = 0x40,
|
RESTRICT_VERTEX_RANGE = 0x40,
|
||||||
MERGE_COLINEAR = 0x80 ///< Merge co-linear segments
|
MERGE_COLINEAR = 0x80, ///< Merge co-linear segments
|
||||||
|
RESTRICT_AREA = 0x100
|
||||||
};
|
};
|
||||||
|
|
||||||
OPTIMIZER( NODE* aWorld );
|
OPTIMIZER( NODE* aWorld );
|
||||||
|
@ -201,6 +202,8 @@ private:
|
||||||
NODE* m_world;
|
NODE* m_world;
|
||||||
int m_collisionKindMask;
|
int m_collisionKindMask;
|
||||||
int m_effortLevel;
|
int m_effortLevel;
|
||||||
|
bool m_keepPostures;
|
||||||
|
|
||||||
|
|
||||||
VECTOR2I m_preservedVertex;
|
VECTOR2I m_preservedVertex;
|
||||||
std::pair<int, int> m_restrictedVertexRange;
|
std::pair<int, int> m_restrictedVertexRange;
|
||||||
|
@ -233,6 +236,25 @@ protected:
|
||||||
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
|
class AREA_CONSTRAINT : public OPT_CONSTRAINT
|
||||||
{
|
{
|
||||||
|
@ -249,6 +271,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BOX2I m_allowedArea;
|
BOX2I m_allowedArea;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,6 +302,7 @@ public:
|
||||||
const SHAPE_LINE_CHAIN& aCurrentPath,
|
const SHAPE_LINE_CHAIN& aCurrentPath,
|
||||||
const SHAPE_LINE_CHAIN& aReplacement ) override;
|
const SHAPE_LINE_CHAIN& aReplacement ) override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
VECTOR2I m_v;
|
VECTOR2I m_v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -297,6 +321,7 @@ public:
|
||||||
const SHAPE_LINE_CHAIN& aCurrentPath,
|
const SHAPE_LINE_CHAIN& aCurrentPath,
|
||||||
const SHAPE_LINE_CHAIN& aReplacement ) override;
|
const SHAPE_LINE_CHAIN& aReplacement ) override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int m_start;
|
int m_start;
|
||||||
int m_end;
|
int m_end;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue