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 61 of file transform.cpp.

62{
63 int invx1;
64 int invx2;
65 int invy1;
66 int invy2;
67
68 /* Calculates the inverse matrix coeffs:
69 * for a matrix m{x1, x2, y1, y2}
70 * the inverse matrix is 1/(x1*y2 -x2*y1) m{y2,-x2,-y1,x1)
71 */
72 int det = x1*y2 -x2*y1; // Is never null, because the inverse matrix exists
73 invx1 = y2/det;
74 invx2 = -x2/det;
75 invy1 = -y1/det;
76 invy2 = x1/det;
77
78 TRANSFORM invtransform( invx1, invy1, invx2, invy2 );
79 return invtransform;
80}
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 83 of file transform.cpp.

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

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 37 of file transform.cpp.

38{
39 return ( x1 == aTransform.x1 &&
40 y1 == aTransform.y1 &&
41 x2 == aTransform.x2 &&
42 y2 == aTransform.y2 );
43}

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 52 of file transform.cpp.

53{
54 BOX2I rect;
55 rect.SetOrigin( TransformCoordinate( aRect.GetOrigin() ) );
56 rect.SetEnd( TransformCoordinate( aRect.GetEnd() ) );
57 return rect;
58}
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:46

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 46 of file transform.cpp.

47{
48 return VECTOR2I( ( x1 * aPoint.x ) + ( y1 * aPoint.y ), ( x2 * aPoint.x ) + ( y2 * aPoint.y ) );
49}
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

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: