LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Point Class Referencefinal

The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5.6mm) for X=1.2mm and Y=5.6mm. More...

#include <point.h>

+ Inheritance diagram for Point:
+ Collaboration diagram for Point:

Public Member Functions

 Point () noexcept
 Default Constructor. More...
 
 Point (const Point &point) noexcept
 Copy Constructor. More...
 
 Point (const Length &x, const Length &y) noexcept
 Constructor for passing two Length objects. More...
 
 Point (const SExpression &node)
 
 ~Point () noexcept
 Destructor. More...
 
void setX (const Length &x) noexcept
 Set the X coordinate. More...
 
void setY (const Length &y) noexcept
 Set the Y coordinate. More...
 
void setXmm (const QString &mm)
 Set the X coordinate from a string in millimeters. More...
 
void setYmm (const QString &mm)
 Set the Y coordinate from a string in millimeters. More...
 
void setPointNm (LengthBase_t nmX, LengthBase_t nmY) noexcept
 
void setPointMm (const QPointF &millimeters)
 
void setPointInch (const QPointF &inches)
 
void setPointMil (const QPointF &mils)
 
void setPointPx (const QPointF &pixels)
 
const LengthgetX () const noexcept
 Get the X coordinate. More...
 
const LengthgetY () const noexcept
 Get the Y coordinate. More...
 
Length getLength () const noexcept
 Get the length of the vector if X and Y represents a vector (e.g. the distance of this Point from the origin) More...
 
bool isOrigin () const noexcept
 Check if the position represents the origin (X == 0 and Y == 0) More...
 
QPointF toMmQPointF () const noexcept
 Get the point as a QPointF object in millimeters. More...
 
QPointF toInchQPointF () const noexcept
 Get the point as a QPointF object in inches. More...
 
QPointF toMilQPointF () const noexcept
 Get the point as a QPointF object in mils (1/1000 inches) More...
 
QPointF toPxQPointF () const noexcept
 Get the point as a QPointF object in pixels (for QGraphics* objects) More...
 
Point abs () const noexcept
 Get a Point object with both coordinates in absolute values (X,Y >= 0) More...
 
PointmakeAbs () noexcept
 Make both coordinates absolute (X,Y >= 0) More...
 
Point mappedToGrid (const PositiveLength &gridInterval) const noexcept
 Get a Point object which is mapped to a specific grid interval. More...
 
PointmapToGrid (const PositiveLength &gridInterval) noexcept
 Map this Point object to a specific grid interval. More...
 
Point rotated (const Angle &angle, const Point &center=Point(0, 0)) const noexcept
 Get the point rotated by a specific angle with respect to a specific center. More...
 
Pointrotate (const Angle &angle, const Point &center=Point(0, 0)) noexcept
 Rotate the point by a specific angle with respect to a specific center. More...
 
Point mirrored (Qt::Orientation orientation, const Point &center=Point(0, 0)) const noexcept
 Get the point mirrored horizontally or vertically around a specific center. More...
 
Pointmirror (Qt::Orientation orientation, const Point &center=Point(0, 0)) noexcept
 Mirror the point horizontally or vertically around a specific center. More...
 
void serialize (SExpression &root) const override
 Serialize the object into an existing S-Expression node. More...
 
Pointoperator= (const Point &rhs)
 
Pointoperator+= (const Point &rhs)
 
Pointoperator-= (const Point &rhs)
 
Pointoperator*= (const Point &rhs)
 
Pointoperator*= (LengthBase_t rhs)
 
Pointoperator/= (const Point &rhs)
 
Pointoperator/= (LengthBase_t rhs)
 
Point operator+ (const Point &rhs) const
 
Point operator- () const
 
Point operator- (const Point &rhs) const
 
Point operator* (const Length &rhs) const
 
Point operator* (LengthBase_t rhs) const
 
Point operator/ (const Length &rhs) const
 
Point operator/ (LengthBase_t rhs) const
 
Point operator% (const Length &rhs) const
 
bool operator== (const Point &rhs) const
 
bool operator!= (const Point &rhs) const
 
- Public Member Functions inherited from SerializableObject
 SerializableObject () noexcept
 
virtual ~SerializableObject () noexcept
 
