50 std::vector<PCB_TRACK*>* buffer;
54 buffer =
new std::vector<PCB_TRACK*>;
59 buffer = (*item).second;
62 buffer->push_back( aTrack );
71 return via->GetWidth( aLayer );
76 return std::min(
pad->GetSize( aLayer ).x,
pad->GetSize( aLayer ).y );
96 &&
pad->GetSize( aLayer ).x
97 ==
pad->GetSize( aLayer ).y );
124 if( zone->IsTeardropArea() )
128 if( !zone->IsOnLayer( layer ) )
131 if( zone->GetNetCode() != aTrack->
GetNetCode() )
135 if( !zone->HasFilledPolysForLayer( layer ) )
138 std::shared_ptr<SHAPE_POLY_SET> fill = zone->GetFilledPolysList( layer );
140 if( !fill || fill->IsEmpty() )
148 if( !fill->Contains( padPos ) )
152 if( !fill->Contains( aTrack->
GetStart() ) && !fill->Contains( aTrack->
GetEnd() ) )
158 PAD*
pad =
static_cast<PAD*
>( aPadOrVia );
184 return trackItem != aTrackRef;
189 PCB_TRACK* curr_track = static_cast<PCB_TRACK*>( trackItem );
192 if( EDA_ITEM_FLAGS match = curr_track->IsPointOnEnds( aEndPoint, m_tolerance ) )
199 double previous_len = candidate->GetLength();
200 double curr_len = curr_track->GetLength();
202 if( previous_len >= curr_len )
207 candidate = curr_track;
238 std::vector<VECTOR2I>& aPoly,
240 int aTrackHalfWidth,
const VECTOR2D& aTrackDir,
242 std::vector<VECTOR2I>& pts )
const
244 int maxError =
m_board->GetDesignSettings().m_MaxError;
264 double minVpercent = double( aTrackHalfWidth ) /
radius;
265 double weaken = (Vpercent - minVpercent) / ( 1 - minVpercent ) /
radius;
277 vecC = pts[2] - aOtherPos;
287 vecE = pts[4] - aOtherPos;
290 double biasBC = 0.5 *
SEG( pts[1], pts[2] ).
Length();
291 double biasAE = 0.5 *
SEG( pts[4], pts[0] ).
Length();
294 pts[2].y + vecC.
x * biasBC * weaken );
296 pts[4].y - vecE.
x * biasAE * weaken );
298 VECTOR2I tangentB =
VECTOR2I( pts[1].x - aTrackDir.
x * biasBC, pts[1].y - aTrackDir.
y * biasBC );
299 VECTOR2I tangentA =
VECTOR2I( pts[0].x - aTrackDir.
x * biasAE, pts[0].y - aTrackDir.
y * biasAE );
301 std::vector<VECTOR2I> curve_pts;
305 aPoly.push_back( corner );
307 aPoly.push_back( pts[3] );
313 aPoly.push_back( corner );
333 VECTOR2I radial = aAnchor - aCornerCenter;
345 int64_t dot1 =
static_cast<int64_t
>( tangent1.
x ) * aDesiredDir.
x
346 +
static_cast<int64_t
>( tangent1.
y ) * aDesiredDir.
y;
347 int64_t dot2 =
static_cast<int64_t
>( tangent2.
x ) * aDesiredDir.
x
348 +
static_cast<int64_t
>( tangent2.
y ) * aDesiredDir.
y;
350 VECTOR2I tangent = ( dot1 > dot2 ) ? tangent1 : tangent2;
372 VECTOR2I localPt = aPoint - aPadPos;
375 int halfW = aPadSize.
x / 2;
376 int halfH = aPadSize.
y / 2;
380 int radius = std::min( halfW, halfH );
381 bool isHorizontal = halfW > halfH;
386 int centerOffset = halfW -
radius;
389 if(
std::abs( localPt.
x ) <= centerOffset )
393 int centerX = ( localPt.
x > 0 ) ? centerOffset : -centerOffset;
394 aArcCenter =
VECTOR2I( centerX, 0 );
399 int centerOffset = halfH -
radius;
402 if(
std::abs( localPt.
y ) <= centerOffset )
406 int centerY = ( localPt.
y > 0 ) ? centerOffset : -centerOffset;
407 aArcCenter =
VECTOR2I( 0, centerY );
412 aArcCenter += aPadPos;
431 const VECTOR2I& aPadSize,
int aCornerRadius,
435 VECTOR2I localPt = aPoint - aPadPos;
439 int halfW = aPadSize.
x / 2;
440 int halfH = aPadSize.
y / 2;
441 int innerHalfW = halfW - aCornerRadius;
442 int innerHalfH = halfH - aCornerRadius;
445 bool inCornerX =
std::abs( localPt.
x ) > innerHalfW;
446 bool inCornerY =
std::abs( localPt.
y ) > innerHalfH;
448 if( !inCornerX || !inCornerY )
452 int cornerX = ( localPt.
x > 0 ) ? innerHalfW : -innerHalfW;
453 int cornerY = ( localPt.
y > 0 ) ? innerHalfH : -innerHalfH;
455 aCornerCenter =
VECTOR2I( cornerX, cornerY );
459 aCornerCenter += aPadPos;
471 std::vector<VECTOR2I>& aPoly,
int aTdWidth,
473 std::vector<VECTOR2I>& aPts,
479 int maxError =
m_board->GetDesignSettings().m_MaxError;
487 VECTOR2I side1( aPts[2] - aPts[1] );
489 VECTOR2I side2( aPts[4] - aPts[0] );
491 VECTOR2I trackDir( aIntersection - ( aPts[0] + aPts[1] ) / 2 );
494 bool isRoundRect =
false;
496 int cornerRadius = 0;
508 cornerRadius =
pad->GetRoundRectCornerRadius( aLayer );
509 padSize =
pad->GetSize( aLayer );
510 padRotation =
pad->GetOrientation();
515 padSize =
pad->GetSize( aLayer );
516 padRotation =
pad->GetOrientation();
520 std::vector<VECTOR2I> curve_pts;
530 ctrl2 = ( aPts[2] + aIntersection ) / 2;
532 if( isRoundRect && cornerRadius > 0 )
537 padRotation, cornerCenter ) )
548 if(
isPointOnOvalEnd( aPts[2], aOtherPos, padSize, padRotation, arcCenter ) )
559 aPoly.push_back( corner );
561 aPoly.push_back( aPts[3] );
567 ctrl1 = ( aPts[4] + aIntersection ) / 2;
569 if( isRoundRect && cornerRadius > 0 )
574 padRotation, cornerCenter ) )
585 if(
isPointOnOvalEnd( aPts[4], aOtherPos, padSize, padRotation, arcCenter ) )
598 aPoly.push_back( corner );
604 std::vector<VECTOR2I>& aPts )
const
606 int maxError =
m_board->GetDesignSettings().m_MaxError;
637 wxCHECK_MSG( aItem->
Type() ==
PCB_PAD_T,
false, wxT(
"Expected non-round item to be PAD" ) );
643 pad->TransformShapeToPolygon( c_buffer, aLayer, 0, maxError,
ERROR_INSIDE );
650 int halfsize = std::min( aParams.
m_TdMaxWidth, preferred_width )/2;
655 VECTOR2I ref_on_track = ( aPts[0] + aPts[1] ) / 2;
656 VECTOR2I teardrop_axis( aPts[3] - ref_on_track );
668 clipping_rect.
Append( 0, - halfsize );
669 clipping_rect.
Append( 0, halfsize );
670 clipping_rect.
Append( len, halfsize );
671 clipping_rect.
Append( len, - halfsize );
673 clipping_rect.
Rotate( -orient );
674 clipping_rect.
Move( ref_on_track );
687 std::vector<VECTOR2I> points = padpoly.
CPoints();
689 std::vector<VECTOR2I> initialPoints;
690 initialPoints.push_back( aPts[0] );
691 initialPoints.push_back( aPts[1] );
694 initialPoints.emplace_back( pt.x, pt.y );
696 std::vector<VECTOR2I> hull;
703 int found_start = -1;
709 for(
unsigned ii = 0, jj = 0; jj < hull.size(); ii++, jj++ )
711 unsigned next = ii+ 1;
713 if(
next >= hull.size() )
719 prev = hull.size()-1;
721 if( hull[ii] == start )
724 if( hull[
next] != pend )
732 if( hull[ii] == pend )
734 if( hull[
next] != start )
743 if( found_start < 0 )
745 int ii = found_end-1;
755 int ii = found_start-1;
772 double area1 = dummy1.
Area();
774 std::swap( aPts[2], aPts[4] );
776 double area2 = dummy2.
Area();
779 std::swap( aPts[2], aPts[4] );
789 int* aEffectiveTeardropLen )
const
796 int maxError =
m_board->GetDesignSettings().m_MaxError;
802 targetLength = std::min( aParams.
m_TdMaxLen, targetLength );
806 bool need_swap =
false;
810 if( !aOther->
HitTest( start, 0 ) )
812 std::swap( start,
end );
824 wxCHECK_MSG( aOther->
Type() ==
PCB_PAD_T,
false, wxT(
"Expected non-round item to be PAD" ) );
825 static_cast<PAD*
>( aOther )->TransformShapeToPolygon( shapebuffer, aTrack->
GetLayer(), 0,
845 pt_count = outline.
Intersect( poly, pts );
857 aIntersection = pts[0].p;
858 start = aIntersection;
862 actualTdLen = std::min( targetLength,
SEG( start,
end ).Length() );
871 while( actualTdLen + consumed < targetLength )
877 if( connected_track ==
nullptr )
881 consumed += actualTdLen;
883 actualTdLen = std::min( targetLength-consumed,
int( connected_track->
GetLength() ) );
884 aTrack = connected_track;
886 start = connected_track->
GetStart();
891 std::swap( start,
end );
925 for(
int ii = poly.
PointCount()-1; ii >= 0 ; ii-- )
927 int dist_from_start = ( poly.
CPoint( ii ) - start ).EuclideanNorm();
931 if( dist_from_start < actualTdLen || ii == 0 )
933 start = poly.
CPoint( ii );
942 actualTdLen -= (start - ref_lenght_point).EuclideanNorm();
945 if( actualTdLen < 0 )
948 actualTdLen = std::min( actualTdLen, (
end - start).EuclideanNorm() );
963 *aEffectiveTeardropLen = actualTdLen;
969 std::vector<VECTOR2I>& aCorners,
PCB_TRACK* aTrack,
993 int track_halfwidth = aTrack->
GetWidth() / 2;
994 VECTOR2I pointB = start +
VECTOR2I( vecT.
x * track_stub_len + vecT.
y * track_halfwidth,
995 vecT.
y * track_stub_len - vecT.
x * track_halfwidth );
996 VECTOR2I pointA = start +
VECTOR2I( vecT.
x * track_stub_len - vecT.
y * track_halfwidth,
997 vecT.
y * track_stub_len + vecT.
x * track_halfwidth );
1003 if( !
IsRound( aOther, layer ) )
1007 if(
pad->HitTest( pointA, 0, layer ) )
1010 if(
pad->HitTest( pointB, 0, layer ) )
1019 pointD +=
VECTOR2I(
int( -vecT.
x*offset),
int(-vecT.
y*offset) );
1022 std::vector<VECTOR2I> pts = { pointA, pointB, pointC, pointD, pointE };
1028 aCorners = std::move( pts );
1033 if(
IsRound( aOther, layer ) )
1045 aOther, aOtherPos, layer );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual VECTOR2I GetPosition() const
KICAD_T Type() const
Returns the type of object.
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
const VECTOR2I & GetMid() const
virtual double GetLength() const
Get the length of the track using the hypotenuse calculation.
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
virtual int GetWidth() const
int Length() const
Return the length (this).
const SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError=DefaultAccuracyForPCB(), int *aActualError=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int Intersect(const SEG &aSeg, INTERSECTIONS &aIp) const
Find all intersection points between our line chain and the segment aSeg.
int PointCount() const
Return the number of points (vertices) in this line chain.
double Area(bool aAbsolute=true) const
Return the area of this chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
std::vector< INTERSECTION > INTERSECTIONS
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
void Move(const VECTOR2I &aVector) override
static bool IsRound(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
bool computeAnchorPoints(const TEARDROP_PARAMETERS &aParams, PCB_LAYER_ID aLayer, BOARD_ITEM *aItem, const VECTOR2I &aPos, std::vector< VECTOR2I > &aPts) const
Compute the 2 points on pad/via of the teardrop shape.
static int GetWidth(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
bool computeTeardropPolygon(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aCorners, PCB_TRACK *aTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos) const
Compute all teardrop points of the polygon shape.
void computeCurvedForRectShape(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aPoly, int aTdWidth, int aTrackHalfWidth, std::vector< VECTOR2I > &aPts, const VECTOR2I &aIntersection, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, PCB_LAYER_ID aLayer) const
Compute the curve part points for teardrops connected to a rectangular/polygonal shape The Bezier cur...
void computeCurvedForRoundShape(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aPoly, PCB_LAYER_ID aLayer, int aTrackHalfWidth, const VECTOR2D &aTrackDir, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, std::vector< VECTOR2I > &aPts) const
Compute the curve part points for teardrops connected to a round shape The Bezier curve control point...
PCB_TRACK * findTouchingTrack(EDA_ITEM_FLAGS &aMatchType, PCB_TRACK *aTrackRef, const VECTOR2I &aEndPoint) const
Find a track connected to the end of another track.
TRACK_BUFFER m_trackLookupList
bool areItemsInSameZone(BOARD_ITEM *aPadOrVia, PCB_TRACK *aTrack) const
friend class TEARDROP_PARAMETERS
bool findAnchorPointsOnTrack(const TEARDROP_PARAMETERS &aParams, VECTOR2I &aStartPoint, VECTOR2I &aEndPoint, VECTOR2I &aIntersection, PCB_TRACK *&aTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, int *aEffectiveTeardropLen) const
double m_BestWidthRatio
The height of a teardrop as ratio between height and size of pad/via.
int m_TdMaxLen
max allowed length for teardrops in IU. <= 0 to disable
bool m_AllowUseTwoTracks
True to create teardrops using 2 track segments if the first in too small.
int m_TdMaxWidth
max allowed height for teardrops in IU. <= 0 to disable
double m_BestLengthRatio
The length of a teardrop as ratio between length and size of pad/via.
bool m_CurvedEdges
True if the teardrop should be curved.
int idxFromLayNet(int aLayer, int aNetcode) const
void AddTrack(PCB_TRACK *aTrack, int aLayer, int aNetcode)
Add a track in buffer, in space grouping tracks having the same netcode and the same layer.
std::map< int, std::vector< PCB_TRACK * > * > m_map_tracks
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
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.
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
std::uint32_t EDA_ITEM_FLAGS
#define STARTPOINT
When a line is selected, these flags indicate which.
PCB_LAYER_ID
A quick note on layer IDs:
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
static bool isPointOnRoundedCorner(const VECTOR2I &aPoint, const VECTOR2I &aPadPos, const VECTOR2I &aPadSize, int aCornerRadius, const EDA_ANGLE &aRotation, VECTOR2I &aCornerCenter)
Check if a point is within a rounded corner region of a rounded rectangle pad.
static bool isPointOnOvalEnd(const VECTOR2I &aPoint, const VECTOR2I &aPadPos, const VECTOR2I &aPadSize, const EDA_ANGLE &aRotation, VECTOR2I &aArcCenter)
Check if a point is on the curved (semicircular) end of an oval pad.
static VECTOR2D NormalizeVector(const VECTOR2I &aVector)
static VECTOR2I computeCornerTangentControlPoint(const VECTOR2I &aAnchor, const VECTOR2I &aCornerCenter, double aBias, const VECTOR2I &aDesiredDir)
Helper to compute a control point for a teardrop anchor on a rounded rectangle corner.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
@ NONE
Pads are not covered.