KiCad PCB EDA Suite
EC_CONVERGING Class Reference

EDIT_CONSTRAINT for 3 segments: dragged and two adjacent ones, enforcing to keep their slopes and allows only to change ending points. More...

#include <edit_constraints.h>

Inheritance diagram for EC_CONVERGING:
EDIT_CONSTRAINT< EDIT_LINE >

Public Member Functions

 EC_CONVERGING (EDIT_LINE &aLine, EDIT_POINTS &aPoints)
 
virtual ~EC_CONVERGING ()
 Correct coordinates of the constrained edit handle. More...
 
virtual void Apply (EDIT_LINE &aHandle) override
 Correct coordinates of the constrained edit handle. More...
 
void Apply ()
 Correct coordinates of the constrained edit handle. More...
 

Protected Attributes

EDIT_LINEm_constrained
 Point that is constrained by rules implemented by Apply(). More...
 

Private Attributes

EDIT_CONSTRAINT< EDIT_POINT > * m_originSideConstraint
 < Constraint for origin side segment. More...
 
EDIT_CONSTRAINT< EDIT_POINT > * m_endSideConstraint
 Additional constraint, applied when at least two points are collinear. More...
 
EDIT_CONSTRAINT< EDIT_POINT > * m_colinearConstraint
 EDIT_POINTS instance that stores currently modified lines. More...
 
EDIT_POINTSm_editPoints
 Vector that represents the initial direction of the dragged segment. More...
 
VECTOR2I m_draggedVector
 

Detailed Description

EDIT_CONSTRAINT for 3 segments: dragged and two adjacent ones, enforcing to keep their slopes and allows only to change ending points.

Applied to zones.

Definition at line 197 of file edit_constraints.h.

Constructor & Destructor Documentation

◆ EC_CONVERGING()

EC_CONVERGING::EC_CONVERGING ( EDIT_LINE aLine,
EDIT_POINTS aPoints 
)

Definition at line 95 of file edit_constraints.cpp.

95  :
97  m_colinearConstraint( nullptr ), m_editPoints( aPoints )
98 {
99  // Dragged segment endings
100  EDIT_POINT& origin = aLine.GetOrigin();
101  EDIT_POINT& end = aLine.GetEnd();
102 
103  // Previous and next points, to make constraining lines (adjacent to the dragged line)
104  EDIT_POINT& prevOrigin = *aPoints.Previous( origin, false );
105  EDIT_POINT& nextEnd = *aPoints.Next( end, false );
106 
107  // Constraints for segments adjacent to the dragged one
108  m_originSideConstraint = new EC_LINE( origin, prevOrigin );
109  m_endSideConstraint = new EC_LINE( end, nextEnd );
110 
111  // Store the current vector of the line
112  m_draggedVector = end.GetPosition() - origin.GetPosition();
113 
114  // Check for colinearity
115  SEG originSide( origin.GetPosition(), prevOrigin.GetPosition() );
116  SEG endSide( end.GetPosition(), nextEnd.GetPosition() );
117  SEG dragged( origin.GetPosition(), end.GetPosition() );
118 
119  if( dragged.Collinear( originSide ) )
121  else if( dragged.Collinear( endSide ) )
123 }
EDIT_POINT * Next(const EDIT_POINT &aPoint, bool aTraverseContours=true)
Return the point that is before the given point in the list.
EDIT_CONSTRAINT< EDIT_POINT > * m_colinearConstraint
EDIT_POINTS instance that stores currently modified lines.
EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined by 2 points).
EDIT_POINT & GetOrigin()
Return the origin EDIT_POINT.
Definition: edit_points.h:277
EDIT_POINT & GetEnd()
Return the end EDIT_POINT.
Definition: edit_points.h:290
virtual VECTOR2I GetPosition() const
Return coordinates of an EDIT_POINT.
Definition: edit_points.h:70
EDIT_CONSTRAINT< EDIT_POINT > * m_endSideConstraint
Additional constraint, applied when at least two points are collinear.
EDIT_CONSTRAINT< EDIT_POINT > * m_originSideConstraint
< Constraint for origin side segment.
Definition: seg.h:40
VECTOR2I m_draggedVector
EDIT_POINTS & m_editPoints
Vector that represents the initial direction of the dragged segment.
EDIT_POINT * Previous(const EDIT_POINT &aPoint, bool aTraverseContours=true)
Return the point that is after the given point in the list.
Represent a single point that can be used for modifying items.
Definition: edit_points.h:47

