27#include <unordered_set>
47#include <geometry/rtree.h>
57using TRACK_RTREE = RTree<CREEPAGE_TRACK_ENTRY*, int, 2, double>;
60 const std::vector<BOARD_ITEM*>& aBe,
61 const std::vector<const BOARD_ITEM*>& aDontTestAgainst,
62 int aMinGrooveWidth );
90 const std::vector<BOARD_ITEM*>& aBoardEdges,
91 const std::vector<const BOARD_ITEM*>& aIgnoreForTest,
SHAPE_POLY_SET* aOutline,
92 const std::pair<bool, bool>& aTestLocalConcavity,
int aMinGrooveWidth,
107 bool contained = aOutline->
Contains( midPoint, -1, tolerance )
113 if(
false && ( aTestLocalConcavity.first || aTestLocalConcavity.second ) )
117 double extendLine = 1000;
122 double extendPoly = 100;
133 if( aTestLocalConcavity.first && !aOutline->
Contains( a - dir, -1, 0 ) )
136 if( aTestLocalConcavity.second && !aOutline->
Contains( b + dir, -1, 0 ) )
148 int minX = std::min( (
int)
a1.x, (
int)
a2.x );
149 int minY = std::min( (
int)
a1.y, (
int)
a2.y );
150 int maxX = std::max( (
int)
a1.x, (
int)
a2.x );
151 int maxY = std::max( (
int)
a1.y, (
int)
a2.y );
153 int searchMin[2] = { minX, minY };
154 int searchMax[2] = { maxX, maxY };
156 bool intersects =
false;
158 aTrackIndex->Search( searchMin, searchMax,
161 if( entry && entry->
layer == aLayer )
185 std::shared_ptr<SHAPE> sh = track->GetEffectiveShape();
189 SEG segTrack( track->GetStart(), track->GetEnd() );
236 m_type = CREEP_SHAPE::TYPE::UNDEFINED;
251 virtual void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
254 std::vector<PATH_CONNECTION>
ReversePaths(
const std::vector<PATH_CONNECTION>& aV )
const
256 std::vector<PATH_CONNECTION> r;
257 r.reserve( aV.size() );
259 for(
const auto& pc : aV )
261 r.emplace_back( pc );
262 std::swap( r.back().a1, r.back().a2 );
269 double aMaxSquaredWeight )
const
271 std::vector<PATH_CONNECTION> a;
276 double aMaxSquaredWeight )
const
278 std::vector<PATH_CONNECTION> a;
283 double aMaxSquaredWeight )
const
285 std::vector<PATH_CONNECTION> a;
290 double aMaxSquaredWeight )
const
292 std::vector<PATH_CONNECTION> a;
297 double aMaxSquaredWeight )
const
299 std::vector<PATH_CONNECTION> a;
304 double aMaxSquaredWeight )
const
306 std::vector<PATH_CONNECTION> a;
311 double aMaxSquaredWeight )
const
313 std::vector<PATH_CONNECTION> a;
369 m_pos = ( aStart + aEnd ) / 2;
382 double aMaxSquaredWeight )
const override;
384 double aMaxSquaredWeight )
const override;
386 double aMaxSquaredWeight )
const override;
388 double aMaxSquaredWeight )
const override;
390 double aMaxSquaredWeight )
const override;
392 double aMaxSquaredWeight )
const override;
419 double aMaxSquaredWeight )
const override;
421 double aMaxSquaredWeight )
const override;
423 double aMaxSquaredWeight )
const override;
425 double aMaxSquaredWeight )
const override
431 double aMaxSquaredWeight )
const override;
433 double aMaxSquaredWeight )
const override;
455 m_type = CREEP_SHAPE::TYPE::ARC;
460 double aMaxSquaredWeight )
const override;
463 double aMaxSquaredWeight )
const override;
466 double aMaxSquaredWeight )
const override;
469 double aMaxSquaredWeight )
const override
475 double aMaxSquaredWeight )
const override
481 double aMaxSquaredWeight )
const override;
572 void GetShapes( std::vector<PCB_SHAPE>& aShapes );
575 std::shared_ptr<GRAPH_NODE>
n1;
576 std::shared_ptr<GRAPH_NODE>
n2;
593 m_type = CREEP_SHAPE::TYPE::POINT;
597 double aMaxSquaredWeight )
const override;
600 double aMaxSquaredWeight )
const override;
603 double aMaxSquaredWeight )
const override;
606 double aMaxSquaredWeight )
const override
612 double aMaxSquaredWeight )
const override
618 double aMaxSquaredWeight )
const override
624 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
640 m_type = CREEP_SHAPE::TYPE::CIRCLE;
644 double aMaxSquaredWeight )
const override
650 double aMaxSquaredWeight )
const override;
653 double aMaxSquaredWeight )
const override;
656 double aMaxSquaredWeight )
const override
662 double aMaxSquaredWeight )
const override
670 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
673 void ShortenChildDueToGV( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
694 m_type = CREEP_SHAPE::TYPE::ARC;
697 void ConnectChildren( std::shared_ptr<GRAPH_NODE>& a1, std::shared_ptr<GRAPH_NODE>& a2,
702 double aMaxSquaredWeight )
const override
707 double aMaxSquaredWeight )
const override
712 double aMaxSquaredWeight )
const override;
715 double aMaxSquaredWeight )
const override
720 double aMaxSquaredWeight )
const override
725 double aMaxSquaredWeight )
const override
786 for( std::shared_ptr<GRAPH_NODE>& n :
m_nodes )
790 n->m_node_conns.clear();
812 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
813 std::shared_ptr<GRAPH_NODE>& aN2,
816 std::shared_ptr<GRAPH_CONNECTION>
AddConnection( std::shared_ptr<GRAPH_NODE>& aN1,
817 std::shared_ptr<GRAPH_NODE>& aN2 );
822 void RemoveConnection(
const std::shared_ptr<GRAPH_CONNECTION>&,
bool aDelete =
false );
824 void Trim(
double aWeightLimit );
826 void Addshape(
const SHAPE& aShape, std::shared_ptr<GRAPH_NODE>& aConnectTo,
829 double Solve( std::shared_ptr<GRAPH_NODE>& aFrom, std::shared_ptr<GRAPH_NODE>& aTo,
830 std::vector<std::shared_ptr<GRAPH_CONNECTION>>& aResult );
841 std::size_t
operator()(
const std::shared_ptr<GRAPH_NODE>& node)
const
843 return hash_val(node->m_type, node->m_parent, node->m_pos.x, node->m_pos.y);
849 bool operator()(
const std::shared_ptr<GRAPH_NODE>& lhs,
const std::shared_ptr<GRAPH_NODE>& rhs)
const
851 return lhs->m_type == rhs->m_type && lhs->m_parent == rhs->m_parent && lhs->m_pos == rhs->m_pos;
860 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())
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