LibrePCB Developers Documentation
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>

+ 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...
 
UnsignedLength 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...
 
bool isOnGrid (const PositiveLength &gridInterval) const noexcept
 Check whether the Point lies on the grid. 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
 Serialize into librepcb::SExpression 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
 
bool operator< (const Point &rhs) const noexcept
 Less/Greater comparison operator overloadings. More...
 
bool operator<= (const Point &rhs) const noexcept
 
bool operator> (const Point &rhs) const noexcept
 
bool operator>= (const Point &rhs) const noexcept
 

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)
 

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 separate 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

Constructor & Destructor Documentation

◆ Point() [1/4]

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() [2/4]

Point ( const Point point)
inlinenoexcept

Copy Constructor.

Parameters
pointAnother Point object

◆ Point() [3/4]

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() [4/4]

Point ( const SExpression node)
explicit

◆ ~Point()

~Point ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ setX()

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:

◆ setY()

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:

◆ setXmm()

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:

◆ setYmm()

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:

◆ setPointNm()

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:

◆ setPointMm()

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:

◆ setPointInch()

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:

◆ setPointMil()

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:

◆ setPointPx()

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:

◆ getX()

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:

◆ getY()

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:

◆ getLength()

UnsignedLength 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:

◆ isOrigin()

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:

◆ toMmQPointF()

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:

◆ toInchQPointF()

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:

◆ toMilQPointF()

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:

◆ toPxQPointF()

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:

◆ abs()

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
librepcb::Length::abs(), librepcb::Point::makeAbs()
+ Here is the call graph for this function:

◆ makeAbs()

Point & makeAbs ( )
noexcept

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

Returns
A reference to the modified object
See also
librepcb::Length::makeAbs(), librepcb::Point::abs()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mappedToGrid()

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
librepcb::Length::mappedToGrid(), librepcb::Point::mapToGrid()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapToGrid()

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
librepcb::Length::mapToGrid(), librepcb::Point::mappedToGrid()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isOnGrid()

bool isOnGrid ( const PositiveLength gridInterval) const
noexcept

Check whether the Point lies on the grid.

Parameters
gridIntervalSee Length::mappedToGrid()
Returns
If the point is on the grid.
See also
librepcb::Length::mappedToGrid(), librepcb::Point::mapToGrid()
+ Here is the caller graph for this function:

◆ rotated()

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 losing 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
librepcb::Point::rotate()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rotate()

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 losing 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
librepcb::Point::rotated()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mirrored()

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
librepcb::Point::mirror()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mirror()

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
librepcb::Point::mirrored()
+ Here is the caller graph for this function:

◆ serialize()

void serialize ( SExpression root) const

Serialize into librepcb::SExpression node.

Parameters
rootRoot node to serialize into.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromMm() [1/2]

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:

◆ fromMm() [2/2]

Point fromMm ( const QPointF &  millimeters)
static
+ Here is the call graph for this function:

◆ fromInch() [1/2]

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:

◆ fromInch() [2/2]

Point fromInch ( const QPointF &  inches)
static
+ Here is the call graph for this function:

◆ fromMil() [1/2]

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:

◆ fromMil() [2/2]

Point fromMil ( const QPointF &  mils)
static
+ Here is the call graph for this function:

◆ fromPx() [1/2]

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:

◆ fromPx() [2/2]

Point fromPx ( const QPointF &  pixels)
static
+ Here is the call graph for this function:

◆ operator=()

Point & operator= ( const Point rhs)
inline

◆ operator+=()

Point & operator+= ( const Point rhs)
inline

◆ operator-=()

Point & operator-= ( const Point rhs)
inline

◆ operator*=() [1/2]

Point & operator*= ( const Point rhs)
inline

◆ operator*=() [2/2]

Point & operator*= ( LengthBase_t  rhs)
inline

◆ operator/=() [1/2]

Point & operator/= ( const Point rhs)
inline

◆ operator/=() [2/2]

Point & operator/= ( LengthBase_t  rhs)
inline

◆ operator+()

Point operator+ ( const Point rhs) const
inline
+ Here is the call graph for this function:

◆ operator-() [1/2]

Point operator- ( ) const
inline
+ Here is the call graph for this function:

◆ operator-() [2/2]

Point operator- ( const Point rhs) const
inline
+ Here is the call graph for this function:

◆ operator*() [1/2]

Point operator* ( const Length rhs) const
inline
+ Here is the call graph for this function:

◆ operator*() [2/2]

Point operator* ( LengthBase_t  rhs) const
inline
+ Here is the call graph for this function:

◆ operator/() [1/2]

Point operator/ ( const Length rhs) const
inline
+ Here is the call graph for this function:

◆ operator/() [2/2]

Point operator/ ( LengthBase_t  rhs) const
inline
+ Here is the call graph for this function:

◆ operator%()

Point operator% ( const Length rhs) const
inline
+ Here is the call graph for this function:

◆ operator==()

bool operator== ( const Point rhs) const
inline

◆ operator!=()

bool operator!= ( const Point rhs) const
inline

◆ operator<()

bool operator< ( const Point rhs) const
inlinenoexcept

Less/Greater comparison operator overloadings.

This comparison operator doesn't make much sense, but it's useful to to sort librepcb::Point objects, e.g. for using them as a key in a sorted map. The comparison is first done on the X coordinate, and only if they are equal, the Y coordinate is also taken into account. So the "smallest" point is at (-infinity, -infinity) and the "greatest" point at (infinity, infinity).

Parameters
rhsThe other object to compare
Returns
Result of the comparison

◆ operator<=()

bool operator<= ( const Point rhs) const
inlinenoexcept

◆ operator>()

bool operator> ( const Point rhs) const
inlinenoexcept

◆ operator>=()

bool operator>= ( const Point rhs) const
inlinenoexcept

Member Data Documentation

◆ mX

Length mX
private

the X coordinate

◆ mY

Length mY
private

the Y coordinate


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