27#include <unordered_set>
63 const std::vector<BOARD_ITEM*>& aBe,
64 const std::vector<const BOARD_ITEM*>& aDontTestAgainst,
65 int aMinGrooveWidth );
93 const std::vector<BOARD_ITEM*>& aBoardEdges,
94 const std::vector<const BOARD_ITEM*>& aIgnoreForTest,
SHAPE_POLY_SET* aOutline,
95 const std::pair<bool, bool>& aTestLocalConcavity,
int aMinGrooveWidth,
110 bool contained = aOutline->
Contains( midPoint, -1, tolerance )
116 if(
false && ( aTestLocalConcavity.first || aTestLocalConcavity.second ) )
120 double extendLine = 1000;
125 double extendPoly = 100;
136 if( aTestLocalConcavity.first && !aOutline->
Contains( a - dir, -1, 0 ) )
139 if( aTestLocalConcavity.second && !aOutline->
Contains( b + dir, -1, 0 ) )
155 constexpr int interiorTolerance = 100;
157 auto endpointInside = [&](
const SEG& segTrack,
int halfWidth ) ->
bool
165 int minX = std::min( (
int)
a1.x, (
int)
a2.x );
166 int minY = std::min( (
int)
a1.y, (
int)
a2.y );
167 int maxX = std::max( (
int)
a1.x, (
int)
a2.x );
168 int maxY = std::max( (
int)
a1.y, (
int)
a2.y );
170 int searchMin[2] = { minX, minY };
171 int searchMax[2] = { maxX, maxY };
177 if( !entry || entry->layer != aLayer )
187 && endpointInside( entry->segment, entry->halfWidth ) )
196 aTrackIndex->Search( searchMin, searchMax, trackVisitor );
206 || !track->IsOnLayer( aLayer ) )
211 std::shared_ptr<SHAPE> sh = track->GetEffectiveShape();
216 SEG segTrack( track->GetStart(), track->GetEnd() );
222 && endpointInside( segTrack, track->GetWidth() / 2 ) )
267 m_type = CREEP_SHAPE::TYPE::UNDEFINED;
282 virtual void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
285 std::vector<PATH_CONNECTION>
ReversePaths(
const std::vector<PATH_CONNECTION>& aV )
const
287 std::vector<PATH_CONNECTION> r;
288 r.reserve( aV.size() );
290 for(
const auto& pc : aV )
292 r.emplace_back( pc );
293 std::swap( r.back().a1, r.back().a2 );
300 double aMaxSquaredWeight )
const
302 std::vector<PATH_CONNECTION> a;
307 double aMaxSquaredWeight )
const
309 std::vector<PATH_CONNECTION> a;
314 double aMaxSquaredWeight )
const
316 std::vector<PATH_CONNECTION> a;
321 double aMaxSquaredWeight )
const
323 std::vector<PATH_CONNECTION> a;
328 double aMaxSquaredWeight )
const
330 std::vector<PATH_CONNECTION> a;
335 double aMaxSquaredWeight )
const
337 std::vector<PATH_CONNECTION> a;
342 double aMaxSquaredWeight )
const
344 std::vector<PATH_CONNECTION> a;
400 m_pos = ( aStart + aEnd ) / 2;
413 double aMaxSquaredWeight )
const override;
415 double aMaxSquaredWeight )
const override;
417 double aMaxSquaredWeight )
const override;
419 double aMaxSquaredWeight )
const override;
421 double aMaxSquaredWeight )
const override;
423 double aMaxSquaredWeight )
const override;
449 double aMaxSquaredWeight )
const override;
451 double aMaxSquaredWeight )
const override;
453 double aMaxSquaredWeight )
const override;
455 double aMaxSquaredWeight )
const override
461 double aMaxSquaredWeight )
const override;
463 double aMaxSquaredWeight )
const override;
484 m_type = CREEP_SHAPE::TYPE::ARC;
489 double aMaxSquaredWeight )
const override;
492 double aMaxSquaredWeight )
const override;
495 double aMaxSquaredWeight )
const override;
498 double aMaxSquaredWeight )
const override
504 double aMaxSquaredWeight )
const override
510 double aMaxSquaredWeight )
const override;
601 void GetShapes( std::vector<PCB_SHAPE>& aShapes );
604 std::shared_ptr<GRAPH_NODE>
n1;
605 std::shared_ptr<GRAPH_NODE>
n2;
622 m_type = CREEP_SHAPE::TYPE::POINT;
626 double aMaxSquaredWeight )
const override;
629 double aMaxSquaredWeight )
const override;
632 double aMaxSquaredWeight )
const override;
635 double aMaxSquaredWeight )
const override
641 double aMaxSquaredWeight )
const override
647 double aMaxSquaredWeight )
const override
653 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
669 m_type = CREEP_SHAPE::TYPE::CIRCLE;
673 double aMaxSquaredWeight )
const override
679 double aMaxSquaredWeight )
const override;
682 double aMaxSquaredWeight )
const override;
685 double aMaxSquaredWeight )
const override
691 double aMaxSquaredWeight )
const override
699 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
702 void ShortenChildDueToGV( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
723 m_type = CREEP_SHAPE::TYPE::ARC;
726 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
731 double aMaxSquaredWeight )
const override
736 double aMaxSquaredWeight )
const override
741 double aMaxSquaredWeight )
const override;
744 double aMaxSquaredWeight )
const override
749 double aMaxSquaredWeight )
const override
754 double aMaxSquaredWeight )
const override
815 for( std::shared_ptr<GRAPH_NODE>& n :
m_nodes )
819 n->m_node_conns.clear();
841 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
842 std::shared_ptr<GRAPH_NODE>& aN2,
845 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
846 std::shared_ptr<GRAPH_NODE>& aN2 );
851 void RemoveConnection(
const std::shared_ptr<GRAPH_CONNECTION>&,
bool aDelete =
false );
853 void Trim(
double aWeightLimit );
855 void Addshape(
const SHAPE& aShape, std::shared_ptr<GRAPH_NODE>& aConnectTo,
858 double Solve( std::shared_ptr<GRAPH_NODE>& aFrom, std::shared_ptr<GRAPH_NODE>& aTo,
859 std::vector<std::shared_ptr<GRAPH_CONNECTION>>& aResult );
870 std::size_t
operator()(
const std::shared_ptr<GRAPH_NODE>& node)
const
872 return hash_val(node->m_type, node->m_parent, node->m_pos.x, node->m_pos.y);
878 bool operator()(
const std::shared_ptr<GRAPH_NODE>& lhs,
const std::shared_ptr<GRAPH_NODE>& rhs)
const
880 return lhs->m_type == rhs->m_type && lhs->m_parent == rhs->m_parent && lhs->m_pos == rhs->m_pos;
889 std::vector<std::shared_ptr<GRAPH_NODE>>
m_nodes;
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)
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
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
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) 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 CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) 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
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 CU_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const override
Creepage: a board edge shape.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
const TRACKS & Tracks() const
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
CREEPAGE_GRAPH(BOARD &aBoard)
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)
std::vector< std::unique_ptr< PCB_SHAPE > > m_ownedBoardEdges
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.
virtual VECTOR2I GetStartPoint() const
virtual std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_POINT &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const
CREEP_SHAPE::TYPE GetType() const
std::vector< PATH_CONNECTION > Paths(const CREEP_SHAPE &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual EDA_ANGLE GetEndAngle() const
void SetParent(BOARD_ITEM *aParent)
virtual std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_ARC &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual std::vector< PATH_CONNECTION > Paths(const BE_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const
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
virtual std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) const
virtual EDA_ANGLE GetStartAngle() const
virtual VECTOR2I GetEndPoint() const
virtual std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) const
std::vector< PATH_CONNECTION > ReversePaths(const std::vector< PATH_CONNECTION > &aV) const
Creepage: a conductive arc.
VECTOR2I GetStartPoint() const override
EDA_ANGLE AngleBetweenStartAndEnd(const VECTOR2I aPoint) const
VECTOR2I GetEndPoint() const override
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_CIRCLE &aS2, double aMaxWeight, double aMaxSquaredWeight) 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 CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) 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
std::vector< PATH_CONNECTION > Paths(const CU_SHAPE_SEGMENT &aS2, double aMaxWeight, double aMaxSquaredWeight) 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
int GetRadius() const override
VECTOR2I GetStart() const
CU_SHAPE_SEGMENT(VECTOR2I aStart, VECTOR2I aEnd, double aWidth=0)
Creepage: a conductive shape.
std::shared_ptr< GRAPH_NODE > n2
void GetShapes(std::vector< PCB_SHAPE > &aShapes)
std::shared_ptr< GRAPH_NODE > n1
GRAPH_CONNECTION(std::shared_ptr< GRAPH_NODE > &aN1, std::shared_ptr< GRAPH_NODE > &aN2, const PATH_CONNECTION &aPc)
std::set< std::shared_ptr< GRAPH_CONNECTION > > m_node_conns
GRAPH_NODE(GRAPH_NODE::TYPE aType, CREEP_SHAPE *aParent, const VECTOR2I &aPos=VECTOR2I())
Static (immutable) packed R-tree built via Hilbert-curve bulk loading.
bool Intersects(const SEG &aSeg) const
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Represent a set of closed polygons.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
bool PointOnEdge(const VECTOR2I &aP, int aAccuracy=0) const
Check if point aP lies on an edge or vertex of some of the outlines or holes.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
An abstract shape on 2D plane.
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
@ ROUND_ALL_CORNERS
All angles are rounded.
KIRTREE::PACKED_RTREE< CREEPAGE_TRACK_ENTRY *, int, 2 > TRACK_RTREE
bool SegmentIntersectsBoard(const VECTOR2I &aP1, const VECTOR2I &aP2, const std::vector< BOARD_ITEM * > &aBe, const std::vector< const BOARD_ITEM * > &aDontTestAgainst, int aMinGrooveWidth)
static constexpr EDA_ANGLE ANGLE_360
static constexpr std::size_t hash_val(const Types &... args)
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
bool operator()(const std::shared_ptr< GRAPH_NODE > &lhs, const std::shared_ptr< GRAPH_NODE > &rhs) const
std::size_t operator()(const std::shared_ptr< GRAPH_NODE > &node) const
bool isValid(const BOARD &aBoard, PCB_LAYER_ID aLayer, const std::vector< BOARD_ITEM * > &aBoardEdges, const std::vector< const BOARD_ITEM * > &aIgnoreForTest, SHAPE_POLY_SET *aOutline, const std::pair< bool, bool > &aTestLocalConcavity, int aMinGrooveWidth, TRACK_RTREE *aTrackIndex=nullptr) const
Test if a path is valid.
bool m_forceA2concavityCheck
bool m_forceA1concavityCheck
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D