32 if( cornersCount == 0 )
39 if( iterator.IsEndContour() )
44 for(
int i = 0; i < cornersCount - 1; ++i )
90 for(
unsigned i = 0; i < aPoints.
LinesSize(); ++i )
123 std::vector<EDA_ITEM*>& aUpdatedItems )
138 const double a =
m_ellipse.GetEllipseMajorRadius();
139 const double b =
m_ellipse.GetEllipseMinorRadius();
142 const double cosTheta = aTheta.
Cos();
143 const double sinTheta = aTheta.
Sin();
144 const double cosRot = rotation.
Cos();
145 const double sinRot = rotation.
Sin();
147 const double lx = a * cosTheta;
148 const double ly = b * sinTheta;
157 const double a = std::max( 1,
m_ellipse.GetEllipseMajorRadius() );
158 const double b = std::max( 1,
m_ellipse.GetEllipseMinorRadius() );
161 const double dx = aWorldPt.
x -
center.x;
162 const double dy = aWorldPt.
y -
center.y;
164 const double cosRot = rotation.
Cos();
165 const double sinRot = rotation.
Sin();
166 const double lx = dx * cosRot + dy * sinRot;
167 const double ly = -dx * sinRot + dy * cosRot;
176 const int a =
m_ellipse.GetEllipseMajorRadius();
177 const int b =
m_ellipse.GetEllipseMinorRadius();
180 const double cosRot = rotation.
Cos();
181 const double sinRot = rotation.
Sin();
203 const int a =
m_ellipse.GetEllipseMajorRadius();
204 const int b =
m_ellipse.GetEllipseMinorRadius();
207 const double cosRot = rotation.
Cos();
208 const double sinRot = rotation.
Sin();
226 std::vector<EDA_ITEM*>& aUpdatedItems )
241 const double len = std::sqrt(
double( v.
x ) * v.
x +
double( v.
y ) * v.
y );
253 const double proj = -v.
x * rotation.
Sin() + v.
y * rotation.
Cos();
263 while( ( rawAngle - prevStart ).AsDegrees() > 180.0 )
265 while( ( prevStart - rawAngle ).AsDegrees() > 180.0 )
268 m_ellipse.SetEllipseStartAngle( rawAngle );
269 m_ellipse.SetEllipseEndAngle( rawAngle + sweep );
276 while( ( rawAngle - prevEnd ).AsDegrees() > 180.0 )
278 while( ( prevEnd - rawAngle ).AsDegrees() > 180.0 )
281 m_ellipse.SetEllipseEndAngle( rawAngle );
313 std::vector<EDA_ITEM*>& aUpdatedItems )
359 COMMIT& aCommit, std::vector<EDA_ITEM*>& aUpdatedItems )
395 bool arcValid =
true;
407 else if( aEnd != aArc.
GetEnd() )
429 if( (
v1.EuclideanNorm() == 0 ) || (
v2.EuclideanNorm() == 0 ) )
432 u1 =
v1 /
v1.EuclideanNorm();
433 u2 =
v3 - ( u1.
x *
v3.x + u1.
y *
v3.y ) * u1;
442 double det = u1.
x * u2.
y - u2.
x * u1.
y;
449 double tmpx =
v1.x * u2.
y -
v1.y * u2.
x;
450 double tmpy = -
v1.x * u1.
y +
v1.y * u1.
x;
455 tmpx =
v2.x * u2.
y -
v2.y * u2.
x;
456 tmpy = -
v2.x * u1.
y +
v2.y * u1.
x;
461 double R =
v1.EuclideanNorm();
462 bool transformCircle =
false;
499 transformCircle =
true;
504 double delta = ( R * R -
v2.x *
v2.x -
v2.y *
v2.y ) / ( 2 *
v2.x - 2 * R );
511 if( !std::isfinite(
delta ) )
517 tmpx =
v4.x * u1.
x +
v4.y * u2.
x;
518 tmpy =
v4.x * u1.
y +
v4.y * u2.
y;
543 const int c_snapEpsilon_sq = 4;
545 VECTOR2I m = ( aStart / 2 + aEnd / 2 );
546 VECTOR2I perp = ( aEnd - aStart ).Perpendicular().Resize( INT_MAX / 2 );
548 SEG legal( m - perp, m + perp );
550 const SEG testSegments[] = {
555 std::vector<VECTOR2I> points = { legal.
A, legal.
B };
557 for(
const SEG& seg : testSegments )
562 points.push_back( *vec );
571 SEG::ecoord d_sq = ( pt - aCenter ).SquaredEuclideanNorm();
573 if( d_sq < min_d_sq - c_snapEpsilon_sq )
620 if( p1.
x == 0 && p1.
y == 0 )
621 p1 = prev_p1 - aCenter;
623 if( p2.
x == 0 && p2.
y == 0 )
653 bool movingStart =
false;
700 double radius = ( aCursor - aCenter ).EuclideanNorm();
708 start = start + aCenter;
727 const int JUST_OFF = ( aStart - aEnd ).EuclideanNorm() / 100;
773 std::vector<EDA_ITEM*>& aUpdatedItems )
796 m_arc.SetArcGeometry(
m_arc.GetStart() + moveVector,
m_arc.GetArcMid() + moveVector,
797 m_arc.GetEnd() + moveVector );
871 wxFAIL_MSG(
"Invalid arc edit mode" );
ARC_EDIT_MODE
Settings for arc editing.
@ KEEP_ENDPOINTS_OR_START_DIRECTION
Whe editing endpoints, the other end remains in place.
@ KEEP_CENTER_ENDS_ADJUST_ANGLE
When editing endpoints, only the angle is adjusted.
@ KEEP_CENTER_ADJUST_ANGLE_RADIUS
When editing endpoints, the angle and radius are adjusted.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Represent a set of changes (additions, deletions or modifications) of a data model (e....
EDIT_CONSTRAINT for polygon line dragging.
EDA_ARC_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aArc, const ARC_EDIT_MODE &aArcEditMode, KIGFX::VIEW_CONTROLS &aViewContols, const EDA_IU_SCALE &aIuScale)
const ARC_EDIT_MODE & m_arcEditMode
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
KIGFX::VIEW_CONTROLS & m_viewControls
const EDA_IU_SCALE & m_iuScale
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
EDA_ANGLE parametricAngleOf(const VECTOR2I &aWorldPt) const
Inverse: the parametric angle of a world-space point relative to this ellipse.
VECTOR2I evaluateAt(const EDA_ANGLE &aTheta) const
World-space point on the ellipse at the given parametric angle.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
virtual void SetEnd(const VECTOR2I &aEnd)
void SetCenter(const VECTOR2I &aCenter)
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
virtual void SetStart(const VECTOR2I &aStart)
VECTOR2I GetArcMid() const
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void SetConstraint(EDIT_CONSTRAINT< EDIT_LINE > *aConstraint)
Set a constraint for and EDIT_POINT.
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
unsigned int PointsSize() const
Return number of stored EDIT_POINTs.
void AddPoint(const EDIT_POINT &aPoint)
Add an EDIT_POINT.
void Clear()
Clear all stored EDIT_POINTs and EDIT_LINEs.
EDIT_POINT * Next(const EDIT_POINT &aPoint, bool aTraverseContours=true)
Return the point that is before the given point in the list.
EDIT_LINE & Line(unsigned int aIndex)
bool IsContourEnd(int aPointIdx) const
Check is a point with given index is a contour finish.
void AddIndicatorLine(EDIT_POINT &aOrigin, EDIT_POINT &aEnd)
Adds an EDIT_LINE that is shown as an indicator, rather than an editable line (no center point drag,...
void AddBreak()
Adds a break, indicating the end of a contour.
int GetContourStartIdx(int aPointIdx) const
Return index of the contour origin for a point with given index.
unsigned int LinesSize() const
Return number of stored EDIT_LINEs.
EDIT_POINT & Point(unsigned int aIndex)
void AddLine(const EDIT_LINE &aLine)
Adds an EDIT_LINE.
Represent a single point that can be used for modifying items.
virtual void SetPosition(const VECTOR2I &aPosition)
Set new coordinates for an EDIT_POINT.
virtual VECTOR2I GetPosition() const
Return coordinates of an EDIT_POINT.
An interface for classes handling user events controlling the view behavior such as zooming,...
static bool isModified(const EDIT_POINT &aEditedPoint, const EDIT_POINT &aPoint)
Checks if two points are the same instance - which means the point is being edited.
static void UpdateOutlineFromPoints(SHAPE_POLY_SET &aOutline, const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints)
Update the polygon outline with the new positions of the edit points.
SHAPE_POLY_SET & m_polygon
static void UpdatePointsFromOutline(const SHAPE_POLY_SET &aOutline, EDIT_POINTS &aPoints)
Update the edit points with the current polygon outline.
void FinalizeItem(EDIT_POINTS &aPoints, COMMIT &aCommit) override
Finalize the edit operation.
static void BuildForPolyOutline(EDIT_POINTS &aPoints, const SHAPE_POLY_SET &aOutline)
Build the edit points for the given polygon outline.
ecoord SquaredDistance(const SEG &aSeg) const
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.
Represent a set of closed polygons.
void SetVertex(const VERTEX_INDEX &aIndex, const VECTOR2I &aPos)
Accessor function to set the position of a specific point.
int TotalVertices() const
Return total number of vertices stored in the set.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
CONST_ITERATOR CIterateWithHoles(int aOutline) const
Define a general 2D-vector/point.
static constexpr extended_type ECOORD_MAX
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.
static constexpr EDA_ANGLE ANGLE_360
constexpr int Mils2IU(const EDA_IU_SCALE &aIuScale, int mils)
void EditArcEndpointKeepCenter(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor, const EDA_IU_SCALE &aIuScale)
Move an arc endpoint around the existing center, pulling the opposite endpoint along to keep the radi...
void EditArcMidKeepCenter(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor, const EDA_IU_SCALE &aIuScale)
Move the mid point of an arc while keeping the center, rotating the endpoints onto the new radius.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
static void editArcEndpointKeepCenterAndRadius(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
ARC_EDIT_MODE IncrementArcEditMode(ARC_EDIT_MODE aMode)
static void editArcCenterKeepEndpoints(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Move the arc center but keep endpoint locations.
static void editArcMidKeepEndpoints(EDA_SHAPE &aArc, const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCursor)
Move the mid point of the arc, while keeping the angle.
static void editArcEndpointKeepTangent(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor)
Move an end point of the arc, while keeping the tangent at the other endpoint.
#define CHECK_POINT_COUNT(aPoints, aExpected)
#define CHECK_POINT_COUNT_GE(aPoints, aExpected)
std::optional< VECTOR2I > OPT_VECTOR2I
VECTOR3I expected(15, 30, 45)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D