SExpression serializeToDomElement (const QString &name) const
 Serialize the object to a new S-Expression node. More...
 

Static Public Member Functions

static Point fromMm (qreal millimetersX, qreal millimetersY)
 
static Point fromMm (const QPointF &millimeters)
 
static Point fromInch (qreal inchesX, qreal inchesY)
 
static Point fromInch (const QPointF &inches)
 
static Point fromMil (qreal milsX, qreal milsY)
 
static Point fromMil (const QPointF &mils)
 
static Point fromPx (qreal pixelsX, qreal pixelsY)
 
static Point fromPx (const QPointF &pixels)
 
- Static Public Member Functions inherited from SerializableObject
template<typename T >
static void serializeObjectContainer (SExpression &root, const T &container, const QString &itemName)
 
template<typename T >
static void serializePointerContainer (SExpression &root, const T &container, const QString &itemName)
 
template<typename T >
static void serializePointerContainerUuidSorted (SExpression &root, const T &container, const QString &itemName)
 

Private Attributes

Length mX
 the X coordinate More...
 
Length mY
 the Y coordinate More...
 

Detailed Description

The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5.6mm) for X=1.2mm and Y=5.6mm.

This class is used to represent ALL coordinates in Symbols, Schematics, Footprints, Layouts and so on. You should never use another coordinate type, like QPoint or QPointF! It's very important to have a consistent coordinate type over the whole project.

A Point object consists always of two Length objects. Basically, this is the only goal of this class, but it will provide also some useful addidional methods.

Note
Please note that the origin (0px;0px) of the QGraphics* objects is always at the top left corner, whereas the origin (0mm;0mm) of most CAD programs is at the bottom left corner. As we want to have the origin at the bottom left corner, like every good CAD program, we need to invert the Y-coordinate on every conversion between nanometers/millimeters and pixels (for QGraphics* objects), in both directions. This means, every time you need to convert a position from a QGraphics* object to millimeters (or another unit), you have to create a Point object and set the coordinate with Point::setPointPx() or Point::fromPx(). These methods will invert the Y-coordinate and you will have the right coordinate in the object. On the other hand, if you have to convert a coordinate from millimeters (or another unit) to pixels for a QGraphics* object, you have to use the method Point::toPxQPointF(), which will also invert the Y-coordinate. You should never convert an X and/or Y coordinate with seperate Length objects - which would be possible, but then the sign of the Y-coordinate is wrong! It is also not allowed to get the Y-coordinate in pixels with calling Point.getY().toPx(), this way the sign of the value in pixels is also wrong! You should use Point.toPxQPointF().y() instead for this purpose.
See Also
class Length
Author
ubruhin
Date
2014-06-21

Constructor & Destructor Documentation

Point ( )
inlinenoexcept

Default Constructor.

The object will be initialized with X=Length(0) and Y=Length(0).

+ Here is the caller graph for this function:

Point ( const Point point)
inlinenoexcept

Copy Constructor.

Parameters
pointAnother Point object
Point ( const Length x,
const Length y 
)
inlineexplicitnoexcept

Constructor for passing two Length objects.

Parameters
xThe X coordinate as a Length object
yThe Y coordinate as a Length object
Point ( const SExpression node)
explicit

+ Here is the call graph for this function:

~Point ( )
inlinenoexcept

Destructor.

Member Function Documentation

void setX ( const Length x)
inlinenoexcept

Set the X coordinate.

Parameters
xThe new X coordinate as a Length object

+ Here is the caller graph for this function:

void setY ( const Length y)
inlinenoexcept

Set the Y coordinate.

Parameters
yThe new Y coordinate as a Length object

+ Here is the caller graph for this function:

void setXmm ( const QString &  mm)
inline

Set the X coordinate from a string in millimeters.

Parameters
mmA string with the new X coordinate in millimeters
Exceptions
ExceptionIf the string is not valid, an exception will be thrown.

+ Here is the call graph for this function:

void setYmm ( const QString &  mm)
inline

Set the Y coordinate from a string in millimeters.

Parameters
mmA string with the new Y coordinate in millimeters
Exceptions
ExceptionIf the string is not valid, an exception will be thrown.

+ Here is the call graph for this function:

void setPointNm ( LengthBase_t  nmX,
LengthBase_t  nmY 
)
inlinenoexcept
See Also
Length::setLengthNm()
Warning
Be careful with this method! Maybe you should call mapToGrid() afterwards!

+ Here is the call graph for this function:

void setPointMm ( const QPointF &  millimeters)
inline
See Also
Length::setLengthMm()
Warning
Be careful with this method! Maybe you should call mapToGrid() afterwards!

+ Here is the call graph for this function:

void setPointInch ( const QPointF &  inches)
inline
See Also
Length::setLengthInch()
Warning
Be careful with this method! Maybe you should call mapToGrid() afterwards!

+ Here is the call graph for this function:

void setPointMil ( const QPointF &  mils)
inline
See Also
Length::setLengthMil()
Warning
Be careful with this method! Maybe you should call mapToGrid() afterwards!

+ Here is the call graph for this function:

void setPointPx ( const QPointF &  pixels)
inline
See Also
Length::setLengthPx()
Warning
Be careful with this method! Maybe you should call mapToGrid() afterwards!
Note
This method is useful to read the position of a QGraphics* object. For this purpose, this method will invert the Y-coordinate.

+ Here is the call graph for this function:

const Length& getX ( ) const
inlinenoexcept

Get the X coordinate.

Returns
The Length object of the X coordinate

+ Here is the caller graph for this function:

const Length& getY ( ) const
inlinenoexcept

Get the Y coordinate.

Returns
The Length object of the Y coordinate

+ Here is the caller graph for this function:

Length getLength ( ) const
inlinenoexcept

Get the length of the vector if X and Y represents a vector (e.g. the distance of this Point from the origin)

Returns
The length of this vector (as a Length object)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool isOrigin ( ) const
inlinenoexcept

Check if the position represents the origin (X == 0 and Y == 0)

Returns
True if X = Y = 0, otherwise false

+ Here is the caller graph for this function:

QPointF toMmQPointF ( ) const
inlinenoexcept

Get the point as a QPointF object in millimeters.

Returns
The point in millimeters
Warning
Be careful with this method, as it can decrease the precision!
See Also
Length::toMm()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QPointF toInchQPointF ( ) const
inlinenoexcept

Get the point as a QPointF object in inches.

Returns
The point in inches
Warning
Be careful with this method, as it can decrease the precision!
See Also
Length::toInch()

+ Here is the call graph for this function:

QPointF toMilQPointF ( ) const
inlinenoexcept

Get the point as a QPointF object in mils (1/1000 inches)

Returns
The point in mils
Warning
Be careful with this method, as it can decrease the precision!
See Also
Length::toMil()

+ Here is the call graph for this function:

QPointF toPxQPointF ( ) const
inlinenoexcept

Get the point as a QPointF object in pixels (for QGraphics* objects)

Returns
The point in pixels
Note
This method is useful to set the position of a QGraphics* object. For this purpose, this method will invert the Y-coordinate.
Warning
Be careful with this method, as it can decrease the precision!
See Also
Length::toPx()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point abs ( ) const
noexcept

Get a Point object with both coordinates in absolute values (X,Y >= 0)

Returns
A new Point object with absolute coordinates
See Also
Length::abs(), Point::makeAbs()

+ Here is the call graph for this function:

Point & makeAbs ( )
noexcept

Make both coordinates absolute (X,Y >= 0)

Returns
A reference to the modified object
See Also
Length::makeAbs(), Point::abs()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point mappedToGrid ( const PositiveLength gridInterval) const
noexcept

Get a Point object which is mapped to a specific grid interval.

Parameters
gridIntervalSee Length::mappedToGrid()
Returns
A new Point object which is mapped to the grid
See Also
Length::mappedToGrid(), Point::mapToGrid()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point & mapToGrid ( const PositiveLength gridInterval)
noexcept

Map this Point object to a specific grid interval.

Parameters
gridIntervalSee Length::mapToGrid()
Returns
A reference to the modified object
See Also
Length::mapToGrid(), Point::mappedToGrid()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point rotated ( const Angle angle,
const Point center = Point(0, 0) 
) const
noexcept

Get the point rotated by a specific angle with respect to a specific center.

