KiCad PCB EDA Suite
TRANSFORM Class Reference

for transforming drawing coordinates for a wxDC device context. More...

#include <transform.h>

Public Member Functions

 TRANSFORM ()
 The default construct creates a transform that draws object is the normal orientation. More...
 
 TRANSFORM (int ax1, int ay1, int ax2, int ay2)
 
bool operator== (const TRANSFORM &aTransform) const
 
bool operator!= (const TRANSFORM &aTransform) const
 
VECTOR2I TransformCoordinate (const VECTOR2I &aPoint) const
 Calculate a new coordinate according to the mirror/rotation transform. More...
 
BOX2I TransformCoordinate (const BOX2I &aRect) const
 Calculate a new rect according to the mirror/rotation transform. More...
 
TRANSFORM InverseTransform () const
 Calculate the Inverse mirror/rotation transform. More...
 
bool MapAngles (EDA_ANGLE *aAngle1, EDA_ANGLE *aAngle2) const
 Calculate new angles according to the transform. More...
 

Public Attributes

int x1
 
int y1
 
int x2
 
int y2
 

Detailed Description

for transforming drawing coordinates for a wxDC device context.

This probably should be a base class with all pure virtual methods and a WXDC_TRANSFORM derived class. Then in the future if some new device context is used, a new transform could be derived from the base class and all the drawable objects would have to do is provide overloaded draw methods to use the new transform.

Definition at line 46 of file transform.h.

Constructor & Destructor Documentation

◆ TRANSFORM() [1/2]

TRANSFORM::TRANSFORM ( )
inline

The default construct creates a transform that draws object is the normal orientation.

Definition at line 57 of file transform.h.

57: x1( 1 ), y1( 0 ), x2( 0 ), y2( -1 ) {}
int x2
Definition: transform.h:51
int y1
Definition: transform.h:50
int y2
Definition: transform.h:52
int x1
Definition: transform.h:49

◆ TRANSFORM() [2/2]

TRANSFORM::TRANSFORM ( int  ax1,
int  ay1,
int  ax2,
int  ay2 
)
inline

Definition at line 59 of file transform.h.

59: x1( ax1 ), y1( ay1 ), x2( ax2 ), y2( ay2 ) {}

Member Function Documentation

◆ InverseTransform()

TRANSFORM TRANSFORM::InverseTransform ( ) const

Calculate the Inverse mirror/rotation transform.

Useful to calculate coordinates relative to a symbol, which must be for a non-rotated, non-mirrored item from the actual coordinate.

Returns
The inverse transform.

Definition at line 56 of file transform.cpp.

57{
58 int invx1;
59 int invx2;
60 int invy1;
61 int invy2;
62
63 /* Calculates the inverse matrix coeffs:
64 * for a matrix m{x1, x2, y1, y2}
65 * the inverse matrix is 1/(x1*y2 -x2*y1) m{y2,-x2,-y1,x1)
66 */
67 int det = x1*y2 -x2*y1; // Is never null, because the inverse matrix exists
68 invx1 = y2/det;
69 invx2 = -x2/det;
70 invy1 = -y1/det;
71 invy2 = x1/det;
72
73 TRANSFORM invtransform( invx1, invy1, invx2, invy2 );
74 return invtransform;
75}
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:47

References x1, x2, y1, and y2.

Referenced by SCH_SYMBOL::doIsConnected(), GetRelativePosition(), EE_SELECTION_TOOL::GuessSelectionCandidates(), SCH_MOVE_TOOL::moveItem(), and SCH_FIELD::SetPosition().

◆ MapAngles()

bool TRANSFORM::MapAngles ( EDA_ANGLE aAngle1,
EDA_ANGLE aAngle2 
) const

Calculate new angles according to the transform.

Parameters
aAngle1= The first angle to transform
aAngle2= The second angle to transform
Returns
True if the angles were swapped during the transform.

Definition at line 78 of file transform.cpp.

79{
80 static const EDA_ANGLE epsilon( 0.1, DEGREES_T );
81
82 wxCHECK_MSG( aAngle1 != nullptr && aAngle2 != nullptr, false,
83 wxT( "Cannot map NULL point angles." ) );
84
85 double x, y;
86 VECTOR2D v;
87 bool swap = false;
88
89 EDA_ANGLE delta = *aAngle2 - *aAngle1;
90
91 x = aAngle1->Cos();
92 y = aAngle1->Sin();
93 v = VECTOR2D( x * x1 + y * y1, x * x2 + y * y2 );
94 *aAngle1 = EDA_ANGLE( v );
95
96 x = aAngle2->Cos();
97 y = aAngle2->Sin();
98 v = VECTOR2D( x * x1 + y * y1, x * x2 + y * y2 );
99 *aAngle2 = EDA_ANGLE( v );
100
101 EDA_ANGLE deltaTransformed = *aAngle2 - *aAngle1;
102 EDA_ANGLE residualError( deltaTransformed - delta );
103 residualError.Normalize();
104
105 if( residualError > epsilon || residualError < epsilon.Invert().Normalize() )
106 {
107 std::swap( *aAngle1, *aAngle2 );
108 swap = true;
109 }
110
111 if( *aAngle2 < *aAngle1 )
112 {
113 if( *aAngle2 < ANGLE_0 )
114 aAngle2->Normalize();
115 else
116 *aAngle1 = aAngle1->Normalize() - ANGLE_360;
117 }
118
119 return swap;
120}
EDA_ANGLE Normalize()
Definition: eda_angle.h:249
double Sin() const
Definition: eda_angle.h:206
double Cos() const
Definition: eda_angle.h:221
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE & ANGLE_360
Definition: eda_angle.h:418
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:412
constexpr int delta
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617

