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
 
wxPoint TransformCoordinate (const wxPoint &aPoint) const
 Calculate a new coordinate according to the mirror/rotation transform. More...
 
EDA_RECT TransformCoordinate (const EDA_RECT &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 (int *aAngle1, int *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 transorm.

Definition at line 45 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 56 of file transform.h.

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

◆ TRANSFORM() [2/2]

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

Definition at line 58 of file transform.h.

58 : x1( ax1 ), y1( ay1 ), x2( ax2 ), y2( ay2 ) {}
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49

Member Function Documentation

◆ InverseTransform()

TRANSFORM TRANSFORM::InverseTransform ( ) const

Calculate the Inverse mirror/rotation transform.

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

Returns
The inverse transform.

Definition at line 59 of file transform.cpp.

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

References x1, x2, y1, and y2.

Referenced by SCH_COMPONENT::doIsConnected(), GetRelativePosition(), and SCH_MOVE_TOOL::moveItem().

◆ MapAngles()

bool TRANSFORM::MapAngles ( int *  aAngle1,
int *  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 81 of file transform.cpp.

82 {
83  wxCHECK_MSG( aAngle1 != NULL && aAngle2 != NULL, false,
84  wxT( "Cannot map NULL point angles." ) );
85 
86  int Angle, Delta;
87  double x, y, t;
88  bool swap = false;
89 
90  Delta = *aAngle2 - *aAngle1;
91  if( Delta >= 1800 )
92  {
93  *aAngle1 -= 1;
94  *aAngle2 += 1;
95  }
96 
97  x = cos( DECIDEG2RAD( *aAngle1 ) );
98  y = sin( DECIDEG2RAD( *aAngle1 ) );
99  t = x * x1 + y * y1;
100  y = x * x2 + y * y2;
101  x = t;
102  *aAngle1 = KiROUND( RAD2DECIDEG( atan2( y, x ) ) );
103 
104  x = cos( DECIDEG2RAD( *aAngle2 ) );
105  y = sin( DECIDEG2RAD( *aAngle2 ) );
106  t = x * x1 + y * y1;
107  y = x * x2 + y * y2;
108  x = t;
109  *aAngle2 = KiROUND( RAD2DECIDEG( atan2( y, x ) ) );
110 
111  NORMALIZE_ANGLE_POS( *aAngle1 );
112  NORMALIZE_ANGLE_POS( *aAngle2 );
113  if( *aAngle2 < *aAngle1 )
114  *aAngle2 += 3600;
115 
116  if( *aAngle2 - *aAngle1 > 1800 ) // Need to swap the two angles
117  {
118  Angle = (*aAngle1);
119  *aAngle1 = (*aAngle2);
120  *aAngle2 = Angle;
121 
122  NORMALIZE_ANGLE_POS( *aAngle1 );
123  NORMALIZE_ANGLE_POS( *aAngle2 );
124  if( *aAngle2 < *aAngle1 )
125  *aAngle2 += 3600;
126  swap = true;
127  }
128 
129  if( Delta >= 1800 )
130  {
131  *aAngle1 += 1;
132  *aAngle2 -= 1;
133  }
134 
135  return swap;
136 }
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
double RAD2DECIDEG(double rad)
Definition: trigo.h:222
int x1
Definition: transform.h:48
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:274
int y1
Definition: transform.h:49
#define NULL
double DECIDEG2RAD(double deg)
Definition: trigo.h:221
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References DECIDEG2RAD(), KiROUND(), NORMALIZE_ANGLE_POS(), NULL, RAD2DECIDEG(), x1, x2, y1, and y2.

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

◆ operator!=()

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

Definition at line 62 of file transform.h.

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

◆ operator==()

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

Definition at line 33 of file transform.cpp.

34 {
35  return ( x1 == aTransform.x1 &&
36  y1 == aTransform.y1 &&
37  x2 == aTransform.x2 &&
38  y2 == aTransform.y2 );
39 }
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49

References x1, x2, y1, and y2.

◆ TransformCoordinate() [1/2]

wxPoint TRANSFORM::TransformCoordinate ( const wxPoint &  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 component which are given for a non rotated, non mirrored item

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

Definition at line 42 of file transform.cpp.

43 {
44  return wxPoint( ( x1 * aPoint.x ) + ( y1 * aPoint.y ),
45  ( x2 * aPoint.x ) + ( y2 * aPoint.y ) );
46 }
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49

References x1, x2, y1, and y2.

Referenced by SCH_COMPONENT::doIsConnected(), SCH_EDITOR_CONTROL::FindComponentAndItem(), LIB_ARC::GetBoundingBox(), SCH_PIN::GetBoundingBox(), SCH_FIELD::GetBoundingBox(), SCH_COMPONENT::GetConnectionPoints(), SCH_COMPONENT::GetPinPhysicalPosition(), SCH_FIELD::GetPosition(), GetRelativePosition(), SCH_PIN::GetTransformedPosition(), LIB_CIRCLE::HitTest(), LIB_RECTANGLE::HitTest(), LIB_TEXT::HitTest(), LIB_BEZIER::HitTest(), LIB_ARC::HitTest(), LIB_POLYLINE::HitTest(), LIB_FIELD::HitTest(), SCH_MOVE_TOOL::moveItem(), LIB_PIN::PinDrawOrient(), LIB_RECTANGLE::Plot(), LIB_CIRCLE::Plot(), LIB_BEZIER::Plot(), LIB_TEXT::Plot(), LIB_ARC::Plot(), LIB_POLYLINE::Plot(), LIB_FIELD::Plot(), LIB_PIN::Plot(), LIB_POLYLINE::print(), LIB_RECTANGLE::print(), LIB_TEXT::print(), LIB_ARC::print(), LIB_FIELD::print(), LIB_BEZIER::print(), LIB_CIRCLE::print(), LIB_PIN::print(), SCH_FIELD::SetPosition(), ERC_TESTER::TestTextVars(), TransformCoordinate(), and SCH_COMPONENT::UpdateDanglingState().

◆ TransformCoordinate() [2/2]

EDA_RECT TRANSFORM::TransformCoordinate ( const EDA_RECT 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 component which are given for a non rotated, non mirrored item

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

Definition at line 48 of file transform.cpp.

49 {
50  EDA_RECT rect;
51  rect.SetOrigin( TransformCoordinate( aRect.GetOrigin() ) );
52  rect.SetEnd( TransformCoordinate( aRect.GetEnd() ) );
53  return rect;
54 }
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:131
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
const wxPoint GetEnd() const
Definition: eda_rect.h:116
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
void SetEnd(int x, int y)
Definition: eda_rect.h:192
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44

References EDA_RECT::GetEnd(), EDA_RECT::GetOrigin(), EDA_RECT::SetEnd(), EDA_RECT::SetOrigin(), and TransformCoordinate().

Member Data Documentation

◆ x1

◆ x2

◆ y1

◆ y2


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