Refactor MEANDER_PLACER_BASE::cutTunedLine to SHAPE_LINE_CHAIN::Split.
This commit is contained in:
parent
6cfb05b4a3
commit
8b21a260c9
|
@ -787,6 +787,18 @@ public:
|
|||
*/
|
||||
double Area( bool aAbsolute = true ) const;
|
||||
|
||||
/**
|
||||
* Extract parts of this line chain, depending on the starting and ending points.
|
||||
*
|
||||
* @param aStart first split point.
|
||||
* @param aEnd second split point.
|
||||
* @param aPre part before the aStart point.
|
||||
* @param aMid part between aStart and aEnd.
|
||||
* @param aPost part after the aEnd point.
|
||||
*/
|
||||
void Split( const VECTOR2I& aStart, const VECTOR2I& aEnd, SHAPE_LINE_CHAIN& aPre,
|
||||
SHAPE_LINE_CHAIN& aMid, SHAPE_LINE_CHAIN& aPost ) const;
|
||||
|
||||
/**
|
||||
* Creates line chains \a aLeft and \a aRight offset to this line chain.
|
||||
*
|
||||
|
|
|
@ -2131,6 +2131,36 @@ double SHAPE_LINE_CHAIN::Area( bool aAbsolute ) const
|
|||
}
|
||||
|
||||
|
||||
void SHAPE_LINE_CHAIN::Split( const VECTOR2I& aStart, const VECTOR2I& aEnd, SHAPE_LINE_CHAIN& aPre,
|
||||
SHAPE_LINE_CHAIN& aMid, SHAPE_LINE_CHAIN& aPost ) const
|
||||
{
|
||||
VECTOR2I cp( aEnd );
|
||||
|
||||
wxASSERT( cp != aStart );
|
||||
|
||||
VECTOR2I n = NearestPoint( cp, false );
|
||||
VECTOR2I m = NearestPoint( aStart, false );
|
||||
|
||||
SHAPE_LINE_CHAIN l( *this );
|
||||
l.Split( n, true );
|
||||
l.Split( m, true );
|
||||
|
||||
int i_start = l.Find( m );
|
||||
int i_end = l.Find( n );
|
||||
|
||||
if( i_start > i_end )
|
||||
{
|
||||
l = l.Reverse();
|
||||
i_start = l.Find( m );
|
||||
i_end = l.Find( n );
|
||||
}
|
||||
|
||||
aPre = l.Slice( 0, i_start );
|
||||
aPost = l.Slice( i_end, -1 );
|
||||
aMid = l.Slice( i_start, i_end );
|
||||
}
|
||||
|
||||
|
||||
bool SHAPE_LINE_CHAIN::OffsetLine( int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError,
|
||||
SHAPE_LINE_CHAIN& aLeft, SHAPE_LINE_CHAIN& aRight,
|
||||
bool aSimplify ) const
|
||||
|
|
|
@ -175,8 +175,8 @@ bool DP_MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
|
|||
SHAPE_LINE_CHAIN preP, tunedP, postP;
|
||||
SHAPE_LINE_CHAIN preN, tunedN, postN;
|
||||
|
||||
cutTunedLine( m_originPair.CP(), m_currentStart, aP, preP, tunedP, postP );
|
||||
cutTunedLine( m_originPair.CN(), m_currentStart, aP, preN, tunedN, postN );
|
||||
m_originPair.CP().Split( m_currentStart, aP, preP, tunedP, postP );
|
||||
m_originPair.CN().Split( m_currentStart, aP, preN, tunedN, postN );
|
||||
|
||||
auto updateStatus =
|
||||
[&]()
|
||||
|
|
|
@ -114,7 +114,7 @@ bool MEANDER_PLACER::doMove( const VECTOR2I& aP, ITEM* aEndItem, long long int a
|
|||
|
||||
m_currentNode = m_world->Branch();
|
||||
|
||||
cutTunedLine( m_originLine.CLine(), m_currentStart, aP, pre, tuned, post );
|
||||
m_originLine.CLine().Split( m_currentStart, aP, pre, tuned, post );
|
||||
|
||||
m_result = MEANDERED_LINE( this, false );
|
||||
m_result.SetWidth( m_originLine.Width() );
|
||||
|
|
|
@ -87,52 +87,6 @@ void MEANDER_PLACER_BASE::UpdateSettings( const MEANDER_SETTINGS& aSettings )
|
|||
}
|
||||
|
||||
|
||||
void MEANDER_PLACER_BASE::cutTunedLine( const SHAPE_LINE_CHAIN& aOrigin, const VECTOR2I& aTuneStart,
|
||||
const VECTOR2I& aCursorPos, SHAPE_LINE_CHAIN& aPre,
|
||||
SHAPE_LINE_CHAIN& aTuned, SHAPE_LINE_CHAIN& aPost )
|
||||
{
|
||||
VECTOR2I cp ( aCursorPos );
|
||||
|
||||
if( cp == aTuneStart ) // we don't like tuning segments with 0 length
|
||||
{
|
||||
int idx = aOrigin.FindSegment( cp );
|
||||
|
||||
if( idx >= 0 )
|
||||
{
|
||||
const SEG& s = aOrigin.CSegment( idx );
|
||||
cp += ( s.B - s.A ).Resize( 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
cp += VECTOR2I( 2, 5 ); // some arbitrary value that is not 45 degrees oriented
|
||||
}
|
||||
}
|
||||
|
||||
VECTOR2I n = aOrigin.NearestPoint( cp, false );
|
||||
VECTOR2I m = aOrigin.NearestPoint( aTuneStart, false );
|
||||
|
||||
SHAPE_LINE_CHAIN l( aOrigin );
|
||||
l.Split( n );
|
||||
l.Split( m );
|
||||
|
||||
int i_start = l.Find( m );
|
||||
int i_end = l.Find( n );
|
||||
|
||||
if( i_start > i_end )
|
||||
{
|
||||
l = l.Reverse();
|
||||
i_start = l.Find( m );
|
||||
i_end = l.Find( n );
|
||||
}
|
||||
|
||||
aPre = l.Slice( 0, i_start );
|
||||
aPost = l.Slice( i_end, -1 );
|
||||
aTuned = l.Slice( i_start, i_end );
|
||||
|
||||
aTuned.Simplify();
|
||||
}
|
||||
|
||||
|
||||
int findAmplitudeBinarySearch( MEANDER_SHAPE& aCopy, int targetLength, int minAmp, int maxAmp )
|
||||
{
|
||||
if( minAmp == maxAmp )
|
||||
|
|
|
@ -115,21 +115,6 @@ public:
|
|||
int GetTotalPadToDieLength( const LINE& aLine ) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Extract the part of a track to be meandered, depending on the starting point and the
|
||||
* cursor position.
|
||||
*
|
||||
* @param aOrigin the original line.
|
||||
* @param aTuneStart point where we start meandering (start click coordinates).
|
||||
* @param aCursorPos current cursor position.
|
||||
* @param aPre part before the beginning of meanders.
|
||||
* @param aTuned part to be meandered.
|
||||
* @param aPost part after the end of meanders.
|
||||
*/
|
||||
void cutTunedLine( const SHAPE_LINE_CHAIN& aOrigin, const VECTOR2I& aTuneStart,
|
||||
const VECTOR2I& aCursorPos, SHAPE_LINE_CHAIN& aPre, SHAPE_LINE_CHAIN& aTuned,
|
||||
SHAPE_LINE_CHAIN& aPost );
|
||||
|
||||
/**
|
||||
* Take a set of meanders in \a aTuned and tunes their length to extend the original line
|
||||
* length by \a aElongation.
|
||||
|
|
Loading…
Reference in New Issue