References ANGLE_0, ANGLE_360, EDA_ANGLE::Cos(), DEGREES_T, delta, EDA_ANGLE::Invert(), EDA_ANGLE::Normalize(), EDA_ANGLE::Sin(), swap, x1, x2, y1, and y2.

Referenced by KIGFX::SCH_PAINTER::draw(), LIB_SHAPE::Plot(), and LIB_SHAPE::print().

◆ operator!=()

bool TRANSFORM::operator!= ( const TRANSFORM aTransform) const
inline

Definition at line 63 of file transform.h.

63{ return !( *this == aTransform ); }

◆ operator==()

bool TRANSFORM::operator== ( const TRANSFORM aTransform) const

Definition at line 32 of file transform.cpp.

33{
34 return ( x1 == aTransform.x1 &&
35 y1 == aTransform.y1 &&
36 x2 == aTransform.x2 &&
37 y2 == aTransform.y2 );
38}

References x1, x2, y1, and y2.

◆ TransformCoordinate() [1/2]

BOX2I TRANSFORM::TransformCoordinate ( const BOX2I aRect) const

Calculate a new rect according to the mirror/rotation transform.

Useful to calculate actual coordinates of a point from coordinates relative to a symbol, which are given for a non-rotated,-non mirrored item.

Parameters
aRect= The rectangle to transform
Returns
The transformed rectangle.

Definition at line 47 of file transform.cpp.

48{
49 BOX2I rect;
50 rect.SetOrigin( TransformCoordinate( aRect.GetOrigin() ) );
51 rect.SetEnd( TransformCoordinate( aRect.GetEnd() ) );
52 return rect;
53}
void SetOrigin(const Vec &pos)
Definition: box2.h:202
const Vec & GetOrigin() const
Definition: box2.h:183
const Vec GetEnd() const
Definition: box2.h:185
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:255
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41

References BOX2< Vec >::GetEnd(), BOX2< Vec >::GetOrigin(), BOX2< Vec >::SetEnd(), BOX2< Vec >::SetOrigin(), and TransformCoordinate().

◆ TransformCoordinate() [2/2]

VECTOR2I TRANSFORM::TransformCoordinate ( const VECTOR2I aPoint) const

Calculate a new coordinate according to the mirror/rotation transform.

Useful to calculate actual coordinates of a point from coordinates relative to a symbol, which are given for a non-rotated,-non mirrored item.

Parameters
aPoint= The position to transform
Returns
The transformed coordinate.

Definition at line 41 of file transform.cpp.

42{
43 return VECTOR2I( ( x1 * aPoint.x ) + ( y1 * aPoint.y ), ( x2 * aPoint.x ) + ( y2 * aPoint.y ) );
44}
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References VECTOR2< T >::x, x1, x2, VECTOR2< T >::y, y1, and y2.

Referenced by SCH_SYMBOL::doIsConnected(), SCH_FIELD::GetBoundingBox(), SCH_PIN::GetBoundingBox(), SCH_SYMBOL::GetConnectionPoints(), SCH_SYMBOL::GetPinPhysicalPosition(), SCH_FIELD::GetPosition(), GetRelativePosition(), SCH_PIN::GetTransformedPosition(), EE_SELECTION_TOOL::GuessSelectionCandidates(), LIB_FIELD::HitTest(), LIB_SHAPE::HitTest(), LIB_TEXT::HitTest(), SCH_MOVE_TOOL::moveItem(), LIB_PIN::PinDrawOrient(), LIB_FIELD::Plot(), LIB_PIN::Plot(), LIB_SHAPE::Plot(), LIB_TEXT::Plot(), LIB_TEXTBOX::Plot(), LIB_FIELD::print(), LIB_PIN::print(), LIB_SHAPE::print(), LIB_TEXT::print(), LIB_TEXTBOX::print(), SCH_FIELD::SetPosition(), ERC_TESTER::TestTextVars(), TransformCoordinate(), and SCH_SYMBOL::UpdateDanglingState().

Member Data Documentation

◆ x1

◆ x2

◆ y1

◆ y2


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