41 m_endsSwapped( false ),
43 m_width( aLineWidth ),
46 m_eeWinding( eeWinding )
66 default:
return wxT(
"??" );
146 m_end += aMoveVector;
156 m_end += aMoveVector;
174 auto scalePt = [&]( wxPoint& pt )
176 pt.x =
KiROUND( pt.x * aScale );
177 pt.y =
KiROUND( pt.y * aScale );
198 std::vector<wxPoint> pts;
202 pts.emplace_back( pt );
203 scalePt( pts.back() );
241 if(
KiROUND( aAngle ) % 900 == 0 )
290 m_end.x = aCentre.x - (
m_end.x - aCentre.x );
295 m_end.y = aCentre.y - (
m_end.y - aCentre.y );
305 m_end.x = aCentre.x - (
m_end.x - aCentre.x );
310 m_end.y = aCentre.y - (
m_end.y - aCentre.y );
318 m_end.x = aCentre.x - (
m_end.x - aCentre.x );
324 m_end.y = aCentre.y - (
m_end.y - aCentre.y );
339 m_end.x = aCentre.x - (
m_end.x - aCentre.x );
346 m_end.y = aCentre.y - (
m_end.y - aCentre.y );
382 std::vector<wxPoint> bezierPoints;
387 converter.
GetPoly( bezierPoints, aMinSegLen );
456 aStartAngle = 180.0 / M_PI * atan2( startRadial.
y, startRadial.
x );
457 aEndAngle = 180.0 / M_PI * atan2( endRadial.
y, endRadial.
x );
459 if( aEndAngle == aStartAngle )
460 aEndAngle = aStartAngle + 360.0;
462 if( aStartAngle > aEndAngle )
491 return std::max( 1,
KiROUND( radius ) );
543 return ( endAngle - startAngle ) * 10;
552 if( aCheckNegativeAngle && aAngle < 0 )
566 wxString shape =
_(
"Shape" );
571 aList.emplace_back( shape,
_(
"Circle" ) );
574 aList.emplace_back(
_(
"Radius" ), msg );
578 aList.emplace_back( shape,
_(
"Arc" ) );
581 aList.emplace_back(
_(
"Angle" ), msg );
584 aList.emplace_back(
_(
"Radius" ), msg );
588 aList.emplace_back( shape,
_(
"Curve" ) );
591 aList.emplace_back(
_(
"Length" ), msg );
595 aList.emplace_back( shape,
_(
"Polygon" ) );
597 msg.Printf( wxT(
"%d" ),
GetPolyShape().Outline(0).PointCount() );
598 aList.emplace_back(
_(
"Points" ), msg );
602 aList.emplace_back( shape,
_(
"Rectangle" ) );
605 aList.emplace_back(
_(
"Width" ), msg );
608 aList.emplace_back(
_(
"Height" ), msg );
613 aList.emplace_back( shape,
_(
"Segment" ) );
616 aList.emplace_back(
_(
"Length" ), msg );
626 aList.emplace_back( shape,
_(
"Unrecognized" ) );
666 wxPoint pt( iter->x, iter->y );
697 int maxdist = aAccuracy;
710 return dist <= radius + maxdist;
712 return abs( radius - dist ) <= maxdist;
723 wxPoint relPos = aPosition -
getCenter();
727 if( abs( radius - dist ) <= maxdist )
734 std::swap( startAngle, endAngle );
736 double relPosAngle = 180.0 / M_PI * atan2( relPos.y, relPos.x );
742 if( endAngle > startAngle )
743 return relPosAngle >= startAngle && relPosAngle <= endAngle;
745 return relPosAngle >= startAngle || relPosAngle <= endAngle;
752 const_cast<EDA_SHAPE*>(
this )->RebuildBezierToSegmentsPointsList(
m_width );
843 arcRect = bb.
Common( arect );
900 double orientation = 0.0;
907 poly.
Rotate( orientation );
912 for(
int ii = 0; ii < count; ii++ )
917 if( arect.
Contains( ( wxPoint ) vertex ) )
925 if( arect.
Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
933 if( arect.
Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
957 for(
unsigned ii = 1; ii < count; ii++ )
963 if( arect.
Contains( ( wxPoint ) vertex ) )
983 std::vector<wxPoint> pts;
985 wxPoint botRight =
GetEnd();
998 pts.emplace_back( topLeft );
999 pts.emplace_back( botRight.x, topLeft.y );
1000 pts.emplace_back( botRight );
1001 pts.emplace_back( topLeft.x, botRight.y );
1006 for( wxPoint& pt : pts )
1020 wxPoint end =
m_end;
1026 std::swap( start, end );
1038 unsigned int quarter;
1065 double angleStart =
ArcTangente( startRadial.
y, startRadial.
x );
1069 while(
angle > 900 )
1090 for (
const wxPoint& p : aPoints )
1097 std::vector<SHAPE*> effectiveShapes;
1115 effectiveShapes.emplace_back(
new SHAPE_SIMPLE( pts ) );
1151 wxPoint start_pt = bezierPoints[0];
1153 for(
unsigned int jj = 1; jj < bezierPoints.size(); jj++ )
1155 wxPoint end_pt = bezierPoints[jj];
1189 return effectiveShapes;
1201 aBuffer.reserve( pointCount );
1204 aBuffer.emplace_back( iter->x, iter->y );
1280 poly.
Append( aPosition,
true );
1293 #define sq( x ) pow( x, 2 ) 1329 double chordBefore =
sq( v.x ) +
sq( v.y );
1337 double chordAfter =
sq( v.x ) +
sq( v.y );
1338 double ratio = chordAfter / chordBefore;
1342 radius = std::max(
int( sqrt(
sq( radius ) * ratio ) ) + 1,
1343 int( sqrt( chordAfter ) / 2 ) + 1 );
1352 radius = int( ( chordA + chordB ) / 2.0 ) + 1;
1382 double chordAngle =
ArcTangente( chordVector.y, chordVector.x );
1385 wxPoint c1Test = c1;
1467 #define EPSILON 2 // Should be enough for rounding errors on calculated items 1469 #define TEST( a, b ) { if( a != b ) return a - b; } 1470 #define TEST_E( a, b ) { if( abs( a - b ) > EPSILON ) return a - b; } 1471 #define TEST_PT( a, b ) { TEST_E( a.x, b.x ); TEST_E( a.y, b.y ); } 1503 int aClearanceValue,
1505 bool ignoreLineWidth )
const 1507 int width = ignoreLineWidth ? 0 :
m_width;
1509 width += 2 * aClearanceValue;
1535 for(
const wxPoint& pt : pts )
1536 aCornerBuffer.
Append( pt );
1570 std::vector<wxPoint> poly;
1573 for( wxPoint& point : poly )
1583 for(
const wxPoint& point : poly )
1584 aCornerBuffer.
Append( point.x, point.y );
1589 wxPoint pt1( poly[ poly.size() - 1] );
1591 for(
const wxPoint& pt2 : poly )
1607 std::vector< wxPoint> poly;
1610 for(
unsigned ii = 1; ii < poly.size(); ii++ )
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
int Length() const
Return the length (this).
int TotalVertices() const
Delete aIdx-th polygon from the set.
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
static PROPERTY_MANAGER & Instance()
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
int OutlineCount() const
Return the number of vertices in a given outline/hole.
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
virtual size_t GetPointCount() const override
T NormalizeAngle360Max(T Angle)
Normalize angle to be >=-360.0 and <= 360.0 Angle can be equal to -360 or +360.
void SetEnd(const wxPoint &aEnd)
void SetArcGeometry(const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd)
Set the three controlling points for an arc.
wxPoint getCenter() const
Implementation of conversion functions that require both schematic and board internal units.
const wxPoint & GetStart() const
Return the starting point of the graphic.
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
void GetPoly(std::vector< wxPoint > &aOutput, int aMinSegLen=0)
Convert a Bezier curve to a polygon.
bool hitTest(const wxPoint &aPosition, int aAccuracy=0) const
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the aGlobalIndex-th vertex in the poly set.
void Move(const VECTOR2I &aVector) override
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth) const
Convert the shape to a closed polygon.
void calcEdit(const wxPoint &aPosition)
double RAD2DEG(double rad)
void computeArcBBox(EDA_RECT &aBBox) const
EDA_SHAPE(SHAPE_T aType, int aLineWidth, FILL_T aFill, bool eeWinding)
int VertexCount(int aOutline=-1, int aHole=-1) const
Return the number of points in the shape poly set.
std::vector< SHAPE * > MakeEffectiveShapes() const
Make a set of SHAPE objects representing the EDA_SHAPE.
static ENUM_MAP< T > & Instance()
static struct EDA_SHAPE_DESC _EDA_SHAPE_DESC
void DupPolyPointsList(std::vector< wxPoint > &aBuffer) const
Duplicate the list of corners in a std::vector<wxPoint>
double GetArcAngle() const
double RAD2DECIDEG(double rad)
void CalcArcAngles(double &aStartAngle, double &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
virtual wxPoint getParentPosition() const =0
void SetOrigin(const wxPoint &pos)
virtual ORIGIN_TRANSFORMS & GetOriginTransforms()
Return a reference to the default ORIGIN_TRANSFORMS object.
bool IntersectsCircleEdge(const wxPoint &aCenter, const int aRadius, const int aWidth) const
Test for intersection between this rect and the edge (radius) of a circle.
extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
void SetArcAngleAndEnd(double aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
EDA_RECT Common(const EDA_RECT &aRect) const
Return the area that is common with another rectangle.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
void beginEdit(const wxPoint &aStartPoint)
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
void SetCachedArcData(const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd, const wxPoint &aCenter)
Set the data used for mid point caching.
void RotatePoint(int *pX, int *pY, double angle)
void NORMALIZE_ANGLE_POS(T &Angle)
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
The base class for create windows for drawing purpose.
wxString ShowShape() const
bool IsPolyShapeValid() const
void endEdit(bool aClosed=true)
Finishes editing the shape.
int PointCount() const
Return the number of points (vertices) in this line chain.
bool Contains(const wxPoint &aPoint) const
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both)
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
This file contains miscellaneous commonly used macros and functions.
void SetStart(const wxPoint &aStart)
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
const wxPoint & GetBezierC1() const
void rotate(const wxPoint &aRotCentre, double aAngle)
int GetPointCount() const
std::vector< wxPoint > GetRectCorners() const
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
const wxPoint & GetEnd() const
Return the ending point of the graphic.
double GetLength() const
Return the length of the track using the hypotenuse calculation.
void Move(const VECTOR2I &aVector) override
bool IsClosed() const override
const std::vector< VECTOR2I > & CPoints() const
void move(const wxPoint &aMoveVector)
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
void SetEnd(int x, int y)
std::vector< wxPoint > m_bezierPoints
bool TestSegmentHit(const wxPoint &aRefPoint, const wxPoint &aStart, const wxPoint &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aCornerBuffer, const wxPoint &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
const wxPoint & GetBezierC2() const
#define UNIMPLEMENTED_FOR(type)
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
const std::vector< wxPoint > buildBezierToSegmentsPointsList(int aMinSegLen) const
void SetWidth(int aWidth)
void Remove(int aStartIndex, int aEndIndex)
Remove the range of points [start_index, end_index] from the line chain.
void SetCenter(const wxPoint &aCenter)
double Angle() const
Compute the angle of the vector.
wxString SHAPE_T_asString() const
void setPosition(const wxPoint &aPos)
int NewOutline()
Creates a new hole in a given outline.
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
int SegmentCount() const
Return the number of segments in this line chain.
virtual const VECTOR2I GetPoint(int aIndex) const override
int Compare(const EDA_SHAPE *aOther) const
SHAPE_POLY_SET & GetPolyShape()
PLOT_DASH_TYPE
Dashed line types.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
void Rotate(double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
Rotate all vertices by a given angle.
void Normalize()
Ensures that the height ant width are positive.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
const EDA_RECT getBoundingBox() const
bool CollideEdge(const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0) const
Check whether aPoint collides with any edge of any of the contours of the polygon.
Bezier curves to polygon converter.
SEG Segment(int aIndex)
Return a copy of the aIndex-th segment in the line chain.
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=DefaultAccuracyForPCB(), double *aEffectiveAccuracy=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
virtual double getParentOrientation() const =0
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SwapShape(EDA_SHAPE *aImage)
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
wxPoint GetArcMid() const
Handle the component boundary box.
double DECIDEG2RAD(double deg)
void SetShape(SHAPE_T aShape)
void TransformOvalToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aStart, const wxPoint &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
wxPoint getPosition() const
void TransformArcToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
Provide class metadata.Helper macro to map type hashes to names.
void scale(double aScale)
double ArcTangente(int dy, int dx)
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
void flip(const wxPoint &aCentre, bool aFlipLeftRight)
void TransformRingToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.
bool continueEdit(const wxPoint &aPosition)
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...