![]() |
Mapper
0.9.0
API documentation
|
Coordinates of a point in a map, with optional flags. More...
#include <map_coord.h>
Classes | |
struct | BoundsOffset |
Offset and flag for importing and moving out-of-bounds MapCoords. More... | |
Public Types | |
enum | Flag { CurveStart = 1 << 0, ClosePoint = 1 << 1, GapPoint = 1 << 2, HolePoint = 1 << 4, DashPoint = 1 << 5, MaskCopiedFlagsAtStart = GapPoint | DashPoint, MaskCopiedFlagsAtEnd = GapPoint | DashPoint | HolePoint | ClosePoint } |
These flags provide extra information on each coordinate in a path. More... | |
template<class c > | |
using | StringBuffer = std::array< c, 28 > |
A buffer that can hold a compact MapCoord string representation. More... | |
Public Member Functions | |
constexpr | MapCoord () noexcept |
Creates a MapCoord with position at the origin and without any flags set. More... | |
constexpr | MapCoord (const MapCoord &) noexcept=default |
Copy constructor. More... | |
constexpr | MapCoord (int x, int y) noexcept |
Creates a MapCoord from a position given in millimeters on the map. More... | |
constexpr | MapCoord (qreal x, qreal y) noexcept |
Creates a MapCoord from a position given in millimeters on the map. More... | |
constexpr | MapCoord (qreal x, qreal y, Flags flags) noexcept |
Creates a MapCoord with the given flags from a position given in millimeters on the map. More... | |
constexpr | MapCoord (qreal x, qreal y, Flag flag) noexcept |
Creates a MapCoord with the given flags from a position given in millimeters on the map. More... | |
MapCoord (qreal x, qreal y, int flags)=delete | |
constexpr | MapCoord (const QPointF &point) noexcept |
Creates a MapCoord with the position taken from a QPointF. More... | |
constexpr | MapCoord (const QPointF &point, Flags flags) noexcept |
Creates a MapCoord with the given flags and with the position taken from a QPointF. More... | |
constexpr | MapCoord (const QPointF &point, Flag flag) noexcept |
Creates a MapCoord with the given flags and with the position taken from a QPointF. More... | |
MapCoord (QPointF point, int flags)=delete | |
MapCoord & | operator= (const MapCoord &other)=default |
Assignment operator. More... | |
constexpr qreal | x () const |
Returns the coord's x position in millimeters on the map. More... | |
constexpr qreal | y () const |
Returns the coord's y position in millimeters on the map. More... | |
void | setX (qreal x) |
Sets the coord's x position to a value in millimeters on the map. More... | |
void | setY (qreal y) |
Sets the coord's y position to a value in millimeters on the map. More... | |
constexpr qint32 | nativeX () const |
Returns the coord's x position in native map coords. More... | |
constexpr qint32 | nativeY () const |
Returns the coord's y position in native map coords. More... | |
void | setNativeX (qint32 new_x) |
Sets the coord's x position to a value in native map coords. More... | |
void | setNativeY (qint32 new_y) |
Sets the coord's y position to a value in native map coords. More... | |
constexpr Flags::Int | flags () const noexcept |
Returns the coord's flags separately, merged into the lowest 8 bits of an int. More... | |
void | setFlags (Flags::Int flags) noexcept |
Sets the flags as retrieved by flags(). More... | |
bool | isRegular () const |
Returns true iff the coordinates are within "regular" bounds. More... | |
qreal | length () const |
Returns the length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map. More... | |
constexpr qreal | lengthSquared () const |
Returns the squared length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map. More... | |
qreal | distanceTo (const MapCoord &other) const |
Returns the distance from this coord to the other in millimeters on the map. More... | |
constexpr qreal | distanceSquaredTo (const MapCoord &other) const |
Returns the squared distance from this coord to the other in millimeters on the map. More... | |
constexpr bool | isPositionEqualTo (const MapCoord &other) const |
Returns if this coord's position is equal to that of the other one. More... | |
constexpr bool | isCurveStart () const |
Is this point the first point of a cubic bezier curve segment? More... | |
void | setCurveStart (bool value) |
Sets the curve start flag. More... | |
constexpr bool | isClosePoint () const |
Is this the last point of a closed path, which is at the same position as the first point? This is set in addition to isHolePoint(). More... | |
void | setClosePoint (bool value) |
Sets the close point flag. More... | |
constexpr bool | isHolePoint () const |
Is this the start of a hole for a line? More... | |
void | setHolePoint (bool value) |
Sets the hole point flag. More... | |
constexpr bool | isDashPoint () const |
Is this coordinate a special dash point? More... | |
void | setDashPoint (bool value) |
Sets the dash point flag. More... | |
constexpr bool | isGapPoint () const |
Is this coordinate a gap point? More... | |
void | setGapPoint (bool value) |
Sets the gap point flag. More... | |
constexpr MapCoord | operator- () const |
Additive inverse. More... | |
MapCoord & | operator+= (const MapCoord &rhs_vector) |
Component-wise addition. More... | |
MapCoord & | operator+= (const QPointF &rhs_vector) |
Component-wise addition of this and a MapCoordF/QPointF. More... | |
MapCoord & | operator-= (const MapCoord &rhs_vector) |
Component-wise subtraction. More... | |
MapCoord & | operator-= (const QPointF &rhs_vector) |
Component-wise subtraction of this and a MapCoordF/QPointF. More... | |
MapCoord & | operator*= (qreal factor) |
Multiply with scalar factor. More... | |
MapCoord & | operator/= (qreal scalar) |
Divide by scalar factor. More... | |
constexpr | operator QPointF () const |
Converts the coord's position to a QPointF. More... | |
QString | toString () const |
Writes raw coordinates and flags to a string. More... | |
QString | toString (StringBuffer< QChar > &buffer) const |
Returns a string for the raw coordinates and flags, using the given buffer. More... | |
QByteArray | toUtf8 (StringBuffer< char > &buffer) const |
Returns an UTF-8 string for the raw coordinates and flags, using the given buffer. More... | |
MapCoord (QStringRef &text) | |
Constructs the MapCoord from the beginning of text, and moves the reference to behind the this coordinates data. More... | |
void | save (QXmlStreamWriter &xml) const |
Saves the MapCoord in xml format to the stream. More... | |
Static Public Member Functions | |
static BoundsOffset & | boundsOffset () |
Returns the global bounds offset. More... | |
static constexpr MapCoord | fromNative (qint32 x, qint32 y) noexcept |
Creates a MapCoord from native map coordinates. More... | |
static constexpr MapCoord | fromNative (qint32 x, qint32 y, Flags flags) noexcept |
Creates a MapCoord from native map coordinates. More... | |
static constexpr MapCoord | fromNative (qint32 x, qint32 y, Flag flag) noexcept |
Creates a MapCoord from native map coordinates. More... | |
static MapCoord | fromNative (qint32 x, qint32 y, int flags)=delete |
static MapCoord | fromNative (qint64 x, qint64 y)=delete |
It is illegal to call MapCoord::fromNative with qint64 arguments. More... | |
static MapCoord | fromNative64 (qint64 x, qint64 y) |
Creates a MapCoord from native map coordinates. More... | |
static MapCoord | fromNative64withOffset (qint64 x, qint64 y) |
Creates a MapCoord from native map coordinates. More... | |
static MapCoord | load (QXmlStreamReader &xml) |
Loads the MapCoord in xml format from the stream. More... | |
static MapCoord | load (qreal x, qreal y, MapCoord::Flags flags) |
Creates a MapCoord from map coordinates in millimeters, with offset handling. More... | |
static MapCoord | load (qreal x, qreal y, int flags)=delete |
static MapCoord | load (const QPointF &p, MapCoord::Flags flags) |
Creates a MapCoord from map coordinates in millimeters, with offset handling. More... | |
static MapCoord | load (const QPointF &p, int flags)=delete |
Friends | |
class | CoordXmlTest |
Benchmark. More... | |
constexpr bool | operator== (const MapCoord &lhs, const MapCoord &rhs) |
Compare MapCoord for equality. More... | |
constexpr MapCoord | operator+ (const MapCoord &lhs, const MapCoord &rhs) |
Component-wise addition of MapCoord. More... | |
constexpr MapCoord | operator+ (const MapCoord &lhs, const QPointF &rhs) |
Component-wise addition of MapCoord and MapCoordF/QPointF. More... | |
constexpr MapCoord | operator- (const MapCoord &lhs, const MapCoord &rhs) |
Component-wise subtraction of MapCoord. More... | |
constexpr MapCoord | operator- (const MapCoord &lhs, const QPointF &rhs) |
Component-wise subtraction of MapCoord and MapCoordF/QPointF. More... | |
constexpr MapCoord | operator* (const MapCoord &lhs, qreal factor) |
Multiply MapCoord with scalar factor. More... | |
constexpr MapCoord | operator* (qreal factor, const MapCoord &rhs) |
Multiply MapCoord with scalar factor. More... | |
constexpr MapCoord | operator/ (const MapCoord &lhs, qreal divisor) |
Divide MapCoord by scalar factor. More... | |
Coordinates of a point in a map, with optional flags.
This coordinate uses what we call native map coordinates. One unit in native map coordinates is 1/1000th of a millimeter on the map paper.
The possible flags are:
These coordinates are implemented as 32 bit integers, the flags are store separately.
using OpenOrienteering::MapCoord::StringBuffer = std::array<c, 28> |
A buffer that can hold a compact MapCoord string representation.
The buffer size must allow for 1x ';': 1 2x '-': 2 2x ' ': 2 2x the decimal digits for values up to 0..2^31: 20 1x the decimal digits for 0..2^8-1: 3 Total: 28
|
noexcept |
Creates a MapCoord with position at the origin and without any flags set.
|
defaultnoexcept |
Copy constructor.
|
noexcept |
Creates a MapCoord from a position given in millimeters on the map.
This is a convenience constructor for efficient construction of a point at the origin i.e. MapCoord(0, 0), or for simple vectors i.e. MapCoord(1, 0). Intentionally, there is no public version with flags - you need to use other argument types than int if the compiler complains about ambiguity.
|
noexcept |
Creates a MapCoord from a position given in millimeters on the map.
|
noexcept |
Creates a MapCoord with the given flags from a position given in millimeters on the map.
|
noexcept |
Creates a MapCoord with the given flags from a position given in millimeters on the map.
|
delete |
|
explicitnoexcept |
|
delete |
OpenOrienteering::MapCoord::MapCoord | ( | QStringRef & | text | ) |
Constructs the MapCoord from the beginning of text, and moves the reference to behind the this coordinates data.
This is the counterpiece to toString(). It will throw a std::invalid_argument if the (beginning of) text does not contain valid data.
This constructor will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.
|
static |
Returns the global bounds offset.
It is returned as a non-const reference, so that it can be used in QScopedValueRollack.
constexpr qreal OpenOrienteering::MapCoord::distanceSquaredTo | ( | const MapCoord & | other | ) | const |
Returns the squared distance from this coord to the other in millimeters on the map.
Faster than lengthTo().
|
inline |
Returns the distance from this coord to the other in millimeters on the map.
|
noexcept |
Returns the coord's flags separately, merged into the lowest 8 bits of an int.
|
staticnoexcept |
Creates a MapCoord from native map coordinates.
|
staticnoexcept |
Creates a MapCoord from native map coordinates.
|
staticnoexcept |
Creates a MapCoord from native map coordinates.
|
staticdelete |
|
staticdelete |
It is illegal to call MapCoord::fromNative with qint64 arguments.
Use fromNative64 instead. That method tests the values against the bounds of qint32.
|
static |
|
static |
Creates a MapCoord from native map coordinates.
This will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32. It does not modify BoundsOffset()!
constexpr bool OpenOrienteering::MapCoord::isClosePoint | ( | ) | const |
Is this the last point of a closed path, which is at the same position as the first point? This is set in addition to isHolePoint().
constexpr bool OpenOrienteering::MapCoord::isCurveStart | ( | ) | const |
Is this point the first point of a cubic bezier curve segment?
constexpr bool OpenOrienteering::MapCoord::isDashPoint | ( | ) | const |
Is this coordinate a special dash point?
constexpr bool OpenOrienteering::MapCoord::isGapPoint | ( | ) | const |
Is this coordinate a gap point?
constexpr bool OpenOrienteering::MapCoord::isHolePoint | ( | ) | const |
Is this the start of a hole for a line?
Returns if this coord's position is equal to that of the other one.
bool OpenOrienteering::MapCoord::isRegular | ( | ) | const |
Returns true iff the coordinates are within "regular" bounds.
|
inline |
Returns the length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map.
constexpr qreal OpenOrienteering::MapCoord::lengthSquared | ( | ) | const |
Returns the squared length of this coord, seen as a vector from the origin to the given coordinate, in millimeters on the map.
Faster than length().
|
static |
Loads the MapCoord in xml format from the stream.
This will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.
|
static |
Creates a MapCoord from map coordinates in millimeters, with offset handling.
This will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.
|
staticdelete |
|
static |
Creates a MapCoord from map coordinates in millimeters, with offset handling.
This will initialize the boundsOffset() if necessary. Otherwise it will apply the BoundsOffset() and throw a std::range_error if the adjusted coordinates are out of bounds for qint32.
constexpr qint32 OpenOrienteering::MapCoord::nativeX | ( | ) | const |
Returns the coord's x position in native map coords.
constexpr qint32 OpenOrienteering::MapCoord::nativeY | ( | ) | const |
Returns the coord's y position in native map coords.
|
explicit |
Converts the coord's position to a QPointF.
|
inline |
Multiply with scalar factor.
Component-wise addition.
Component-wise addition of this and a MapCoordF/QPointF.
constexpr MapCoord OpenOrienteering::MapCoord::operator- | ( | ) | const |
Additive inverse.
Component-wise subtraction.
Component-wise subtraction of this and a MapCoordF/QPointF.
|
inline |
Divide by scalar factor.
Assignment operator.
void OpenOrienteering::MapCoord::save | ( | QXmlStreamWriter & | xml | ) | const |
Saves the MapCoord in xml format to the stream.
|
inline |
Sets the close point flag.
|
inline |
Sets the curve start flag.
|
inline |
Sets the dash point flag.
|
inlinenoexcept |
Sets the flags as retrieved by flags().
|
inline |
Sets the gap point flag.
|
inline |
Sets the hole point flag.
|
inline |
Sets the coord's x position to a value in native map coords.
|
inline |
Sets the coord's y position to a value in native map coords.
|
inline |
Sets the coord's x position to a value in millimeters on the map.
|
inline |
Sets the coord's y position to a value in millimeters on the map.
QString OpenOrienteering::MapCoord::toString | ( | ) | const |
Writes raw coordinates and flags to a string.
QString OpenOrienteering::MapCoord::toString | ( | MapCoord::StringBuffer< QChar > & | buffer | ) | const |
Returns a string for the raw coordinates and flags, using the given buffer.
The string is created using QString::fromRawData(), so it is valid for the lifetime of the buffer only.
QByteArray OpenOrienteering::MapCoord::toUtf8 | ( | MapCoord::StringBuffer< char > & | buffer | ) | const |
Returns an UTF-8 string for the raw coordinates and flags, using the given buffer.
The string is created using QByteArray::fromRawData(), so it is valid for the lifetime of the buffer only.
constexpr qreal OpenOrienteering::MapCoord::x | ( | ) | const |
Returns the coord's x position in millimeters on the map.
constexpr qreal OpenOrienteering::MapCoord::y | ( | ) | const |
Returns the coord's y position in millimeters on the map.
|
friend |
Benchmark.
Multiply MapCoord with scalar factor.
Multiply MapCoord with scalar factor.
Component-wise addition of MapCoord.
Component-wise addition of MapCoord and MapCoordF/QPointF.
Component-wise subtraction of MapCoord.
Component-wise subtraction of MapCoord and MapCoordF/QPointF.
Divide MapCoord by scalar factor.
Compare MapCoord for equality.