32 std::vector<VECTOR2I>* aIntersectionPoints =
nullptr )
34 SEG segment( p1, p2 );
44 std::vector<VECTOR2I> rawPoints;
46 std::visit( visitor, geom1 );
50 std::vector<VECTOR2I> filtered;
52 for(
const VECTOR2I& ip : rawPoints )
54 bool atSharedEndpoint = ( ip == arcStart || ip == arcEnd )
55 && ( ip == p1 || ip == p2 );
57 if( !atSharedEndpoint )
58 filtered.push_back( ip );
61 if( aIntersectionPoints )
64 aIntersectionPoints->push_back( ip );
67 return !filtered.empty();
74 std::vector<VECTOR2I>& aIntersectionPoints )
76 if( p1 == p2 || p1 == q2 || q1 == p2 || q1 == q2 )
79 SEG segment1( p1, q1 );
80 SEG segment2( p2, q2 );
85 size_t startCount = aIntersectionPoints.size();
88 std::visit( visitor, geom1 );
90 return aIntersectionPoints.size() > startCount;
105 if( a->
GetType() == CREEP_SHAPE::TYPE::UNDEFINED )
111 if( a->
GetType() == CREEP_SHAPE::TYPE::CIRCLE )
129 if( a->
GetType() == CREEP_SHAPE::TYPE::POINT )
132 if( a->
GetType() == CREEP_SHAPE::TYPE::CIRCLE )
140 double aMaxSquaredWeight )
const
142 std::vector<PATH_CONNECTION>
result;
144 double weight = ( this->
GetPos() - aS2.
GetPos() ).SquaredEuclideanNorm();
146 if( weight > aMaxSquaredWeight )
152 pc.
weight = sqrt( weight );
160 double aMaxSquaredWeight )
const
162 std::vector<PATH_CONNECTION>
result;
170 double pointToCenterDistanceSquared = ( pointPos - circleCenter ).SquaredEuclideanNorm();
171 double weightSquared = pointToCenterDistanceSquared - (float)
radius * (
float)
radius;
173 if( weightSquared > aMaxSquaredWeight )
177 direction1 = direction1.
Resize( 1 );
181 double radiusSquared = double(
radius ) * double(
radius );
183 double distance = sqrt( pointToCenterDistanceSquared );
184 double value1 = radiusSquared /
distance;
185 double value2 = sqrt( radiusSquared - value1 * value1 );
191 pc.
weight = sqrt( weightSquared );
193 resultPoint = direction1 * value1 + direction2 * value2 + circleCenter;
194 pc.
a2.
x = int( resultPoint.
x );
195 pc.
a2.
y = int( resultPoint.
y );
198 resultPoint = direction1 * value1 - direction2 * value2 + circleCenter;
199 pc.
a2.
x = int( resultPoint.
x );
200 pc.
a2.
y = int( resultPoint.
y );
209 std::pair<bool, bool>
result;
226 double pointAngle = testAngle.
AsRadians();
229 bool connectToEndPoint;
231 connectToEndPoint = ( cos( startAngle ) * newPoint.
x + sin( startAngle ) * newPoint.
y >= R );
234 connectToEndPoint &= ( cos( endAngle ) * newPoint.
x + sin( endAngle ) * newPoint.
y <= R );
236 connectToEndPoint |= ( cos( endAngle ) * newPoint.
x + sin( endAngle ) * newPoint.
y <= R )
237 && ( pointAngle >= endAngle || pointAngle <= startAngle );
239 result.first = !connectToEndPoint;
241 connectToEndPoint = ( cos( endAngle ) * newPoint.
x + sin( endAngle ) * newPoint.
y >= R );
244 connectToEndPoint &= ( cos( startAngle ) * newPoint.
x + sin( startAngle ) * newPoint.
y <= R );
246 connectToEndPoint |= ( cos( startAngle ) * newPoint.
x + sin( startAngle ) * newPoint.
y <= R )
247 && ( pointAngle >= endAngle || pointAngle <= startAngle );
249 result.second = !connectToEndPoint;
255 double aMaxSquaredWeight )
const
257 std::vector<PATH_CONNECTION>
result;
263 std::pair<bool, bool> behavesLikeCircle;
266 if( behavesLikeCircle.first && behavesLikeCircle.second )
269 return this->
Paths( csc, aMaxWeight, aMaxSquaredWeight );
272 if( behavesLikeCircle.first )
275 std::vector<PATH_CONNECTION> paths = this->
Paths( csc, aMaxWeight, aMaxSquaredWeight );
277 if( paths.size() > 1 )
278 result.push_back( paths[1] );
288 if( behavesLikeCircle.second )
291 std::vector<PATH_CONNECTION> paths = this->
Paths( csc, aMaxWeight, aMaxSquaredWeight );
293 if( paths.size() > 1 )
294 result.push_back( paths[0] );
308 double aMaxSquaredWeight )
const
310 std::vector<PATH_CONNECTION>
result;
318 double centerDistance = ( circleCenter - arcCenter ).EuclideanNorm();
320 if( centerDistance + arcRadius < circleRadius )
358 double aMaxSquaredWeight )
const
360 std::vector<PATH_CONNECTION>
result;
366 double centerDistance = ( circleCenter - arcCenter ).EuclideanNorm();
368 if( centerDistance + arcRadius < circleRadius )
380 aMaxWeight, aMaxSquaredWeight ) )
389 .
Paths( aS2, aMaxWeight, aMaxSquaredWeight ) )
402 double aMaxSquaredWeight )
const
404 std::vector<PATH_CONNECTION>
result;
409 VECTOR2D distSquared(
double( ( p2 - p1 ).x ),
double( ( p2 - p1 ).y ) );
415 double Rdiff = abs( R1 - R2 );
416 double Rsum = R1 + R2;
419 double weightSquared1 = weightSquared - Rdiff * Rdiff;
421 double weightSquared2 = weightSquared - Rsum * Rsum;
423 if( weightSquared1 <= aMaxSquaredWeight )
426 direction1 = direction1.
Resize( 1 );
429 double D = sqrt( weightSquared );
430 double ratio1 = ( R1 - R2 ) /
D;
431 double ratio2 = sqrt( 1 - ratio1 * ratio1 );
435 pc.
weight = sqrt( weightSquared1 );
437 pc.
a1 = p1 + direction1 * R1 * ratio1 + direction2 * R1 * ratio2;
438 pc.
a2 = p2 + direction1 * R2 * ratio1 + direction2 * R2 * ratio2;
442 pc.
a1 = p1 + direction1 * R1 * ratio1 - direction2 * R1 * ratio2;
443 pc.
a2 = p2 + direction1 * R2 * ratio1 - direction2 * R2 * ratio2;
447 if( weightSquared2 <= aMaxSquaredWeight )
450 direction1 = direction1.
Resize( 1 );
453 double D = sqrt( weightSquared );
454 double ratio1 = ( R1 + R2 ) /
D;
455 double ratio2 = sqrt( 1 - ratio1 * ratio1 );
459 pc.
weight = sqrt( weightSquared2 );
461 pc.
a1 = p1 + direction1 * R1 * ratio1 + direction2 * R1 * ratio2;
462 pc.
a2 = p2 - direction1 * R2 * ratio1 - direction2 * R2 * ratio2;
466 pc.
a1 = p1 + direction1 * R1 * ratio1 - direction2 * R1 * ratio2;
467 pc.
a2 = p2 - direction1 * R2 * ratio1 + direction2 * R2 * ratio2;
483 switch( p1->GetType() )
485 case CREEP_SHAPE::TYPE::POINT:
AddNode( GRAPH_NODE::TYPE::POINT, p1, p1->GetPos() );
break;
486 case CREEP_SHAPE::TYPE::CIRCLE:
AddNode( GRAPH_NODE::TYPE::CIRCLE, p1, p1->GetPos() );
break;
487 case CREEP_SHAPE::TYPE::ARC:
AddNode( GRAPH_NODE::TYPE::ARC, p1, p1->GetPos() );
break;
497 std::vector<CREEP_SHAPE*> newVector;
583 double tolerance = 10;
614 if(
n1->m_type == GRAPH_NODE::TYPE::VIRTUAL ||
n2->m_type == GRAPH_NODE::TYPE::VIRTUAL )
618 &&
n1->m_parent ==
n2->m_parent
619 &&
n1->m_parent->GetType() == CREEP_SHAPE::TYPE::CIRCLE )
626 if( R1.
Cross( R2 ) > 0 )
638 aShapes.push_back( s );
643 &&
n1->m_parent ==
n2->m_parent
644 &&
n1->m_parent->GetType() == CREEP_SHAPE::TYPE::ARC )
653 if( R1.
Cross( R2 ) > 0 )
668 EDA_ANGLE midAngle = arc->AngleBetweenStartAndEnd( mid );
670 if( midAngle > arc->GetEndAngle() )
679 aShapes.push_back( s );
687 aShapes.push_back( s );
718 EDA_ANGLE maxAngle = angle1 > angle2 ? angle1 : angle2;
721 skipAngle += skipAngle;
722 EDA_ANGLE pointAngle = maxAngle - skipAngle;
732 pc.
a1 = maxAngle == angle2 ? a1->m_pos : a2->m_pos;
738 pc.
a2 = maxAngle == angle2 ? a2->m_pos : a1->m_pos;
741 std::shared_ptr<GRAPH_CONNECTION> gc = aG.
AddConnection( gnt, maxAngle == angle2 ? a2 : a1, pc );
744 gc->m_forceStraightLine =
true;
757 VECTOR2D distI( a1->m_pos - a2->m_pos );
758 VECTOR2D distD(
double( distI.
x ),
double( distI.
y ) );
770 pc.
weight = std::max( weight, 0.0 );
791 double weight = abs(
m_radius * ( angle2 - angle1 ).AsRadians() );
820 double aMaxSquaredWeight )
const
822 std::vector<PATH_CONNECTION>
result;
825 double halfWidth = this->
GetWidth() / 2;
829 double length = ( start -
end ).EuclideanNorm();
830 double projectedPos = cos( trackAngle.
AsRadians() ) * ( pointPos.
x - start.
x )
831 + sin( trackAngle.
AsRadians() ) * ( pointPos.
y - start.
y );
835 if( projectedPos <= 0 )
837 newPoint = start + ( pointPos - start ).Resize( halfWidth );
839 else if( projectedPos >= length )
841 newPoint =
end + ( pointPos -
end ).Resize( halfWidth );
845 double posOnSegment = ( start - pointPos ).SquaredEuclideanNorm()
846 - (
end - pointPos ).SquaredEuclideanNorm();
847 posOnSegment = posOnSegment / ( 2 * length ) + length / 2;
849 newPoint = start + (
end - start ).Resize( posOnSegment );
850 newPoint += ( pointPos - newPoint ).Resize( halfWidth );
853 double weightSquared = ( pointPos - newPoint ).SquaredEuclideanNorm();
855 if( weightSquared > aMaxSquaredWeight )
861 pc.
weight = sqrt( weightSquared );
869 double aMaxSquaredWeight )
const
871 std::vector<PATH_CONNECTION>
result;
874 double halfWidth = this->
GetWidth() / 2;
878 double length = ( start -
end ).EuclideanNorm();
881 double weightSquared = std::numeric_limits<double>::infinity();
882 VECTOR2I PointOnTrack, PointOnCircle;
886 double projectedPos1 = cos( trackAngle.
AsRadians() ) * ( circleCenter.
x - start.
x )
887 + sin( trackAngle.
AsRadians() ) * ( circleCenter.
y - start.
y );
888 double projectedPos2 = projectedPos1 + circleRadius;
889 projectedPos1 = projectedPos1 - circleRadius;
891 double trackSide = (
end - start ).Cross( circleCenter - start ) > 0 ? 1 : -1;
893 if( ( projectedPos1 < 0 && projectedPos2 < 0 ) )
901 else if( ( projectedPos1 > length && projectedPos2 > length ) )
909 else if( ( projectedPos1 >= 0 ) && ( projectedPos1 <= length ) && ( projectedPos2 >= 0 )
910 && ( projectedPos2 <= length ) )
913 PointOnTrack = start;
914 PointOnTrack += (
end - start ).Resize( projectedPos1 );
915 PointOnTrack += (
end - start ).Perpendicular().
Resize( halfWidth ) * trackSide;
916 PointOnCircle = circleCenter - (
end - start ).Resize( circleRadius );
917 weightSquared = ( PointOnCircle - PointOnTrack ).SquaredEuclideanNorm();
919 if( weightSquared < aMaxSquaredWeight )
922 pc.
a1 = PointOnTrack;
923 pc.
a2 = PointOnCircle;
924 pc.
weight = sqrt( weightSquared );
928 PointOnTrack = start;
929 PointOnTrack += (
end - start ).Resize( projectedPos2 );
930 PointOnTrack += (
end - start ).Perpendicular().
Resize( halfWidth ) * trackSide;
931 PointOnCircle = circleCenter + (
end - start ).Resize( circleRadius );
934 pc.
a1 = PointOnTrack;
935 pc.
a2 = PointOnCircle;
940 else if( ( ( projectedPos1 >= 0 ) && ( projectedPos1 <= length ) )
941 && ( ( projectedPos2 > length ) || projectedPos2 < 0 ) )
944 std::vector<PATH_CONNECTION> pcs = csc.
Paths( aS2, aMaxWeight, aMaxSquaredWeight );
949 result.push_back( pcs.at( trackSide == 1 ? 1 : 0 ) );
952 PointOnTrack = start;
953 PointOnTrack += (
end - start ).Resize( projectedPos1 );
954 PointOnTrack += (
end - start ).Perpendicular().
Resize( halfWidth ) * trackSide;
955 PointOnCircle = circleCenter - (
end - start ).Resize( circleRadius );
956 weightSquared = ( PointOnCircle - PointOnTrack ).SquaredEuclideanNorm();
958 if( weightSquared < aMaxSquaredWeight )
961 pc.
a1 = PointOnTrack;
962 pc.
a2 = PointOnCircle;
963 pc.
weight = sqrt( weightSquared );
968 else if( ( ( projectedPos2 >= 0 ) && ( projectedPos2 <= length ) )
969 && ( ( projectedPos1 > length ) || projectedPos1 < 0 ) )
972 std::vector<PATH_CONNECTION> pcs = csc.
Paths( aS2, aMaxWeight, aMaxSquaredWeight );
977 result.push_back( pcs.at( trackSide == 1 ? 0 : 1 ) );
979 PointOnTrack = start;
980 PointOnTrack += (
end - start ).Resize( projectedPos2 );
981 PointOnTrack += (
end - start ).Perpendicular().
Resize( halfWidth ) * trackSide;
982 PointOnCircle = circleCenter + (
end - start ).Resize( circleRadius );
983 weightSquared = ( PointOnCircle - PointOnTrack ).SquaredEuclideanNorm();
985 if( weightSquared < aMaxSquaredWeight )
988 pc.
a1 = PointOnTrack;
989 pc.
a2 = PointOnCircle;
990 pc.
weight = sqrt( weightSquared );
1001 double aMaxSquaredWeight )
const
1003 std::vector<PATH_CONNECTION>
result;
1027 if( !
segmentIntersectsArc( pc.a1, pc.a2, beArcPos, beArcRadius, beArcStartAngle, beArcEndAngle ) )
1033 if( !
segmentIntersectsArc( pc.a1, pc.a2, beArcPos, beArcRadius, beArcStartAngle, beArcEndAngle ) )
1043 double aMaxSquaredWeight )
const
1045 std::vector<PATH_CONNECTION>
result;
1068 if( !
segmentIntersectsArc( pc.a1, pc.a2, beArcPos, beArcRadius, beArcStartAngle, beArcEndAngle ) )
1074 if( !
segmentIntersectsArc( pc.a1, pc.a2, beArcPos, beArcRadius, beArcStartAngle, beArcEndAngle ) )
1084 double aMaxSquaredWeight )
const
1086 std::vector<PATH_CONNECTION>
result;
1115 double aMaxSquaredWeight )
const
1117 std::vector<PATH_CONNECTION>
result;
1140 if( !
segmentIntersectsArc( pc.a1, pc.a2, beArcPos, beArcRadius, beArcStartAngle, beArcEndAngle ) )
1146 if( !
segmentIntersectsArc( pc.a1, pc.a2, beArcPos, beArcRadius, beArcStartAngle, beArcEndAngle ) )
1156 double aMaxSquaredWeight )
const
1158 std::vector<PATH_CONNECTION>
result;
1163 double weight = (
center - point ).EuclideanNorm() - R;
1165 if( weight > aMaxWeight )
1169 pc.
weight = std::max( weight, 0.0 );
1179 double aMaxSquaredWeight )
const
1181 std::vector<PATH_CONNECTION>
result;
1188 if( ( C1 - C2 ).SquaredEuclideanNorm() < ( R1 - R2 ) * ( R1 - R2 ) )
1194 double weight = ( C1 - C2 ).EuclideanNorm() - R1 - R2;
1196 if( weight > aMaxWeight || weight < 0 )
1200 pc.
weight = std::max( weight, 0.0 );
1201 pc.
a1 = ( C2 - C1 ).Resize( R1 ) + C1;
1202 pc.
a2 = ( C1 - C2 ).Resize( R2 ) + C2;
1209 double aMaxSquaredWeight )
const
1211 std::vector<PATH_CONNECTION>
result;
1215 double halfWidth = this->
GetWidth() / 2;
1217 EDA_ANGLE trackAngle( s_end - s_start );
1220 double length = ( s_start - s_end ).EuclideanNorm();
1221 double projectedPos = cos( trackAngle.
AsRadians() ) * ( pointPos.
x - s_start.
x )
1222 + sin( trackAngle.
AsRadians() ) * ( pointPos.
y - s_start.
y );
1224 if( ( projectedPos <= 0 ) || ( s_start == s_end ) )
1227 return csc.
Paths( aS2, aMaxWeight, aMaxSquaredWeight );
1230 if( projectedPos >= length )
1233 return csc.
Paths( aS2, aMaxWeight, aMaxSquaredWeight );
1237 double trackSide = ( s_end - s_start ).Cross( pointPos - s_start ) > 0 ? 1 : -1;
1240 pc.
a1 = s_start + ( s_end - s_start ).Resize( projectedPos )
1241 + ( s_end - s_start ).Perpendicular().
Resize( halfWidth ) * trackSide;
1242 pc.
a2 = ( pc.
a1 - pointPos ).Resize(
radius ) + pointPos;
1243 pc.
weight = ( pc.
a2 - pc.
a1 ).SquaredEuclideanNorm();
1245 if( pc.
weight <= aMaxSquaredWeight )
1256 double aMaxSquaredWeight )
const
1258 std::vector<PATH_CONNECTION>
result;
1263 double circleRadius = this->
GetRadius();
1271 if( ( circlePos - arcPos ).EuclideanNorm() > arcRadius + circleRadius )
1273 const std::vector<PATH_CONNECTION>& pcs = this->
Paths( csc, aMaxWeight, aMaxSquaredWeight );
1275 if( pcs.size() == 1 )
1281 result.push_back( pcs[0] );
1293 std::vector<PATH_CONNECTION> pcs1 = this->
Paths( csc1, aMaxWeight, aMaxSquaredWeight );
1294 std::vector<PATH_CONNECTION> pcs2 = this->
Paths( csc2, aMaxWeight, aMaxSquaredWeight );
1298 if( !bestPath || ( ( bestPath->
weight > pc.weight ) && ( pc.weight > 0 ) ) )
1304 if( !bestPath || ( ( bestPath->
weight > pc.weight ) && ( pc.weight > 0 ) ) )
1312 if( ( circlePos - arcPos ).SquaredEuclideanNorm() < arcRadius * arcRadius )
1314 if( circlePos != arcPos )
1320 pc3.
weight = std::max( arcRadius - ( circlePos - arcPos ).EuclideanNorm() - circleRadius, 0.0 );
1321 pc3.
a1 = circlePos + ( circlePos - arcPos ).Resize( circleRadius );
1322 pc3.
a2 = arcPos + ( circlePos - arcPos ).Resize( arcRadius - aS2.
GetWidth() / 2 );
1330 if( bestPath && bestPath->
weight > 0 )
1332 result.push_back( *bestPath );
1340 double aMaxSquaredWeight )
const
1342 std::vector<PATH_CONNECTION>
result;
1346 double halfWidth1 = this->
GetWidth() / 2;
1350 double halfWidth2 = aS2.
GetWidth() / 2;
1355 std::vector<PATH_CONNECTION> pcs;
1356 pcs = this->
Paths( csc, aMaxWeight, aMaxSquaredWeight );
1358 if( pcs.size() < 1 )
1364 if( pcs.size() > 0 )
1366 circlePoint = pcs[0].a1;
1370 if( testAngle < aS2.
GetEndAngle() && pcs.size() > 0 )
1372 result.push_back( pcs[0] );
1382 if( !bestPath || ( bestPath->
weight > pc.weight ) )
1388 if( !bestPath || ( bestPath->
weight > pc.weight ) )
1397 if( !bestPath || ( bestPath->
weight > pc.weight ) )
1404 if( !bestPath || ( bestPath->
weight > pc.weight ) )
1409 result.push_back( *bestPath );
1428 t = std::max( 0.0, std::min( 1.0, t ) );
1430 return A + ( AB * t );
1436 double aMaxSquaredWeight )
const
1438 std::vector<PATH_CONNECTION>
result;
1442 double halfWidth1 = this->
GetWidth() / 2;
1447 double halfWidth2 = aS2.
GetWidth() / 2;
1455 double dist1 = ( P1 -
C ).SquaredEuclideanNorm();
1456 double dist2 = ( P2 -
D ).SquaredEuclideanNorm();
1457 double dist3 = ( P3 -
A ).SquaredEuclideanNorm();
1458 double dist4 = ( P4 -
B ).SquaredEuclideanNorm();
1461 double min_dist = dist1;
1465 if( dist2 < min_dist )
1472 if( dist3 < min_dist )
1479 if( dist4 < min_dist )
1488 pc.
a1 = closest1 + ( closest2 - closest1 ).Resize( halfWidth1 );
1489 pc.
a2 = closest2 + ( closest1 - closest2 ).Resize( halfWidth2 );
1490 pc.
weight = std::max( sqrt( min_dist ) - halfWidth1 - halfWidth2, 0.0 );
1492 if( pc.
weight <= aMaxWeight )
1500 double aMaxSquaredWeight )
const
1502 std::vector<PATH_CONNECTION>
result;
1508 double dist = ( center1 - center2 ).EuclideanNorm();
1510 if( dist > aMaxWeight || dist == 0 )
1513 double weight = sqrt( dist * dist - R2 * R2 ) - R1;
1514 double theta = asin( R2 / dist );
1515 double psi = acos( R2 / dist );
1517 if( weight > aMaxWeight )
1521 pc.
weight = std::max( weight, 0.0 );
1528 pStart =
VECTOR2I( R1 * cos( theta + circleAngle ), R1 * sin( theta + circleAngle ) );
1530 pEnd =
VECTOR2I( -R2 * cos( psi - circleAngle ), R2 * sin( psi - circleAngle ) );
1537 pStart =
VECTOR2I( R1 * cos( -theta + circleAngle ), R1 * sin( -theta + circleAngle ) );
1539 pEnd =
VECTOR2I( -R2 * cos( -psi - circleAngle ), R2 * sin( -psi - circleAngle ) );
1551 double aMaxSquaredWeight )
const
1553 std::vector<PATH_CONNECTION>
result;
1569 if( ( point - arcCenter ).SquaredEuclideanNorm() >
radius *
radius )
1572 return circle.Paths( aS2, aMaxWeight, aMaxSquaredWeight );
1577 pc.
weight = std::max( (
radius - width / 2 ) - ( point - arcCenter ).EuclideanNorm(), 0.0 );
1578 pc.
a1 = ( point - arcCenter ).Resize(
radius - width / 2 ) + arcCenter;
1591 if( ( point - this->
GetStartPoint() ).SquaredEuclideanNorm()
1592 > ( point - this->
GetEndPoint() ).SquaredEuclideanNorm() )
1602 return circle.Paths( aS2, aMaxWeight, aMaxSquaredWeight );
1608 double aMaxSquaredWeight )
const
1610 std::vector<PATH_CONNECTION>
result;
1619 bestPath.
weight = std::numeric_limits<double>::infinity();
1628 for(
const std::vector<PATH_CONNECTION>& pcs : { csc1.
Paths( csc2, aMaxWeight, aMaxSquaredWeight ),
1629 this->
Paths( csc2, aMaxWeight, aMaxSquaredWeight ),
1630 csc1.
Paths( aS2, aMaxWeight, aMaxSquaredWeight ) } )
1642 for(
const std::vector<PATH_CONNECTION>& pcs : { this->
Paths( csc5, aMaxWeight, aMaxSquaredWeight ),
1643 this->
Paths( csc6, aMaxWeight, aMaxSquaredWeight ),
1644 csc3.
Paths( aS2, aMaxWeight, aMaxSquaredWeight ),
1645 csc4.
Paths( aS2, aMaxWeight, aMaxSquaredWeight ) } )
1649 if( bestPath.
weight > pc.weight )
1654 if( bestPath.
weight != std::numeric_limits<double>::infinity() )
1655 result.push_back( bestPath );
1662 std::vector<VECTOR2I>* aIntersectPoints )
1664 SEG segment( p1, p2 );
1667 std::vector<VECTOR2I> intersectionPoints;
1672 std::visit( visitor, geom1 );
1674 if( aIntersectPoints )
1676 for(
VECTOR2I& point : intersectionPoints )
1677 aIntersectPoints->push_back( point );
1680 return intersectionPoints.size() > 0;
1684 const std::vector<BOARD_ITEM*>& aBe,
1685 const std::vector<const BOARD_ITEM*>& aDontTestAgainst,
1686 int aMinGrooveWidth )
1688 std::vector<VECTOR2I> intersectionPoints;
1689 bool TestGrooveWidth = aMinGrooveWidth > 0;
1693 if( count( aDontTestAgainst.begin(), aDontTestAgainst.end(), be ) > 0 )
1706 if( intersects && !TestGrooveWidth )
1719 bool intersects =
false;
1725 if( intersects && !TestGrooveWidth )
1735 if( points.size() < 2 )
1738 VECTOR2I prevPoint = points.back();
1740 bool intersects =
false;
1748 if( intersects && !TestGrooveWidth )
1761 if( intersects && !TestGrooveWidth )
1777 if( intersects && !TestGrooveWidth )
1788 if( intersectionPoints.size() <= 0 )
1791 if( intersectionPoints.size() % 2 != 0 )
1794 int minx = intersectionPoints[0].x;
1795 int maxx = intersectionPoints[0].x;
1796 int miny = intersectionPoints[0].y;
1797 int maxy = intersectionPoints[0].y;
1799 for(
const VECTOR2I& v : intersectionPoints )
1801 minx = v.x < minx ? v.x : minx;
1802 maxx = v.x > maxx ? v.x : maxx;
1803 miny = v.x < miny ? v.x : miny;
1804 maxy = v.x > maxy ? v.x : maxy;
1807 if( abs( maxx - minx ) > abs( maxy - miny ) )
1809 std::sort( intersectionPoints.begin(), intersectionPoints.end(),
1817 std::sort( intersectionPoints.begin(), intersectionPoints.end(),
1824 int GVSquared = aMinGrooveWidth * aMinGrooveWidth;
1826 for(
size_t i = 0; i < intersectionPoints.size(); i += 2 )
1828 if( intersectionPoints[i].SquaredDistance( intersectionPoints[i + 1] ) > GVSquared )
1838 double maxWeight = aMaxWeight;
1839 double maxWeightSquared = maxWeight * maxWeight;
1840 std::vector<PATH_CONNECTION>
result;
1859 if( cuarc1 && cuarc2 )
1860 return cuarc1->
Paths( *cuarc2, maxWeight, maxWeightSquared );
1861 if( cuarc1 && cucircle2 )
1862 return cuarc1->
Paths( *cucircle2, maxWeight, maxWeightSquared );
1863 if( cuarc1 && cusegment2 )
1864 return cuarc1->
Paths( *cusegment2, maxWeight, maxWeightSquared );
1865 if( cucircle1 && cuarc2 )
1866 return cucircle1->
Paths( *cuarc2, maxWeight, maxWeightSquared );
1867 if( cucircle1 && cucircle2 )
1868 return cucircle1->
Paths( *cucircle2, maxWeight, maxWeightSquared );
1869 if( cucircle1 && cusegment2 )
1870 return cucircle1->
Paths( *cusegment2, maxWeight, maxWeightSquared );
1871 if( cusegment1 && cuarc2 )
1872 return cusegment1->
Paths( *cuarc2, maxWeight, maxWeightSquared );
1873 if( cusegment1 && cucircle2 )
1874 return cusegment1->
Paths( *cucircle2, maxWeight, maxWeightSquared );
1875 if( cusegment1 && cusegment2 )
1876 return cusegment1->
Paths( *cusegment2, maxWeight, maxWeightSquared );
1881 if( cuarc1 && bearc2 )
1882 return cuarc1->
Paths( *bearc2, maxWeight, maxWeightSquared );
1883 if( cuarc1 && becircle2 )
1884 return cuarc1->
Paths( *becircle2, maxWeight, maxWeightSquared );
1885 if( cuarc1 && bepoint2 )
1886 return cuarc1->
Paths( *bepoint2, maxWeight, maxWeightSquared );
1887 if( cucircle1 && bearc2 )
1888 return cucircle1->
Paths( *bearc2, maxWeight, maxWeightSquared );
1889 if( cucircle1 && becircle2 )
1890 return cucircle1->
Paths( *becircle2, maxWeight, maxWeightSquared );
1891 if( cucircle1 && bepoint2 )
1892 return cucircle1->
Paths( *bepoint2, maxWeight, maxWeightSquared );
1893 if( cusegment1 && bearc2 )
1894 return cusegment1->
Paths( *bearc2, maxWeight, maxWeightSquared );
1895 if( cusegment1 && becircle2 )
1896 return cusegment1->
Paths( *becircle2, maxWeight, maxWeightSquared );
1897 if( cusegment1 && bepoint2 )
1898 return cusegment1->
Paths( *bepoint2, maxWeight, maxWeightSquared );
1902 if( cuarc2 && bearc1 )
1903 return bearc1->
Paths( *cuarc2, maxWeight, maxWeightSquared );
1904 if( cuarc2 && becircle1 )
1905 return becircle1->
Paths( *cuarc2, maxWeight, maxWeightSquared );
1906 if( cuarc2 && bepoint1 )
1907 return bepoint1->
Paths( *cuarc2, maxWeight, maxWeightSquared );
1908 if( cucircle2 && bearc1 )
1909 return bearc1->
Paths( *cucircle2, maxWeight, maxWeightSquared );
1910 if( cucircle2 && becircle1 )
1911 return becircle1->
Paths( *cucircle2, maxWeight, maxWeightSquared );
1912 if( cucircle2 && bepoint1 )
1913 return bepoint1->
Paths( *cucircle2, maxWeight, maxWeightSquared );
1914 if( cusegment2 && bearc1 )
1915 return bearc1->
Paths( *cusegment2, maxWeight, maxWeightSquared );
1916 if( cusegment2 && becircle1 )
1917 return becircle1->
Paths( *cusegment2, maxWeight, maxWeightSquared );
1918 if( cusegment2 && bepoint1 )
1919 return bepoint1->
Paths( *cusegment2, maxWeight, maxWeightSquared );
1924 if( bearc1 && bearc2 )
1925 return bearc1->
Paths( *bearc2, maxWeight, maxWeightSquared );
1926 if( bearc1 && becircle2 )
1927 return bearc1->
Paths( *becircle2, maxWeight, maxWeightSquared );
1928 if( bearc1 && bepoint2 )
1929 return bearc1->
Paths( *bepoint2, maxWeight, maxWeightSquared );
1930 if( becircle1 && bearc2 )
1931 return becircle1->
Paths( *bearc2, maxWeight, maxWeightSquared );
1932 if( becircle1 && becircle2 )
1933 return becircle1->
Paths( *becircle2, maxWeight, maxWeightSquared );
1934 if( becircle1 && bepoint2 )
1935 return becircle1->
Paths( *bepoint2, maxWeight, maxWeightSquared );
1936 if( bepoint1 && bearc2 )
1937 return bepoint1->
Paths( *bearc2, maxWeight, maxWeightSquared );
1938 if( bepoint1 && becircle2 )
1939 return bepoint1->
Paths( *becircle2, maxWeight, maxWeightSquared );
1940 if( bepoint1 && bepoint2 )
1941 return bepoint1->
Paths( *bepoint2, maxWeight, maxWeightSquared );
1947 std::vector<std::shared_ptr<GRAPH_CONNECTION>>& aResult )
1949 if( !aFrom || !aTo )
1956 std::unordered_map<GRAPH_NODE*, double> distances;
1957 std::unordered_map<GRAPH_NODE*, GRAPH_NODE*> previous;
1961 double distLeft = distances[
left];
1962 double distRight = distances[
right];
1964 if( distLeft == distRight )
1966 return distLeft > distRight;
1968 std::priority_queue<GRAPH_NODE*, std::vector<GRAPH_NODE*>,
decltype( cmp )> pq( cmp );
1971 for(
const std::shared_ptr<GRAPH_NODE>& node :
m_nodes )
1973 if( node !=
nullptr )
1974 distances[node.get()] = std::numeric_limits<double>::infinity();
1977 distances[aFrom.get()] = 0.0;
1978 distances[aTo.get()] = std::numeric_limits<double>::infinity();
1979 pq.push( aFrom.get() );
1982 while( !pq.empty() )
1987 if( current == aTo.get() )
1993 for(
const std::shared_ptr<GRAPH_CONNECTION>& connection : current->
m_node_conns )
1995 GRAPH_NODE* neighbor = ( connection->n1 ).get() == current ? ( connection->n2 ).get()
1996 : ( connection->n1 ).get();
2002 if( connection->m_path.weight < 0.0 )
2004 wxLogTrace(
"CREEPAGE",
"Negative weight connection found. Ignoring connection." );
2008 double alt = distances[current] + connection->m_path.weight;
2010 if( alt < distances[neighbor] )
2012 distances[neighbor] = alt;
2013 previous[neighbor] = current;
2014 pq.push( neighbor );
2019 double pathWeight = distances[aTo.get()];
2022 if( pathWeight == std::numeric_limits<double>::infinity() )
2023 return std::numeric_limits<double>::infinity();
2028 while( step != aFrom.get() )
2032 for(
const std::shared_ptr<GRAPH_CONNECTION>& node_conn : step->
m_node_conns )
2034 if( ( ( node_conn->n1 ).get() == prevNode && ( node_conn->n2 ).get() == step )
2035 || ( ( node_conn->n1 ).get() == step && ( node_conn->n2 ).get() == prevNode ) )
2037 aResult.push_back( node_conn );
2055 switch( aShape.
Type() )
2070 newshape =
dynamic_cast<CREEP_SHAPE*
>( cucircle );
2085 start = arc.
GetP0();
2091 start = arc.
GetP1();
2106 int nbShapes =
static_cast<const SHAPE_COMPOUND*
>( &aShape )->Shapes().size();
2107 for(
const SHAPE* subshape : (
static_cast<const SHAPE_COMPOUND*
>( &aShape )->Shapes() ) )
2112 if( !( ( subshape->Type() ==
SH_RECT ) && ( nbShapes == 5 ) ) )
2113 Addshape( *subshape, aConnectTo, aParent );
2125 const SEG object = *it;
2127 Addshape( segment, aConnectTo, aParent );
2142 Addshape( segment, aConnectTo, aParent );
2171 std::shared_ptr<GRAPH_NODE> gnShape =
nullptr;
2175 switch( aShape.
Type() )
2186 gnShape->m_net = aConnectTo->m_net;
2187 std::shared_ptr<GRAPH_CONNECTION> gc =
AddConnection( gnShape, aConnectTo );
2190 gc->m_path.m_show =
false;
2201 std::vector<std::shared_ptr<GRAPH_NODE>> nodes;
2202 std::mutex nodes_lock;
2206 std::vector<CREEPAGE_TRACK_ENTRY*> trackEntries;
2214 std::shared_ptr<SHAPE> sh = track->GetEffectiveShape();
2219 entry->
segment =
SEG( track->GetStart(), track->GetEnd() );
2220 entry->
layer = aLayer;
2222 BOX2I bbox = track->GetBoundingBox();
2223 int minCoords[2] = { bbox.
GetX(), bbox.
GetY() };
2225 trackIndex.Insert( minCoords, maxCoords, entry );
2226 trackEntries.push_back( entry );
2232 std::copy_if(
m_nodes.begin(),
m_nodes.end(), std::back_inserter( nodes ),
2233 [&](
const std::shared_ptr<GRAPH_NODE>& gn )
2235 return gn && gn->m_parent && gn->m_connectDirectly && ( gn->m_type != GRAPH_NODE::TYPE::VIRTUAL );
2238 std::sort( nodes.begin(), nodes.end(),
2239 [](
const std::shared_ptr<GRAPH_NODE>& gn1,
const std::shared_ptr<GRAPH_NODE>& gn2 )
2241 return gn1->m_parent < gn2->m_parent
2242 || ( gn1->m_parent == gn2->m_parent && gn1->m_net < gn2->m_net );
2247 std::unordered_map<const BOARD_ITEM*, std::unordered_map<int, std::vector<std::shared_ptr<GRAPH_NODE>>>> parent_net_groups;
2248 std::unordered_map<const BOARD_ITEM*, BOX2I> parent_bboxes;
2249 std::vector<const BOARD_ITEM*> parent_keys;
2251 for(
const auto& gn : nodes )
2253 const BOARD_ITEM* parent = gn->m_parent->GetParent();
2255 if( parent_net_groups[parent].
empty() )
2257 parent_keys.push_back( parent );
2262 parent_net_groups[parent][gn->m_net].push_back( gn );
2266 std::vector<std::pair<std::shared_ptr<GRAPH_NODE>, std::shared_ptr<GRAPH_NODE>>> work_items;
2271 int64_t maxDist =
static_cast<int64_t
>( aMaxWeight );
2279 RTree<ParentEntry*, int, 2, double> parentIndex;
2280 std::vector<ParentEntry> parentEntries;
2283 for(
const auto* parent : parent_keys )
2288 entry.parent = parent;
2289 entry.bbox = parent_bboxes[parent];
2290 parentEntries.push_back( entry );
2295 for( ParentEntry& entry : parentEntries )
2297 int minCoords[2] = { entry.bbox.GetLeft(), entry.bbox.GetTop() };
2298 int maxCoords[2] = { entry.bbox.GetRight(), entry.bbox.GetBottom() };
2299 parentIndex.Insert( minCoords, maxCoords, &entry );
2303 std::mutex work_items_lock;
2305 auto searchParent = [&](
size_t i ) ->
bool
2307 const ParentEntry& entry1 = parentEntries[i];
2309 BOX2I bbox1 = entry1.bbox;
2311 std::vector<std::pair<std::shared_ptr<GRAPH_NODE>, std::shared_ptr<GRAPH_NODE>>> localWorkItems;
2314 int searchMin[2] = { bbox1.
GetLeft() - (int) maxDist, bbox1.
GetTop() - (int) maxDist };
2315 int searchMax[2] = { bbox1.
GetRight() + (int) maxDist, bbox1.
GetBottom() + (int) maxDist };
2317 parentIndex.Search( searchMin, searchMax,
2318 [&]( ParentEntry* entry2 ) ->
bool
2323 if( parent1 >= parent2 )
2327 BOX2I bbox2 = entry2->bbox;
2329 int64_t bboxDistX = 0;
2335 int64_t bboxDistY = 0;
2341 int64_t bboxDistSq = bboxDistX * bboxDistX + bboxDistY * bboxDistY;
2342 if( bboxDistSq > maxDist * maxDist )
2346 auto it1 = parent_net_groups.find( parent1 );
2347 auto it2 = parent_net_groups.find( parent2 );
2349 if( it1 == parent_net_groups.end() || it2 == parent_net_groups.end() )
2352 for(
const auto& [net1, nodes1] : it1->second )
2354 for(
const auto& [net2, nodes2] : it2->second )
2357 if( net1 == net2 && !nodes1.empty() && !nodes2.empty() )
2359 if( nodes1[0]->m_parent->IsConductive()
2360 && nodes2[0]->m_parent->IsConductive() )
2364 for(
const auto& gn1 : nodes1 )
2366 for(
const auto& gn2 : nodes2 )
2368 VECTOR2I pos1 = gn1->m_parent->GetPos();
2369 VECTOR2I pos2 = gn2->m_parent->GetPos();
2370 int r1 = gn1->m_parent->GetRadius();
2371 int r2 = gn2->m_parent->GetRadius();
2373 int64_t centerDistSq = ( pos1 - pos2 ).SquaredEuclideanNorm();
2374 double threshold = aMaxWeight + r1 + r2;
2375 double thresholdSq = threshold * threshold;
2377 if( (
double) centerDistSq > thresholdSq )
2380 localWorkItems.push_back( { gn1, gn2 } );
2390 if( !localWorkItems.empty() )
2392 std::lock_guard<std::mutex> lock( work_items_lock );
2393 work_items.insert( work_items.end(), localWorkItems.begin(), localWorkItems.end() );
2400 if( parentEntries.size() > 100 &&
tp.get_tasks_total() <
tp.get_thread_count() - 4 )
2402 auto ret =
tp.submit_loop( 0, parentEntries.size(), searchParent );
2404 for(
auto& r : ret )
2412 for(
size_t i = 0; i < parentEntries.size(); ++i )
2421 for(
const auto& [parent, net_groups] : parent_net_groups )
2423 std::vector<std::shared_ptr<GRAPH_NODE>> sameParentNodes;
2425 for(
const auto& [net, nodeList] : net_groups )
2426 sameParentNodes.insert( sameParentNodes.end(), nodeList.begin(), nodeList.end() );
2428 for(
size_t i = 0; i < sameParentNodes.size(); i++ )
2430 for(
size_t j = i + 1; j < sameParentNodes.size(); j++ )
2432 auto& gn1 = sameParentNodes[i];
2433 auto& gn2 = sameParentNodes[j];
2436 if( gn1->m_parent == gn2->m_parent )
2440 if( gn1->m_parent->IsConductive() && gn2->m_parent->IsConductive()
2441 && gn1->m_net == gn2->m_net )
2446 VECTOR2I pos1 = gn1->m_parent->GetPos();
2447 VECTOR2I pos2 = gn2->m_parent->GetPos();
2448 int r1 = gn1->m_parent->GetRadius();
2449 int r2 = gn2->m_parent->GetRadius();
2451 int64_t centerDistSq = ( pos1 - pos2 ).SquaredEuclideanNorm();
2452 double threshold = aMaxWeight + r1 + r2;
2453 double thresholdSq = threshold * threshold;
2455 if( (
double) centerDistSq > thresholdSq )
2458 work_items.push_back( { gn1, gn2 } );
2463 auto processWorkItems =
2464 [&](
size_t idx ) ->
bool
2466 auto& [gn1, gn2] = work_items[idx];
2474 std::vector<const BOARD_ITEM*> IgnoreForTest;
2486 if( shape1->
GetType() == CREEP_SHAPE::TYPE::CIRCLE )
2487 IgnoreForTest.push_back( shape1->
GetParent() );
2489 if( shape2->
GetType() == CREEP_SHAPE::TYPE::CIRCLE )
2490 IgnoreForTest.push_back( shape2->
GetParent() );
2500 std::shared_ptr<GRAPH_NODE> connect1 = gn1, connect2 = gn2;
2501 std::lock_guard<std::mutex> lock( nodes_lock );
2504 if( gn1->m_parent->GetType() != CREEP_SHAPE::TYPE::POINT )
2507 gnt1->m_connectDirectly =
false;
2510 if( gn1->m_parent->IsConductive() )
2512 if( std::shared_ptr<GRAPH_CONNECTION> gc =
AddConnection( gn1, gnt1 ) )
2513 gc->m_path.m_show =
false;
2518 if( gn2->m_parent->GetType() != CREEP_SHAPE::TYPE::POINT )
2521 gnt2->m_connectDirectly =
false;
2524 if( gn2->m_parent->IsConductive() )
2526 if( std::shared_ptr<GRAPH_CONNECTION> gc =
AddConnection( gn2, gnt2 ) )
2527 gc->m_path.m_show =
false;
2539 if(
tp.get_tasks_total() >=
tp.get_thread_count() - 4 )
2541 for(
size_t ii = 0; ii < work_items.size(); ii++ )
2542 processWorkItems( ii );
2546 auto ret =
tp.submit_loop( 0, work_items.size(), processWorkItems );
2548 for(
size_t ii = 0; ii < ret.size(); ii++ )
2555 while( r.wait_for( std::chrono::milliseconds( 100 ) ) != std::future_status::ready ){}
2567 std::vector<std::shared_ptr<GRAPH_CONNECTION>> toRemove;
2570 for( std::shared_ptr<GRAPH_CONNECTION>& gc :
m_connections )
2572 if( gc && ( gc->m_path.weight > aWeightLimit ) )
2573 toRemove.push_back( gc );
2577 for(
const std::shared_ptr<GRAPH_CONNECTION>& gc : toRemove )
2587 for( std::shared_ptr<GRAPH_NODE> gn : { aGc->n1, aGc->n2 } )
2591 gn->m_node_conns.erase( aGc );
2593 if( gn->m_node_conns.empty() && aDelete )
2596 [&gn](
const std::shared_ptr<GRAPH_NODE>& node )
2598 return node.get() == gn.get();
2621 std::shared_ptr<GRAPH_NODE> gn =
FindNode( aType, parent, pos );
2626 gn = std::make_shared<GRAPH_NODE>( aType, parent, pos );
2636 std::shared_ptr<GRAPH_NODE> gn = std::make_shared<GRAPH_NODE>( GRAPH_NODE::TYPE::VIRTUAL,
nullptr );
2644 std::shared_ptr<GRAPH_NODE>& aN2,
2650 wxASSERT_MSG( ( aN1 != aN2 ),
"Creepage: a connection connects a node to itself" );
2652 std::shared_ptr<GRAPH_CONNECTION> gc = std::make_shared<GRAPH_CONNECTION>( aN1, aN2, aPc );
2654 aN1->m_node_conns.insert( gc );
2655 aN2->m_node_conns.insert( gc );
2662 std::shared_ptr<GRAPH_NODE>& aN2 )
2679 auto it =
m_nodeset.find( std::make_shared<GRAPH_NODE>( aType, aParent, aPos ) );
2692 virtualNode->m_net = aNetCode;
2696 for(
PAD*
pad : footprint->Pads() )
2698 if(
pad->GetNetCode() != aNetCode || !
pad->IsOnLayer( aLayer ) )
2701 if( std::shared_ptr<SHAPE> padShape =
pad->GetEffectiveShape( aLayer ) )
2708 if( track->GetNetCode() != aNetCode || !track->IsOnLayer( aLayer ) )
2711 if( std::shared_ptr<SHAPE> shape = track->GetEffectiveShape() )
2712 Addshape( *shape, virtualNode, track );
2718 if( zone->GetNetCode() != aNetCode || !zone->IsOnLayer( aLayer ) )
2721 if( std::shared_ptr<SHAPE> shape = zone->GetEffectiveShape( aLayer ) )
2722 Addshape( *shape, virtualNode, zone );
2725 const DRAWINGS drawings =
m_board.Drawings();
2729 if( drawing->IsConnected() )
2737 Addshape( *shape, virtualNode, bci );
Creepage: a board edge arc.
std::pair< bool, bool > IsThereATangentPassingThroughPoint(const BE_SHAPE_POINT aPoint) const
EDA_ANGLE GetStartAngle() const override
int GetRadius() const override
BE_SHAPE_ARC(VECTOR2I aPos, int aRadius, EDA_ANGLE aStartAngle, EDA_ANGLE aEndAngle, VECTOR2D aStartPoint, VECTOR2D aEndPoint)
VECTOR2I GetStartPoint() const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const override
EDA_ANGLE GetEndAngle() const override
VECTOR2I GetEndPoint() const override
EDA_ANGLE AngleBetweenStartAndEnd(const VECTOR2I aPoint) const
Creepage: a board edge circle.
int GetRadius() const override
BE_SHAPE_CIRCLE(VECTOR2I aPos=VECTOR2I(0, 0), int aRadius=0)
void ShortenChildDueToGV(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG, double aNormalWeight) const
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const override
Creepage: a board edge point.
BE_SHAPE_POINT(VECTOR2I aPos)
void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
constexpr coord_type GetY() const
constexpr coord_type GetX() const
constexpr coord_type GetLeft() const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
Represent basic circle geometry with utility geometry functions.
A graph with nodes and connections for creepage calculation.
std::shared_ptr< GRAPH_NODE > AddNode(GRAPH_NODE::TYPE aType, CREEP_SHAPE *aParent=nullptr, const VECTOR2I &aPos=VECTOR2I())
std::shared_ptr< GRAPH_CONNECTION > AddConnection(std::shared_ptr< GRAPH_NODE > &aN1, std::shared_ptr< GRAPH_NODE > &aN2, const PATH_CONNECTION &aPc)
void SetTarget(double aTarget)
double Solve(std::shared_ptr< GRAPH_NODE > &aFrom, std::shared_ptr< GRAPH_NODE > &aTo, std::vector< std::shared_ptr< GRAPH_CONNECTION > > &aResult)
void Addshape(const SHAPE &aShape, std::shared_ptr< GRAPH_NODE > &aConnectTo, BOARD_ITEM *aParent=nullptr)
std::vector< CREEP_SHAPE * > m_shapeCollection
void TransformEdgeToCreepShapes()
std::shared_ptr< GRAPH_NODE > AddNodeVirtual()
void TransformCreepShapesToNodes(std::vector< CREEP_SHAPE * > &aShapes)
void Trim(double aWeightLimit)
SHAPE_POLY_SET * m_boardOutline
void RemoveDuplicatedShapes()
std::vector< BOARD_ITEM * > m_boardEdge
double m_creepageTargetSquared
std::unordered_set< std::shared_ptr< GRAPH_NODE >, GraphNodeHash, GraphNodeEqual > m_nodeset
void GeneratePaths(double aMaxWeight, PCB_LAYER_ID aLayer)
std::vector< std::shared_ptr< GRAPH_NODE > > m_nodes
std::vector< std::shared_ptr< GRAPH_CONNECTION > > m_connections
std::shared_ptr< GRAPH_NODE > AddNetElements(int aNetCode, PCB_LAYER_ID aLayer, int aMaxCreepage)
void RemoveConnection(const std::shared_ptr< GRAPH_CONNECTION > &, bool aDelete=false)
std::shared_ptr< GRAPH_NODE > FindNode(GRAPH_NODE::TYPE aType, CREEP_SHAPE *aParent, const VECTOR2I &aPos)
A class used to represent the shapes for creepage calculation.
CREEP_SHAPE::TYPE GetType() const
void SetParent(BOARD_ITEM *aParent)
virtual int GetRadius() const
const BOARD_ITEM * GetParent() const
virtual void ConnectChildren(std::shared_ptr< GRAPH_NODE > &a1, std::shared_ptr< GRAPH_NODE > &a2, CREEPAGE_GRAPH &aG) const
Creepage: a conductive arc.
VECTOR2I GetStartPoint() const override
EDA_ANGLE AngleBetweenStartAndEnd(const VECTOR2I aPoint) const
VECTOR2I GetEndPoint() const override
EDA_ANGLE GetStartAngle() const override
CU_SHAPE_ARC(VECTOR2I aPos, double aRadius, EDA_ANGLE aStartAngle, EDA_ANGLE aEndAngle, VECTOR2D aStartPoint, VECTOR2D aEndPoint)
int GetRadius() const override
EDA_ANGLE GetEndAngle() const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
Creepage: a conductive circle.
int GetRadius() const override
CU_SHAPE_CIRCLE(VECTOR2I aPos, double aRadius=0)
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
Creepage: a conductive segment.
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
VECTOR2I GetStart() const
CU_SHAPE_SEGMENT(VECTOR2I aStart, VECTOR2I aEnd, double aWidth=0)
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
void SetCenter(const VECTOR2I &aCenter)
VECTOR2I getCenter() const
std::vector< VECTOR2I > GetPolyPoints() const
Duplicate the polygon outlines into a flat list of VECTOR2I points.
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetEnd(const VECTOR2I &aEnd)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
VECTOR2I GetArcMid() const
std::shared_ptr< GRAPH_NODE > n2
void GetShapes(std::vector< PCB_SHAPE > &aShapes)
std::shared_ptr< GRAPH_NODE > n1
std::set< std::shared_ptr< GRAPH_CONNECTION > > m_node_conns
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
const VECTOR2I & GetArcMid() const
int GetWidth() const override
const VECTOR2I & GetP1() const
const VECTOR2I & GetP0() const
SHAPE_TYPE Type() const
Return the type of the shape.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
CONST_SEGMENT_ITERATOR CIterateSegmentsWithHoles() const
Return an iterator object, for the aOutline-th outline in the set (with holes).
const VECTOR2I & GetPosition() const
const VECTOR2I GetSize() const
const SEG & GetSeg() const
int GetWidth() const override
An abstract shape on 2D plane.
constexpr extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
constexpr VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Handle a list of polygons defining a copper zone.
static bool empty(const wxTextEntryBase *aCtrl)
VECTOR2I closestPointOnSegment(const VECTOR2I &A, const VECTOR2I &B, const VECTOR2I &P)
bool SegmentIntersectsBoard(const VECTOR2I &aP1, const VECTOR2I &aP2, const std::vector< BOARD_ITEM * > &aBe, const std::vector< const BOARD_ITEM * > &aDontTestAgainst, int aMinGrooveWidth)
std::vector< PATH_CONNECTION > GetPaths(CREEP_SHAPE *aS1, CREEP_SHAPE *aS2, double aMaxWeight)
bool segmentIntersectsArc(const VECTOR2I &p1, const VECTOR2I &p2, const VECTOR2I ¢er, double radius, EDA_ANGLE startAngle, EDA_ANGLE endAngle, std::vector< VECTOR2I > *aIntersectionPoints=nullptr)
bool compareShapes(const CREEP_SHAPE *a, const CREEP_SHAPE *b)
bool segments_intersect(const VECTOR2I &p1, const VECTOR2I &q1, const VECTOR2I &p2, const VECTOR2I &q2, std::vector< VECTOR2I > &aIntersectionPoints)
bool areEquivalent(const CREEP_SHAPE *a, const CREEP_SHAPE *b)
bool segmentIntersectsCircle(const VECTOR2I &p1, const VECTOR2I &p2, const VECTOR2I ¢er, double radius, std::vector< VECTOR2I > *aIntersectPoints)
RTree< CREEPAGE_TRACK_ENTRY *, int, 2, double > TRACK_RTREE
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_360
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
std::variant< LINE, HALF_LINE, SEG, CIRCLE, SHAPE_ARC, BOX2I > INTERSECTABLE_GEOM
A variant type that can hold any of the supported geometry types for intersection calculations.
PCB_LAYER_ID
A quick note on layer IDs:
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
@ SH_POLY_SET
set of polygons (with holes, etc.)
@ SH_RECT
axis-aligned rectangle
@ SH_LINE_CHAIN
line chain (polyline)
@ SH_COMPOUND
compound shape, consisting of multiple simple shapes
A visitor that visits INTERSECTABLE_GEOM variant objects with another (which is held as state: m_othe...
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
wxString result
Test unit parsing edge cases and error handling.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::priority_thread_pool thread_pool
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D