Note
If the angle is a multiple of (exactly!) 90 degrees, this method will work without loosing accuracy (only integer operations). Otherwise, the result may be not very accurate.
Parameters
angleThe angle to rotate (CCW)
centerThe center of the rotation
Returns
A new Point object which is rotated
See Also
Point::rotate()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point & rotate ( const Angle angle,
const Point center = Point(0, 0) 
)
noexcept

Rotate the point by a specific angle with respect to a specific center.

Note
If the angle is a multiple of (exactly!) 90 degrees, this method will work without loosing accuracy (only integer operations). Otherwise, the result may be not very accurate.
Parameters
angleThe angle to rotate (CCW)
centerThe center of the rotation
Returns
A reference to the modified object
See Also
Point::rotated()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point mirrored ( Qt::Orientation  orientation,
const Point center = Point(0, 0) 
) const
noexcept

Get the point mirrored horizontally or vertically around a specific center.

Parameters
orientationQt::Horizontal = mirror X axis; Qt::Vertical = mirror Y axis
centerThe center of the mirror operation
Returns
A new Point object which is mirrored
See Also
Point::mirror()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point & mirror ( Qt::Orientation  orientation,
const Point center = Point(0, 0) 
)
noexcept

Mirror the point horizontally or vertically around a specific center.

Parameters
orientationQt::Horizontal = mirror X axis; Qt::Vertical = mirror Y axis
centerThe center of the mirror operation
Returns
A reference to the modified object
See Also
Point::mirrored()

+ Here is the caller graph for this function:

void serialize ( SExpression root) const
overridevirtual

Serialize the object into an existing S-Expression node.

This method inserts/appends all attributes and childs of the object to an existing S-Expression node. The content which already exists in the given S-Expression node will not be removed.

Note
The generated S-Expression node has always the format of the application's major version (it's not possible to generate DOMs of older versions).
Parameters
rootThe target DOM root node
Exceptions
ExceptionThis method throws an exception if an error occurs.

Implements SerializableObject.

+ Here is the call graph for this function:

Point fromMm ( qreal  millimetersX,
qreal  millimetersY 
)
static
See Also
Length::fromMm(qreal, const Length&)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point fromMm ( const QPointF &  millimeters)
static

+ Here is the call graph for this function:

Point fromInch ( qreal  inchesX,
qreal  inchesY 
)
static
See Also
Length::fromInch()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point fromInch ( const QPointF &  inches)
static

+ Here is the call graph for this function:

Point fromMil ( qreal  milsX,
qreal  milsY 
)
static
See Also
Length::fromMil()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point fromMil ( const QPointF &  mils)
static

+ Here is the call graph for this function:

Point fromPx ( qreal  pixelsX,
qreal  pixelsY 
)
static
See Also
Length::fromPx()
Note
These methods are useful to read the position of a QGraphics* object. For this purpose, these methods will invert the Y-coordinate.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point fromPx ( const QPointF &  pixels)
static

+ Here is the call graph for this function:

Point& operator= ( const Point rhs)
inline
Point& operator+= ( const Point rhs)
inline
Point& operator-= ( const Point rhs)
inline
Point& operator*= ( const Point rhs)
inline
Point& operator*= ( LengthBase_t  rhs)
inline
Point& operator/= ( const Point rhs)
inline
Point& operator/= ( LengthBase_t  rhs)
inline
Point operator+ ( const Point rhs) const
inline

+ Here is the call graph for this function:

Point operator- ( ) const
inline

+ Here is the call graph for this function:

Point operator- ( const Point rhs) const
inline

+ Here is the call graph for this function:

Point operator* ( const Length rhs) const
inline

+ Here is the call graph for this function:

Point operator* ( LengthBase_t  rhs) const
inline

+ Here is the call graph for this function:

Point operator/ ( const Length rhs) const
inline

+ Here is the call graph for this function:

Point operator/ ( LengthBase_t  rhs) const
inline

+ Here is the call graph for this function:

Point operator% ( const Length rhs) const
inline

+ Here is the call graph for this function:

bool operator== ( const Point rhs) const
inline
bool operator!= ( const Point rhs) const
inline

Member Data Documentation

Length mX
private

the X coordinate

Length mY
private

the Y coordinate


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