KiCad PCB EDA Suite
EC_45DEGREE Class Reference

Class EC_45DEGREE. More...

#include <edit_constraints.h>

Inheritance diagram for EC_45DEGREE:
EDIT_CONSTRAINT< EDIT_POINT >

Public Member Functions

 EC_45DEGREE (EDIT_POINT &aConstrained, const EDIT_POINT &aConstrainer)
 Constructor. More...
 
virtual void Apply (EDIT_POINT &aHandle) override
 > More...
 
void Apply ()
 Function Apply() More...
 

Protected Attributes

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

Private Attributes

const EDIT_POINTm_constrainer
 Point that imposes the constraint. More...
 

Detailed Description

Class EC_45DEGREE.

EDIT_CONSTRAINT that imposes a constraint that two points have to be located at angle of 45 degree multiplicity.

Definition at line 134 of file edit_constraints.h.

Constructor & Destructor Documentation

EC_45DEGREE::EC_45DEGREE ( EDIT_POINT aConstrained,
const EDIT_POINT aConstrainer 
)
inline

Constructor.

Parameters
aConstrainedis the point that is put under constrain.
aConstraineris the point that is the source of the constrain.

Definition at line 143 of file edit_constraints.h.

143  :
144  EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
145  {}
const EDIT_POINT & m_constrainer
Point that imposes the constraint.

Member Function Documentation

void EDIT_CONSTRAINT< EDIT_POINT >::Apply ( )
inlineinherited

Function Apply()

Corrects coordinates of the constrained edit handle.

Definition at line 66 of file edit_constraints.h.

67  {
69  }
void Apply()
Function Apply()
EDIT_POINT & m_constrained
Point that is constrained by rules implemented by Apply()
void EC_45DEGREE::Apply ( EDIT_POINT aHandle)
overridevirtual

>

Function Apply() Corrects coordinates of the constrained edit handle.

Implements EDIT_CONSTRAINT< EDIT_POINT >.

Definition at line 48 of file edit_constraints.cpp.

References PNS::angle(), EDIT_POINT::GetPosition(), KiROUND(), m_constrainer, VECTOR2< T >::Rotate(), and EDIT_POINT::SetPosition().

49 {
50  // Current line vector
51  VECTOR2I lineVector( aHandle.GetPosition() - m_constrainer.GetPosition() );
52  double angle = lineVector.Angle();
53 
54  // Find the closest angle, which is a multiple of 45 degrees
55  double newAngle = KiROUND( angle / ( M_PI / 4.0 ) ) * M_PI / 4.0;
56  VECTOR2I newLineVector = lineVector.Rotate( newAngle - angle );
57 
58  aHandle.SetPosition( m_constrainer.GetPosition() + newLineVector );
59 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
virtual VECTOR2I GetPosition() const
Function GetPosition()
Definition: edit_points.h:65
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
const EDIT_POINT & m_constrainer
Point that imposes the constraint.
virtual void SetPosition(const VECTOR2I &aPosition)
Function SetPosition()
Definition: edit_points.h:97

Member Data Documentation

EDIT_POINT & EDIT_CONSTRAINT< EDIT_POINT >::m_constrained
protectedinherited

Point that is constrained by rules implemented by Apply()

Definition at line 72 of file edit_constraints.h.

Referenced by EC_LINE::EC_LINE().

const EDIT_POINT& EC_45DEGREE::m_constrainer
private

Point that imposes the constraint.

Definition at line 151 of file edit_constraints.h.

Referenced by Apply().


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