LibrePCB Developers Documentation
Transform Class Reference

Helper class to perform coordinate transformation with various types. More...

#include <transform.h>

+ Collaboration diagram for Transform:

Public Member Functions

 Transform (const Point &position=Point(0, 0), const Angle &rotation=Angle(0), bool mirrored=false) noexcept
 (Default) construdtor More...
 
template<typename T >
 Transform (const T &obj)
 Constructor to copy the transformation of an object. More...
 
 Transform (const Transform &other) noexcept
 Copy constructor. More...
 
 ~Transform () noexcept
 Destructor. More...
 
const PointgetPosition () const noexcept
 
const AnglegetRotation () const noexcept
 
bool getMirrored () const noexcept
 
void setPosition (const Point &position) noexcept
 
void setRotation (const Angle &rotation) noexcept
 
void setMirrored (bool mirrored) noexcept
 
bool map (bool mirror) const noexcept
 Map a given mirror state to the transformed coordinate system. More...
 
Angle mapMirrorable (const Angle &angle) const noexcept
 Map a given angle to the transformed coordinate system. More...
 
Angle mapNonMirrorable (const Angle &angle) const noexcept
 Map a given angle to the transformed coordinate system. More...
 
Point map (const Point &point) const noexcept
 Map a given point to the transformed coordinate system. More...
 
Path map (const Path &path) const noexcept
 Map a given path to the transformed coordinate system. More...
 
NonEmptyPath map (const NonEmptyPath &path) const noexcept
 Map a given path to the transformed coordinate system. More...
 
const Layermap (const Layer &layer) const noexcept
 Map a given layer to the transformed coordinate system. More...
 
template<typename T >
map (const T &container) const noexcept
 Map all items of a container to the transformed coordinate system. More...
 
template<typename T >
mapPx (const T &obj) const noexcept
 Map a given Qt object in pixels to the transformed coordinate system. More...
 
bool operator== (const Transform &rhs) const noexcept
 
bool operator!= (const Transform &rhs) const noexcept
 
Transformoperator= (const Transform &rhs) noexcept
 

Private Attributes

Point mPosition
 
Angle mRotation
 
bool mMirrored
 

Detailed Description

Helper class to perform coordinate transformation with various types.

The class is similar to QTransform, but with the following differences:

  • It transforms mainly LibrePCB types instead of Qt types (e.g. librepcb::Point instead of QPointF).
  • It does not allow arbitrary transformations, but only mirror, rotate and translate. The order of the transformation is not configurable, it is hardcoded to the order of transformations applied to symbols within a schematic, and to footprints within a board. This order is: mirror horizontally (negating X-coordinate) -> rotate CCW -> translate.

Long story short, this class converts symbol- or footprint coordinates into schematic- resp. board coordinates.

Constructor & Destructor Documentation

◆ Transform() [1/3]

Transform ( const Point position = Point(0, 0),
const Angle rotation = Angle(0),
bool  mirrored = false 
)
inlinenoexcept

(Default) construdtor

Parameters
positionTransformation position.
rotationTransformation rotation.
mirroredTransformation mirror state.

◆ Transform() [2/3]

Transform ( const T &  obj)
inlineexplicit

Constructor to copy the transformation of an object.

Template Parameters
TAny type which provides the methods Point get Position(), Angle getRotation() and bool getMirrored().
Parameters
objAny object of the given type. The transformation is copied from the provided object.

◆ Transform() [3/3]

Transform ( const Transform other)
inlinenoexcept

Copy constructor.

Parameters
otherObject to copy.

◆ ~Transform()

~Transform ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ getPosition()

const Point& getPosition ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ getRotation()

const Angle& getRotation ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ getMirrored()

bool getMirrored ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ setPosition()

void setPosition ( const Point position)
inlinenoexcept

◆ setRotation()

void setRotation ( const Angle rotation)
inlinenoexcept

◆ setMirrored()

void setMirrored ( bool  mirrored)
inlinenoexcept
+ Here is the call graph for this function:

◆ map() [1/6]

bool map ( bool  mirror) const
noexcept

Map a given mirror state to the transformed coordinate system.

Parameters
mirrorThe mirror state to map.
Returns
The passed mirror state inverted if the transformation is mirroring, otherwise not inverted.
+ Here is the caller graph for this function:

◆ mapMirrorable()

Angle mapMirrorable ( const Angle angle) const
noexcept

Map a given angle to the transformed coordinate system.

Note
Intended for mirrorable objects (e.g. footprint pads), which expects the mapped object to mirror its geometry.
Parameters
angleThe angle to map.
Returns
The passed angle, mirrored horizontally if the transformation is mirroring and rotated by the transformations rotation.
+ Here is the caller graph for this function:

◆ mapNonMirrorable()

Angle mapNonMirrorable ( const Angle angle) const
noexcept

Map a given angle to the transformed coordinate system.

Note
Intended for non-mirrorable objects (e.g. symbol pins), which will cause the mirroring to be "emulated" by a 180° rotation.
Parameters
angleThe angle to map.
Returns
The passed angle, mirrored horizontally if the transformation is mirroring and rotated by the transformations rotation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ map() [2/6]

Point map ( const Point point) const
noexcept

Map a given point to the transformed coordinate system.

Parameters
pointThe point to map.
Returns
The passed point, mirrored horizontally if the transformation is mirroring, rotated by the transformations rotation, and translated by the transformation offset.
+ Here is the call graph for this function:

◆ map() [3/6]

Path map ( const Path path) const
noexcept

Map a given path to the transformed coordinate system.

Parameters
pathThe path to map.
Returns
The passed path, mirrored horizontally if the transformation is mirroring, rotated by the transformations rotation, and translated by the transformation offset.
+ Here is the call graph for this function:

◆ map() [4/6]

NonEmptyPath map ( const NonEmptyPath path) const
noexcept

Map a given path to the transformed coordinate system.

Parameters
pathThe path to map.
Returns
The passed path, mirrored horizontally if the transformation is mirroring, rotated by the transformations rotation, and translated by the transformation offset.

◆ map() [5/6]

const Layer & map ( const Layer layer) const
noexcept

Map a given layer to the transformed coordinate system.

Parameters
layerThe layer to map.
Returns
The mirrored layer if it's a symetric layer and the transformation is mirroring, otherwise the layer is returned as-is.

◆ map() [6/6]

T map ( const T &  container) const
inlinenoexcept

Map all items of a container to the transformed coordinate system.

Template Parameters
Containertype.
Parameters
containerThe items to map.
Returns
The passed items, mirrored horizontally if the transformation is mirroring, rotated by the transformations rotation, and translated by the transformation offset.
+ Here is the call graph for this function:

◆ mapPx()

T mapPx ( const T &  obj) const
inlinenoexcept

Map a given Qt object in pixels to the transformed coordinate system.

Parameters
objThe Qt object (in pixel coordinates) to map, e.g. QPoint, QPainterPath, ...).
Returns
The passed object, mirrored horizontally if the transformation is mirroring, rotated by the transformations rotation, and translated by the transformation offset.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator==()

bool operator== ( const Transform rhs) const
inlinenoexcept

◆ operator!=()

bool operator!= ( const Transform rhs) const
inlinenoexcept

◆ operator=()

Transform& operator= ( const Transform rhs)
inlinenoexcept

Member Data Documentation

◆ mPosition

Point mPosition
private

◆ mRotation

Angle mRotation
private

◆ mMirrored

bool mMirrored
private

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