105 int aNet,
const std::vector<CONTACT>& aContacts )
const
108 const VECTOR2I normal = ( aWire.
B - aWire.
A ).Perpendicular().Resize( step );
109 const SEG replaced( aEnter, aLeave );
112 for(
const CONTACT& contact : aContacts )
114 if( contact.Net == aNet && strictlyInside( replaced, contact.Pos ) )
118 std::vector<SEG> best;
119 int bestCrossings = 0;
121 for(
int mult : { 1, -1, 2, -2, 3, -3 } )
125 const SEG pieces[] = {
SEG( aEnter, enterOff ),
SEG( enterOff, leaveOff ),
SEG( leaveOff, aLeave ) };
127 if( std::any_of( std::begin( pieces ), std::end( pieces ),
128 [&](
const SEG& aPiece )
141 if( wire.Net == aNet )
144 for(
const SEG& piece : pieces )
146 if( piece.Intersect( wire.Seg,
true ) )
151 if( best.empty() || crossings < bestCrossings )
153 best.assign( std::begin( pieces ), std::end( pieces ) );
154 bestCrossings = crossings;
167 const std::vector<CONTACT> all =
contacts();
169 std::vector<VECTOR2I> foreign;
171 for(
const CONTACT& contact : all )
173 if( contact.Net != aNet && strictlyInside( aWire, contact.Pos )
174 && std::find( foreign.begin(), foreign.end(), contact.Pos ) == foreign.end() )
176 foreign.push_back( contact.Pos );
180 auto replaceRegistered =
184 [&](
const WIRE& aEntry )
186 return aEntry.
Net == aNet && aEntry.
Seg == aWire;
193 if( foreign.empty() )
195 result.Pieces = { aWire };
201 if( aWire.
A.
x != aWire.
B.
x && aWire.
A.
y != aWire.
B.
y )
203 result.Pieces = { aWire };
212 std::sort( foreign.begin(), foreign.end(),
215 return ( a - aWire.A ).SquaredEuclideanNorm() < ( b - aWire.A ).SquaredEuclideanNorm();
218 auto alongWire = [&](
const VECTOR2I& aPt )
220 return ( aPt - aWire.
A ).Dot( along );
224 std::vector<VECTOR2I> branches;
226 for(
const CONTACT& contact : all )
228 if( contact.Net == aNet && strictlyInside( aWire, contact.Pos ) )
229 branches.push_back( contact.Pos );
234 return std::any_of( branches.begin(), branches.end(),
237 return alongWire( aPt ) > alongWire( aFrom ) && alongWire( aPt ) < alongWire( aTo );
242 std::vector<std::pair<VECTOR2I, VECTOR2I>> clusters;
246 if( !clusters.empty() && ( pt - clusters.back().second ).EuclideanNorm() <= 3 * step
247 && !branchBetween( clusters.back().second, pt ) )
249 clusters.back().second = pt;
253 clusters.emplace_back( pt, pt );
257 std::vector<VECTOR2I>
path{ aWire.
A };
259 for(
const auto& [first, last] : clusters )
264 if( alongWire( enter ) < 0 )
267 if( alongWire( leave ) > alongWire( aWire.
B ) )
270 for(
const VECTOR2I& branch : branches )
272 if( alongWire( branch ) > alongWire( enter ) && alongWire( branch ) < alongWire( first ) )
275 if( alongWire( branch ) < alongWire( leave ) && alongWire( branch ) > alongWire( last ) )
279 std::vector<SEG> pieces =
detour( aWire, enter, leave, aNet, all );
287 for(
const VECTOR2I& pt : { pieces[0].A, pieces[0].B, pieces[1].B, pieces[2].B } )
289 if( pt !=
path.back() )
290 path.push_back( pt );
294 if( aWire.
B !=
path.back() )
295 path.push_back( aWire.
B );
297 for(
size_t i = 1; i <
path.size(); i++ )
301 for(
const VECTOR2I& branch : branches )
303 if( std::none_of(
result.Pieces.begin(),
result.Pieces.end(),
304 [&](
const SEG& aPiece )
306 return aPiece.Contains( branch );
309 result.Pieces = { aWire };
bool joinsOtherNet(const SEG &aPiece, const SEG &aWire, int aNet, const std::vector< CONTACT > &aContacts) const
True if a detour piece would join another net.
std::vector< SEG > detour(const SEG &aWire, const VECTOR2I &aEnter, const VECTOR2I &aLeave, int aNet, const std::vector< CONTACT > &aContacts) const
Detour the stretch of a wire between two points, or an empty vector if there is no safe place for it.
wxString result
Test unit parsing edge cases and error handling.