References EDIT_LINE::GetEnd(), EDIT_LINE::GetOrigin(), EDIT_POINT::GetPosition(), m_colinearConstraint, m_draggedVector, m_endSideConstraint, m_originSideConstraint, EDIT_POINTS::Next(), and EDIT_POINTS::Previous().

◆ ~EC_CONVERGING()

EC_CONVERGING::~EC_CONVERGING ( )
virtual

Correct coordinates of the constrained edit handle.

Definition at line 126 of file edit_constraints.cpp.

127 {
128  delete m_originSideConstraint;
129  delete m_endSideConstraint;
130  // m_colinearConstraint should not be freed, it is a pointer to one of the above
131 }
EDIT_CONSTRAINT< EDIT_POINT > * m_endSideConstraint
Additional constraint, applied when at least two points are collinear.
EDIT_CONSTRAINT< EDIT_POINT > * m_originSideConstraint
< Constraint for origin side segment.

References m_endSideConstraint, and m_originSideConstraint.

Member Function Documentation

◆ Apply() [1/2]

void EDIT_CONSTRAINT< EDIT_LINE >::Apply ( )
inlineinherited

Correct coordinates of the constrained edit handle.

Definition at line 71 of file edit_constraints.h.

72  {
74  }
void Apply()
Correct coordinates of the constrained edit handle.
EDIT_LINE & m_constrained
Point that is constrained by rules implemented by Apply().

◆ Apply() [2/2]

void EC_CONVERGING::Apply ( EDIT_LINE aHandle)
overridevirtual

Correct coordinates of the constrained edit handle.

Implements EDIT_CONSTRAINT< EDIT_LINE >.

Definition at line 134 of file edit_constraints.cpp.

135 {
136  // The dragged segment endpoints
137  EDIT_POINT& origin = aHandle.GetOrigin();
138  EDIT_POINT& end = aHandle.GetEnd();
139 
141  {
142  m_colinearConstraint->Apply( origin );
143  m_colinearConstraint->Apply( end );
144  }
145 
146  // The dragged segment
147  SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector );
148 
149  // Do not allow points on the adjacent segments move freely
152 
153  EDIT_POINT& prevOrigin = *m_editPoints.Previous( origin, false );
154  EDIT_POINT& nextEnd = *m_editPoints.Next( end, false );
155 
156  // Two segments adjacent to the dragged segment
157  SEG originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() );
158  SEG endSide = SEG( end.GetPosition(), nextEnd.GetPosition() );
159 
160  // First intersection point (dragged segment against origin side)
161  if( OPT_VECTOR2I originIntersect = dragged.IntersectLines( originSide ) )
162  origin.SetPosition( *originIntersect );
163 
164  // Second intersection point (dragged segment against end side)
165  if( OPT_VECTOR2I endIntersect = dragged.IntersectLines( endSide ) )
166  end.SetPosition( *endIntersect );
167 
168  // Check if adjacent segments intersect (did we dragged the line to the point that it may
169  // create a selfintersecting polygon?)
170  originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() );
171  endSide = SEG( end.GetPosition(), nextEnd.GetPosition() );
172 
173  if( OPT_VECTOR2I originEndIntersect = endSide.Intersect( originSide ) )
174  {
175  // Triangle intersect by definition
176  if( m_editPoints.LinesSize() > 3 )
177  {
178  origin.SetPosition( *originEndIntersect );
179  end.SetPosition( *originEndIntersect );
180  }
181  }
182 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
Definition: seg.cpp:154
EDIT_POINT * Next(const EDIT_POINT &aPoint, bool aTraverseContours=true)
Return the point that is before the given point in the list.
EDIT_CONSTRAINT< EDIT_POINT > * m_colinearConstraint
EDIT_POINTS instance that stores currently modified lines.
EDIT_POINT & GetOrigin()
Return the origin EDIT_POINT.
Definition: edit_points.h:277
EDIT_POINT & GetEnd()
Return the end EDIT_POINT.
Definition: edit_points.h:290
virtual VECTOR2I GetPosition() const
Return coordinates of an EDIT_POINT.
Definition: edit_points.h:70
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:38
unsigned int LinesSize() const
Return number of stored EDIT_LINEs.
Definition: edit_points.h:486
EDIT_CONSTRAINT< EDIT_POINT > * m_endSideConstraint
Additional constraint, applied when at least two points are collinear.
EDIT_CONSTRAINT< EDIT_POINT > * m_originSideConstraint
< Constraint for origin side segment.
Definition: seg.h:40
VECTOR2I m_draggedVector
virtual void Apply(EDIT_TYPE &aHandle)=0
Correct coordinates of the constrained edit handle.
EDIT_POINTS & m_editPoints
Vector that represents the initial direction of the dragged segment.
EDIT_POINT * Previous(const EDIT_POINT &aPoint, bool aTraverseContours=true)
Return the point that is after the given point in the list.
Represent a single point that can be used for modifying items.
Definition: edit_points.h:47
virtual void SetPosition(const VECTOR2I &aPosition)
Set new coordinates for an EDIT_POINT.
Definition: edit_points.h:106

