KiCad PCB EDA Suite
Loading...
Searching...
No Matches
transform_trs.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef TRANSFORM_TRS_H
21#define TRANSFORM_TRS_H
22
23#include <math/vector2d.h>
24#include <geometry/eda_angle.h>
25
26
27// Translate / rotate / scale transform for footprint placement.
28// Apply order is fixed: scale, then rotate, then translate.
29// Independent X/Y scale is allowed. Shear is not representable.
31{
32public:
34 m_translate( 0, 0 ),
36 m_scaleX( 1.0 ),
37 m_scaleY( 1.0 )
38 {}
39
40 TRANSFORM_TRS( const VECTOR2I& aTranslate, const EDA_ANGLE& aRotate,
41 double aScaleX, double aScaleY ) :
42 m_translate( aTranslate ),
43 m_rotate( aRotate ),
44 m_scaleX( aScaleX ),
45 m_scaleY( aScaleY )
46 {}
47
48 VECTOR2I Apply( const VECTOR2I& aPoint ) const;
49 VECTOR2D Apply( const VECTOR2D& aPoint ) const;
50
51 VECTOR2I InverseApply( const VECTOR2I& aPoint ) const;
52 VECTOR2D InverseApply( const VECTOR2D& aPoint ) const;
53
54 TRANSFORM_TRS Invert() const;
55
56 TRANSFORM_TRS Compose( const TRANSFORM_TRS& aOuter ) const;
57
58 TRANSFORM_TRS RescaleAround( const VECTOR2I& aFixedPoint, double aSx, double aSy ) const;
59
60 bool IsIdentity() const;
61 bool IsUniformScale() const;
62
63 double ApplyLinearScale( double aLength ) const;
64
65 const VECTOR2I& GetTranslate() const { return m_translate; }
66 const EDA_ANGLE& GetRotate() const { return m_rotate; }
67 double GetScaleX() const { return m_scaleX; }
68 double GetScaleY() const { return m_scaleY; }
69
70 void SetTranslate( const VECTOR2I& aT ) { m_translate = aT; }
71 void SetRotate( const EDA_ANGLE& aR ) { m_rotate = aR; }
72 void SetScale( double aSx, double aSy ) { m_scaleX = aSx; m_scaleY = aSy; }
73
74 bool operator==( const TRANSFORM_TRS& aOther ) const;
75 bool operator!=( const TRANSFORM_TRS& aOther ) const { return !( *this == aOther ); }
76
77private:
80 double m_scaleX;
81 double m_scaleY;
82};
83
84#endif // TRANSFORM_TRS_H
VECTOR2I InverseApply(const VECTOR2I &aPoint) const
TRANSFORM_TRS Compose(const TRANSFORM_TRS &aOuter) const
TRANSFORM_TRS(const VECTOR2I &aTranslate, const EDA_ANGLE &aRotate, double aScaleX, double aScaleY)
bool IsUniformScale() const
TRANSFORM_TRS Invert() const
const EDA_ANGLE & GetRotate() const
double GetScaleX() const
void SetTranslate(const VECTOR2I &aT)
VECTOR2I Apply(const VECTOR2I &aPoint) const
EDA_ANGLE m_rotate
double GetScaleY() const
double ApplyLinearScale(double aLength) const
TRANSFORM_TRS RescaleAround(const VECTOR2I &aFixedPoint, double aSx, double aSy) const
bool operator==(const TRANSFORM_TRS &aOther) const
void SetScale(double aSx, double aSy)
bool IsIdentity() const
VECTOR2I m_translate
void SetRotate(const EDA_ANGLE &aR)
const VECTOR2I & GetTranslate() const
bool operator!=(const TRANSFORM_TRS &aOther) const
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682