26#include <unordered_set>
46#include <geometry/rtree.h>
56using TRACK_RTREE = RTree<CREEPAGE_TRACK_ENTRY*, int, 2, double>;
59 const std::vector<BOARD_ITEM*>& aBe,
60 const std::vector<const BOARD_ITEM*>& aDontTestAgainst,
61 int aMinGrooveWidth );
89 const std::vector<BOARD_ITEM*>& aBoardEdges,
90 const std::vector<const BOARD_ITEM*>& aIgnoreForTest,
SHAPE_POLY_SET* aOutline,
91 const std::pair<bool, bool>& aTestLocalConcavity,
int aMinGrooveWidth,
106 bool contained = aOutline->
Contains( midPoint, -1, tolerance )
112 if(
false && ( aTestLocalConcavity.first || aTestLocalConcavity.second ) )
116 double extendLine = 1000;
121 double extendPoly = 100;
132 if( aTestLocalConcavity.first && !aOutline->
Contains( a - dir, -1, 0 ) )
135 if( aTestLocalConcavity.second && !aOutline->
Contains( b + dir, -1, 0 ) )
147 int minX = std::min( (
int)
a1.x, (
int)
a2.x );
148 int minY = std::min( (
int)
a1.y, (
int)
a2.y );
149 int maxX = std::max( (
int)
a1.x, (
int)
a2.x );
150 int maxY = std::max( (
int)
a1.y, (
int)
a2.y );
152 int searchMin[2] = { minX, minY };
153 int searchMax[2] = { maxX, maxY };
155 bool intersects =
false;
157 aTrackIndex->Search( searchMin, searchMax,
160 if( entry && entry->
layer == aLayer )
184 std::shared_ptr<SHAPE> sh = track->GetEffectiveShape();
188 SEG segTrack( track->GetStart(), track->GetEnd() );
235 m_type = CREEP_SHAPE::TYPE::UNDEFINED;
250 virtual void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
253 std::vector<PATH_CONNECTION>
ReversePaths(
const std::vector<PATH_CONNECTION>& aV )
const
255 std::vector<PATH_CONNECTION> r;
256 r.reserve( aV.size() );
258 for(
const auto& pc : aV )
260 r.emplace_back( pc );
261 std::swap( r.back().a1, r.back().a2 );
268 double aMaxSquaredWeight )
const
270 std::vector<PATH_CONNECTION> a;
275 double aMaxSquaredWeight )
const
277 std::vector<PATH_CONNECTION> a;
282 double aMaxSquaredWeight )
const
284 std::vector<PATH_CONNECTION> a;
289 double aMaxSquaredWeight )
const
291 std::vector<PATH_CONNECTION> a;
296 double aMaxSquaredWeight )
const
298 std::vector<PATH_CONNECTION> a;
303 double aMaxSquaredWeight )
const
305 std::vector<PATH_CONNECTION> a;
310 double aMaxSquaredWeight )
const
312 std::vector<PATH_CONNECTION> a;
375 double aMaxSquaredWeight )
const override;
377 double aMaxSquaredWeight )
const override;
379 double aMaxSquaredWeight )
const override;
381 double aMaxSquaredWeight )
const override;
383 double aMaxSquaredWeight )
const override;
385 double aMaxSquaredWeight )
const override;
412 double aMaxSquaredWeight )
const override;
414 double aMaxSquaredWeight )
const override;
416 double aMaxSquaredWeight )
const override;
418 double aMaxSquaredWeight )
const override
424 double aMaxSquaredWeight )
const override;
426 double aMaxSquaredWeight )
const override;
448 m_type = CREEP_SHAPE::TYPE::ARC;
453 double aMaxSquaredWeight )
const override;
456 double aMaxSquaredWeight )
const override;
459 double aMaxSquaredWeight )
const override;
462 double aMaxSquaredWeight )
const override
468 double aMaxSquaredWeight )
const override
474 double aMaxSquaredWeight )
const override;
565 void GetShapes( std::vector<PCB_SHAPE>& aShapes );
568 std::shared_ptr<GRAPH_NODE>
n1;
569 std::shared_ptr<GRAPH_NODE>
n2;
586 m_type = CREEP_SHAPE::TYPE::POINT;
590 double aMaxSquaredWeight )
const override;
593 double aMaxSquaredWeight )
const override;
596 double aMaxSquaredWeight )
const override;
599 double aMaxSquaredWeight )
const override
605 double aMaxSquaredWeight )
const override
611 double aMaxSquaredWeight )
const override
617 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
633 m_type = CREEP_SHAPE::TYPE::CIRCLE;
637 double aMaxSquaredWeight )
const override
643 double aMaxSquaredWeight )
const override;
646 double aMaxSquaredWeight )
const override;
649 double aMaxSquaredWeight )
const override
655 double aMaxSquaredWeight )
const override
663 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
666 void ShortenChildDueToGV( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
687 m_type = CREEP_SHAPE::TYPE::ARC;
690 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
695 double aMaxSquaredWeight )
const override
700 double aMaxSquaredWeight )
const override
705 double aMaxSquaredWeight )
const override;
708 double aMaxSquaredWeight )
const override
713 double aMaxSquaredWeight )
const override
718 double aMaxSquaredWeight )
const override
779 for( std::shared_ptr<GRAPH_NODE>& n :
m_nodes )
783 n->m_node_conns.clear();
805 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
806 std::shared_ptr<GRAPH_NODE>& aN2,
809 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
810 std::shared_ptr<GRAPH_NODE>& aN2 );
815 void RemoveConnection(
const std::shared_ptr<GRAPH_CONNECTION>&,
bool aDelete =
false );
817 void Trim(
double aWeightLimit );
819 void Addshape(
const SHAPE& aShape, std::shared_ptr<GRAPH_NODE>& aConnectTo,
822 double Solve( std::shared_ptr<GRAPH_NODE>& aFrom, std::shared_ptr<GRAPH_NODE>& aTo,
823 std::vector<std::shared_ptr<GRAPH_CONNECTION>>& aResult );
834 std::size_t
operator()(
const std::shared_ptr<GRAPH_NODE>& node)
const
836 return hash_val(node->m_type, node->m_parent, node->m_pos.x, node->m_pos.y);
842 bool operator()(
const std::shared_ptr<GRAPH_NODE>& lhs,
const std::shared_ptr<GRAPH_NODE>& rhs)
const
844 return lhs->m_type == rhs->m_type && lhs->m_parent == rhs->m_parent && lhs->m_pos == rhs->m_pos;
852 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)
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
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())
bool Intersects(const SEG &aSeg) const
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.
bool SegmentIntersectsBoard(const VECTOR2I &aP1, const VECTOR2I &aP2, const std::vector< BOARD_ITEM * > &aBe, const std::vector< const BOARD_ITEM * > &aDontTestAgainst, int aMinGrooveWidth)
RTree< CREEPAGE_TRACK_ENTRY *, int, 2, double > TRACK_RTREE
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 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