References EDIT_CONSTRAINT< EDIT_TYPE >::Apply(), EDIT_LINE::GetEnd(), EDIT_LINE::GetOrigin(), EDIT_POINT::GetPosition(), SEG::Intersect(), EDIT_POINTS::LinesSize(), m_colinearConstraint, m_draggedVector, m_editPoints, m_endSideConstraint, m_originSideConstraint, EDIT_POINTS::Next(), EDIT_POINTS::Previous(), and EDIT_POINT::SetPosition().

Member Data Documentation

◆ m_colinearConstraint

EDIT_CONSTRAINT<EDIT_POINT>* EC_CONVERGING::m_colinearConstraint
private

EDIT_POINTS instance that stores currently modified lines.

Definition at line 216 of file edit_constraints.h.

Referenced by Apply(), and EC_CONVERGING().

◆ m_constrained

EDIT_LINE & EDIT_CONSTRAINT< EDIT_LINE >::m_constrained
protectedinherited

Point that is constrained by rules implemented by Apply().

Definition at line 77 of file edit_constraints.h.

◆ m_draggedVector

VECTOR2I EC_CONVERGING::m_draggedVector
private

Definition at line 222 of file edit_constraints.h.

Referenced by Apply(), and EC_CONVERGING().

◆ m_editPoints

EDIT_POINTS& EC_CONVERGING::m_editPoints
private

Vector that represents the initial direction of the dragged segment.

Definition at line 219 of file edit_constraints.h.

Referenced by Apply().

◆ m_endSideConstraint

EDIT_CONSTRAINT<EDIT_POINT>* EC_CONVERGING::m_endSideConstraint
private

Additional constraint, applied when at least two points are collinear.

It is a pointer to m_[origin/end]SideConstraint, so it should not be freed.

Definition at line 212 of file edit_constraints.h.

Referenced by Apply(), EC_CONVERGING(), and ~EC_CONVERGING().

◆ m_originSideConstraint

EDIT_CONSTRAINT<EDIT_POINT>* EC_CONVERGING::m_originSideConstraint
private

< Constraint for origin side segment.

Constraint for end side segment.

Definition at line 209 of file edit_constraints.h.

Referenced by Apply(), EC_CONVERGING(), and ~EC_CONVERGING().


The documentation for this class was generated from the following files: